Skip to content

Instantly share code, notes, and snippets.

@botic
Created December 7, 2015 19:27
Show Gist options
  • Select an option

  • Save botic/4c30cc6ac71191d626f0 to your computer and use it in GitHub Desktop.

Select an option

Save botic/4c30cc6ac71191d626f0 to your computer and use it in GitHub Desktop.
First Reactive Steps
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