Ded Jay
Ded Jay

Reputation: 11

rxjs-compat vs pipe() method

I used to chain methods with Observable like

Observable
.of('bla')
.map(text => 1)
.filter(value => value === 1)
.subscribe(value => console.log(value));

But now, I realize that since angular V6, we should use pipe() method like

Observable.of('bla').pipe(
map(text => 1),
filter(value => value === 1)
).subscribe(value => console.log(value));

As I saw lot of code that uses pipe(), I suppose I should use it, but is it really 'mandatory' ? or rxjs-compat will do the trick ?

Upvotes: 1

Views: 1469

Answers (1)

wentjun
wentjun

Reputation: 42576

RxJS compat is nothing but a backward-compatibility layer that eases the update/migration process from RxJS 5 to RxJS 6. You should not rely on RxJS compat for any long term development, but instead, slowly upgrade your codebase which utilises any RxJS operators. You may read more about the migration guide for more details.

In RxJS 6, RxJS operators are now chained using pipe() utility (rather than dot chaining), hence they are also known as pipeable operators.

Since you are using Angular, I would recommend you to check out the Angular update guide too, which includes a series of steps to update your Angular and RxJs versions.

In addition, Observable.of() has been replaced by the of() operator in RxJS 6.

of('bla')
  .pipe(
    map(text => 1),
    filter(value => value === 1)
  ).subscribe(value => console.log(value));

Upvotes: 5

Related Questions