What's new in Rxjs 6.0

Hello Everyone,

I have been working on Angular 5 to Angular 7 migration. From Angular 5 onwards, Rxjs 6.0 is used. I would like to share the rxjs changes with you.

rxjs-compat is a life saver

If you are migrating a large project to Rxjs 6.0 then you just need to install rxjs-compat. It will take care of your old code. You don't have to change anything. Everything will work fine.

What's changed in Rxjs 6.0

  1. The package structure.
  2. Pipable Operators.
  3. Some operators are renamed.

Let's see one by one.

  1. The package structure.

The rxjs 6.0 has updated package structure to reduce the bundle size and easy imports. In the past we used to import as follows:-

import { Observable, Subject } from ‘rxjs/Observable’

import rxjs/add/operator/map

import rxjs/add/operator/take

import rxjs/add/observable/fromEvent

import rxjs/add/observable/fromPromise

Now Observable, Subject etc are imported directly from ‘rxjs’ and operators such as map, take are imported from ‘rxjs/operators’. The observable creation methods such as fromPromise, fromEvent are imported from ‘rxjs’.

import { Observable, Subject } from ‘rxjs’

import { map, take } from ‘rxjs/operators’

import { fromEvent, fromPromise } from ‘rxjs’

2. Pipable Operators.

In the past we used to chain the operators as follows:-

observable.map(…).throttle(…).subscribe(…).

Now we use special pipe method on observable which takes the infinite number of arguments. These arguments are nothing but the operator functions.

observable.pipe(map(…), throttle(…)).subscribe(…).

Now due to this pipable operators, some operators have to be renamed as they were conflicting with the javascript keywords.

3. Renamed Operators

And That’s all! Hope it helps.