Created
April 6, 2017 08:02
-
-
Save Pierozi/1e90a39d059b73471dc10bf7e7af21fd to your computer and use it in GitHub Desktop.
RxJs Operator multiplyBy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Credit andre-staltz | |
| // from : https://egghead.io/instructors/andre-staltz | |
| const data = [1,2,3,4,5]; | |
| var foo = Rx.Observable.of(...data); | |
| // foo.map | |
| // foo.filter | |
| // foo.merge | |
| // foo.combineLatest | |
| function multiplyBy(multiplier) { | |
| var source = this; | |
| var result = Rx.Observable.create(function subscribe(observer) { | |
| source.subscribe( | |
| function (x) { observer.next(x * multiplier); }, | |
| function (err) { observer.error(err); }, | |
| function () { observer.complete(); } | |
| ); | |
| }); | |
| return result; | |
| } | |
| Rx.Observable.prototype.multiplyBy = multiplyBy; | |
| var bar = foo.multiplyBy(100); | |
| bar.subscribe( | |
| function (x) { console.log('next ' + x); }, | |
| function (err) { console.log('error ' + err); }, | |
| function () { console.log('done'); }, | |
| ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment