Created
May 24, 2014 04:53
-
-
Save phadej/c9138f45ee3e1b4618f1 to your computer and use it in GitHub Desktop.
Glitch
This file contains 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
var Bacon = require("baconjs"); | |
var aBus = new Bacon.Bus(); | |
a = aBus.toProperty(3); | |
b = a.map(function (x) { return x * 2; }); | |
c = a.map(function (x) { return x * 3; }); | |
d = Bacon.combineWith(function (x, y) { return x + y; }, b, c); | |
d.onValue(function (x) { | |
console.log("next", x); | |
}); | |
aBus.push(4); |
This file contains 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
% node rx.js | |
next 15 | |
next 17 | |
next 20 | |
% node bacon.js | |
next 15 | |
next 20 |
This file contains 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
var Rx = require("rx"); | |
var a = new Rx.BehaviorSubject(3); | |
b = a.map(function (x) { return x * 2; }); | |
c = a.map(function (x) { return x * 3; }); | |
d = b.combineLatest(c, function (x, y) { return x + y; }); | |
d.subscribe(function (x) { | |
console.log("next", x); | |
}, function (x) { | |
console.log("err", x); | |
}, function () { | |
console.log("completed"); | |
}); | |
a.onNext(4); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment