Open AlexGalays opened 8 years ago
Consider the following snippet (directly copy-pastable in requirebin) :
const flyd = require('flyd') const switchLatest = require('flyd/module/switchlatest') const stream = flyd.stream(3) const mapped = switchLatest( flyd.map(function(x) { return flyd.stream(x * 2) }, stream) ) flyd.on(function(value) { console.log('stream ended', value); }, stream.end) flyd.on(function(value) { console.log('mapped ended', value); }, mapped.end) flyd.on(function(value) { console.log('stream value', value); }, stream) flyd.on(function(value) { console.log('mapped value', value); }, mapped) stream(4) stream(5)
It produces the following console ouput:
stream value 3 stream value 4 mapped value 8 mapped value 8 stream value 5 mapped value 10 mapped value 10
Why is the mapped stream called twice for every change to the source stream?
It's most probably a bug with requirebin it self.
requirebin
I couldn't reproduce it anywhere else, including locally (node@6.9 with all flyd @ 1.x and above), on runkit and jsfiddle browserified.
Consider the following snippet (directly copy-pastable in requirebin) :
It produces the following console ouput:
Why is the mapped stream called twice for every change to the source stream?