Reputation: 3460
I am trying to produce the zip example from BaconJS. But it doesn't work.
var obs = Bacon.fromArray([{ x: 1, y: 2 },
{ x: 3, y: 4 }]);
var x = obs.map('.x');
var y = obs.map('.y');
var result = x.zip(y, function(x, y) {
return x + y;
});
// This doesn't work
// if `result` is replaced with `x` then it produces 1, 3 correctly
result.onValue(function(value) {
$("#events").append($("<li>").text(value))
});
Upvotes: 0
Views: 67
Reputation: 7113
The problem is with Bacon.fromArray
, which behaves differently (synchronously) than other streams. This is a typical problem that many people run into in example code. See the FAQ.
One way to solve this is to add .delay(0)
to your stream, another is to use Bacon.sequentially
.
I've updated your fiddle so it works.
Upvotes: 1