Search code examples
angularrxjsrxjs-pipeable-operators

Rxjs, Pipe with one argument


Are there any differences when using the Pipe function with one argument, versus not using Pipe at all?

I am currently implementing the takeUntil unsubscribe strategy from this article. In the "official solution" from this SO question the takeUntil operator is sent through a pipe. However, on this page takeUntil is used with no pipe.

I am therefore wondering if there is any difference (memory leakage/performance, etc) in using a Pipe with a single Rx operator, versus no Pipe at all.

private destroy$ = new Subject();
...
this.potatoService.getPotato()
   .pipe(
    takeUntil(this.destroy$)
   ).subscribe(...

as opposed to

this.potatoService.getPotato()
    .takeUntil(this.destroy$)
    .subscribe(...

Solution

  • Since RxJS v6, takeUntil (and the others) have become pipeable operators rather than a standalone function.

    In the link you shared, please have a look at the imports section which means this example uses a former version of RxJS:

    import 'rxjs/add/operator/takeUntil';
    

    From the official docs of RxJS v6, the import path of takeUntil becomes:

    import { takeUntil } from 'rxjs/operators';
    

    For further reading: https://rxjs-dev.firebaseapp.com/api/operators/takeUntil