Adding operators to observables
In Chapter 2, Reacting for the First Time, we used operators using bacon.js. They let us transform our data before it reaches the subscribers of the given Observable. The operators in RxJS work similar to the ones in bacon.js; some even have the same name. They are just methods called from Observable objects, as you can see in the following example:
Rx.Observable .just('Hello ') .map((msg)=>msg+'World') .subscribe((msg)=> console.log(msg));
In this example, we created an Observable, which emits only one string, and called the map()
operator over this Observable and subscribed to it to show the result in the console:
Hello World
Note
If you can't recall the map()
operator from Chapter 2, Reacting for the First Time, don't worry! We will see more of it and what it does later in this chapter.
Every time you call an operator over an observable, it returns a new observable with the transformation applied. This way, we can chain multiples operators...