What's New in RxJS 6.0

DZone 's Guide to

What's New in RxJS 6.0

We take a quick look into the RxJS library, the updates that come with its 6.0 version, and how to use it with the Angular framework.

· Web Dev Zone ·
Free Resource

Hello everyone!

I have been working on an 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?

The package structure, pipable operators, and some operators have been renamed. Let's look at these one-by-one.

1. The Package Structure

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 ObservableSubject, etc. are imported directly from ‘rxjs’ and operators such as map and take are imported from ‘rxjs/operators.’ The observable creation methods such as fromPromise and 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 the 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 operator, some operators have to be renamed as they were conflicting with the JavaScript keywords.

3. Renamed Operators

And that’s all! Hope it helps.

angular tutorial, rxjs, web dev

Published at DZone with permission of Rohit Kawade . See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}