Created
December 7, 2015 19:27
-
-
Save botic/4c30cc6ac71191d626f0 to your computer and use it in GitHub Desktop.
First Reactive Steps
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
| const Rx = require("rx"); | |
| const dates = require("ringo/utils/dates"); | |
| // very simple | |
| const a$ = Rx.Observable.of(1,2,3); | |
| a$.subscribe(function(x) { console.log("a$", x); }); | |
| // a little bit more complex | |
| const start = new Date(); | |
| const createObservable = function() { | |
| return Rx.Observable.create(function (observer) { | |
| observer.onNext(new Date()); | |
| setTimeout(function() { | |
| observer.onNext(new Date()); | |
| }, 3000); | |
| setTimeout(function() { | |
| observer.onNext(new Date()); | |
| observer.onCompleted(); | |
| }, 5000); | |
| }).map(function(x) { | |
| return dates.diff(x, start, "second"); | |
| }); | |
| }; | |
| const b$ = createObservable(); | |
| b$.subscribe(function(x) { console.log("Diff: ", x, "seconds"); }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment