What is pipe for in rxJS

前端 未结 4 826
青春惊慌失措
青春惊慌失措 2020-12-02 15:07

I think I have the base concept, but there are some obscurities

So in general this is how I use an observable:



        
4条回答
  •  半阙折子戏
    2020-12-02 15:53

    The "pipable" (former "lettable") operators is the current and recommended way of using operators since RxJS 5.5.

    I strongly recommend you to read the official documentation https://rxjs.dev/guide/v6/pipeable-operators

    The main difference is that it's easier to make custom operators and that it's better treeshakable while not altering some global Observable object that could possible make collisions if two different parties wanted to create an operator of the same name.

    Using separate import statement for each operator 'rxjs/add/operator/first' was a way to make smaller app bundles. By importing only operators you need instead of the entire RxJS library you can significantly reduce the total bundle size. However the compiler can't know if you imported 'rxjs/add/operator/first' because you really need it in you code or you just forgot to remove it when refactoring your code. That's one of the advantages of using pipable operators where unused imports are ignored automatically.

提交回复
热议问题