Reset a Bus

50 views
Skip to first unread message

Thomas Crevoisier

unread,
Nov 6, 2014, 10:47:46 AM11/6/14
to bac...@googlegroups.com
Hello !

I try more and more to do frp in my apps and I kinda enjoy it :) But recently, I struggled with a problem. I probably miss an obvious solution...

I've got a Bus A and I create a stream resulting of the number of different consecutive elements, let's call it stream B. Nothing difficult here.

I have also a Bus C. And for each event pushed to this bus, I want to reset the value of the stream B to 0.

I tried to do something like this, to make a kind of "reset" of A :

A = C.flatMapLatest(function () {
    return new Bacon.Bus();
});

But A will be a stream so I can't push any value to it...

Like I said, it may be obvious but I can't find a good and simple solution :/

Cheers,

Thomas Crevoisier

raimohanska

unread,
Nov 7, 2014, 11:11:02 AM11/7/14
to bac...@googlegroups.com
You might try something like
   
    numItemsP = Bacon.update(0,
      sourceE, function(numItems, newValue) { return numItems+1 },
      resetE, function(numItems) { return 0 }
    )

Hope this helps!
Reply all
Reply to author
Forward
0 new messages