Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

switchLatest: stream subscribers called more than once #120

Open
AlexGalays opened this issue Jun 6, 2016 · 1 comment
Open

switchLatest: stream subscribers called more than once #120

AlexGalays opened this issue Jun 6, 2016 · 1 comment

Comments

@AlexGalays
Copy link

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?

@anodynos
Copy link

anodynos commented Dec 7, 2016

It's most probably a bug with requirebin it self.

I couldn't reproduce it anywhere else, including locally (node@6.9 with all flyd @ 1.x and above), on runkit and jsfiddle browserified.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants