Rxjs pipe

Pipeable 操作符

现在 RxJS 提供了 pipe 辅助函数,它存在于 Observable 上,它缓解了操作符不在原型上所带来的问题。我们还继续使用上面丑陋的代码块:

import { take, map } from 'rxjs/operators';
import { of } from 'rxjs/observable/of';

map.call(
  take.call(
    of(1,2,3), 
    2
  ),
  val => val + 2
);

并将其转换成:

import { take, map } from 'rxjs/operators';
import { of } from 'rxjs/observable/of';

of(1,2,3)
  .pipe(
    take(2),
    map(val => val + 2)
  );

Much easier to read, right? This also has the benefit of greatly reducing the RxJS bundle size in your application. For more on this, Reduce Angular app bundle size using lettable operators.

代码可读性更高了,是吧?它还有额外的好处,就是可以大大减少应用中 RxJS 的打包尺寸。想深入了解, 使用 lettable 操作符来减少 Angular 应用的打包尺寸。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值