I have an event that is fired periodically:
let periodicEvent = Bacon.interval(1000, {});
periodicEvent.onValue(() => {
doStuff();
});
What I would like is to pause and restart periodicEvent when I need it. How can periodicEvent be paused and restarted? Or is there a better way to do it with baconjs?
An impure way to do it is to add a filter that checks for a variable before you subscribe, and then change the variable when you don't want the subscribed action to occur:
A "pure-r" way to do it would be turn an input into a property of true/false and filter you stream based on the value of that property:
Here is a jsbin of the above code
There might be an even better/fancier way of doing it using
Bacon.when, but I'm not at that level yet. :)