We have covered the basics of the observable.create, and other creation functions. Now lets finally dive into operators, which is the focus of this course. We'll see how operators is simple pure functions attached to the Observable type.
varfoo = Rx.Observable.of (1, 2, 3, 4, 5);functionmultiplyby (num) {//When chaining the subscribe, the source was this keywordConst Source = This; //Create a observalbe and subscribeConst RESULT = Rx.Observable.create (function(Observer) {//source should be immutable, everytime return a new valueSource.subscribe (item) ={Observer. Next (item*num); }, (Err)={observer.error (err); }, () ={observer.complete (); }) }); //Return the observable returnresult;}//HackRx.Observable.prototype.multiplyBy =multiplyby;varBar = foo.multiplyby (100); Bar.subscribe (function(x) {Console.log (' next ' +x); }, function(ERR) {console.log (' error ' +err); }, function() {console.log (' done ')); },);
If you had many operators in chain like this, with some arguments in between, then, it means the once you subscribe to T He observable that this returns (Multiplyby), that would subscribe to bar, which would subscribe to Foo, which would subscrib E to the source in the Multiplyby function.
[RxJS] What RxJS operators is