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 应用的打包尺寸。

你可能感兴趣的:(JS&TS,angular.js,javascript,typescript)