Skip to content

Instantly share code, notes, and snippets.

@phadej
Created May 24, 2014 04:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phadej/c9138f45ee3e1b4618f1 to your computer and use it in GitHub Desktop.
Save phadej/c9138f45ee3e1b4618f1 to your computer and use it in GitHub Desktop.
Glitch
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);
% node rx.js
next 15
next 17
next 20
% node bacon.js
next 15
next 20
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