var event1 = new Bacon.Bus();
var event2 = new Bacon.Bus();
var event3 = new Bacon.Bus();
var combinedStream = Bacon.combineWith(function(e1, e2) {
return e1 + e2;
},
event1,
event2
);
combinedStream.onValue(function (each) {
console.log(each);
})
// Is there a way to modify the combinedStream so that it will include
// event3 events and no longer listent to event1 events? I want to
// leave the combinedStream onValue observer in place, but I want to
// change the streams that are being combined into it.
//
// I don't see any simple method on combinedStream to add/remove
// source streams. But I'm wondering if the basic behavior (maybe not
// even using combineWith at all) can be achived through some
// combination of custom streams, or flatMaps, or something! :)
Thanks,
Jesse
function selectStream(selector, streams) {
return selector.flatMapLatest(function(current_key) {
return streams[current_key];
})
}
Example:
var a = new Bacon.Bus();
var b = new Bacon.Bus();
var src = new Bacon.Bus();
var current = selectStream(src.toProperty('a'), {a: a, b: b});
current.assign(console, 'log')
console.log('a')
b.push('b foo');
a.push('a foo');
a.push('a bar');
b.push('b bar');
console.log('b')
src.push('b')
b.push('b foo');
a.push('a foo');
a.push('a bar');
b.push('b bar');