Open jayrbolton opened 8 years ago
I have the same problem, after add a subscriber to a stream, it is called immediately. my code looks like the following:
var todos = flyd.stream([])
var filter = flyd.stream('')
flyd.on(renderView, todos) // calls render
flyd.on(renderView, filter) // calls render
renderView() // official render call
I've solved the problem by combining streams but it is bit hacky
var todos = flyd.stream([])
var filter = flyd.stream('')
var allstreams = flyd.combine(function(){}, [todos, filter])
flyd.on(function(){
flyd.on(renderView, todos)
flyd.on(renderView, filter)
},
// fires view render once
allstreams(null))
I hit a snag in the default behavior of the
scan
function; in particular, how it pushes the initial accumulator value to the resulting stream immediately if the stream you pass in has no values when starting out (this line)Here is my specific problem case. This is a countdown timer stream that gets triggered by button clicks:
The "4,5,5" values on the stream all get emitted immediately/simultaneously. (I'm not sure why 5 gets emitted twice)
Here is an alternate implementation of scan that does not push the initial accumulator, but you could instead use
immediate
to get that behavior:When using the above scan in my countdown timer, I get
4, 3, 2, 1, 0
emitted as expected with my countdown timer.