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 應用的打包尺寸。
總結
- 上一篇: 公测与奥运同行,云服务总线CSB:“连”
- 下一篇: 系统无法以在此计算机上安装,window