from()

The from() operator allows us to create an Observable from some other asynchronous/synchronous concept. It's really powerful when almost anything can be made into an Observable, as this allows for rich composition. Here is what a typical snippet can look like:

let stream$ = Rx.Observable.from(new Promise(resolve, reject) => {  resolve('some data');});stream$.subscribe( data => console.log(data)); // some datalet stream2$ = Rx.Observable.from([1,2,3,4]);stream2$.subscribe( data => console.log(data)); // 1,2,3,4

Get Architecting Angular Applications with Redux, RxJS, and NgRx now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.