Operators conversion

The whole point with this category is to show how easy it is to create Observables from something so they can play nice with the operators and well whatever construct you come from enables rich composition.

from

In Rxjs4 there existed a bunch of operators with resembling names such as fromArray(), from(), fromPromise() etc. All these from() operators are now just from(). Let’s look at some examples:

old fromArray

  1. Rx.Observable.from([2,3,4,5])

old fromPromise

  1. Rx.Observable.from(new Promise(resolve, reject) => {
  2. // do async work
  3. resolve( data )
  4. })

of

The of operator takes x number of arguments so you can call it with one arguments as well as 10 arguments like so:

  1. Rx.Observable.of(1,2);
  2. Rx.Observable.of(1,2,3,4);

to

There also exist a bunch of operators that allows you go the other way, i.e leave the wonderful world of observables and go back to a more primitive state like :

  1. let promise = Rx.Observable.of(1,2).toPromise();
  2. promise.then(data => console.log('Promise', data));