Newbie Trouble with Bus

46 views
Skip to first unread message

Michael Jones

unread,
Oct 30, 2014, 9:39:28 AM10/30/14
to bac...@googlegroups.com
Hi,

I wanted to raise this as I've hit it twice now as a newbie.

If I have code like:

var myPlainBus = new Bacon.Bus();
var myExtraBus = new Bacon.Bus()
.debounce(300)
.map(function(address) {
 // stuff
 return ...;
})
.filter(function(address) {
 // stuff
 return ...;
})
.skipDuplicates()
.onValue(function(value) {
 // stuff
});

myPlainBus.push(someValue);
myExtraBus.push(someValue);

Then the push on myPlainBus works and the push on myExtraBus doesn't. I'm guessing it is because as some point an EventStream is returned instead of a Bus so the push method no longer exists on it. Though frustratingly, I don't get an error in Chrome saying that 'undefined isn't callable' or whatever you'd normally get here if push didn't exist. Instead you just get nothing which is mildly frustrating as a clueless newbie :)

I might be doing something wrong or perhaps this has been fixed in a later version that I'm not on yet, but I feel it might be worth mentioning somewhere in the docs as it doesn't seem like such a crazy approach to use. Maybe I'm confused and you're not meant to just chain a bunch of those methods together off the initial 'new' call.

Anyway, I otherwise love Bacon.js and the FRP paradigm or what little I understand of it. It certain has solved a few issues I've had very neatly :)

Thanks,
Michael

raimohanska

unread,
Oct 31, 2014, 4:01:59 AM10/31/14
to bac...@googlegroups.com
You're correct in that the combinators (such as map, filter, debonce, skipDuplicates) return a new EventStream, not a Bus. You can push to the original Bus created with "new Bus()". So try something like

    var myExtraBus = new Bacon.Bus()
    myExtraBus.map(..).filter(..).skipDuplicates(..).onValue(..)
    myExtraBus.push(someValue)

Michael Jones

unread,
Oct 31, 2014, 11:12:13 AM10/31/14
to bac...@googlegroups.com
Thanks for confirming it. Is it clear why use of 'push' on an EventStream doesn't result in an error? My issue here is really the silent failure.

Many thanks for the library though, it is pretty damn fantastic :)
Michael
Reply all
Reply to author
Forward
0 new messages