Non-atomic update of dependent stream created within a dependent stream
See original GitHub issueHi @paldepind,
Let me begin by saying nice work. I’ve really enjoyed using flyd so far. Thank you for sharing it with us all.
I’ve come across an edge case that I’m hoping you can help with. I did my best to uncover the cause in the source but had limited success.
Basically, when a dependent stream is created within the body of another stream, and that stream is triggered, the dependent streams dependents are updated twice. I would expect it to be updated only once since the top level stream was only triggered once.
It’s hard to describe in words. Here is an example that will allow you to reproduce the unexpected behavior:
const f = require('flyd');
const input = f.stream(); input.mark = 'input';
const oninput = f.on(v => {
const s = f.stream(v); s.mark = 's';
const ds = f.combine(s => s(), [s]); ds.mark = 'ds';
const dds = f.on(v => console.log('dds:', v), ds); dds.mark = 'dds';
}, input); oninput.mark = 'oninput';
input(0);
// Console output:
//
// dds: 0
// dds: 0
From the best I was able to discern, when the oninput body runs, the following streams are added to the global toUpdate
object: s, ds (not dds).
Then each of those streams have their dependencies updated: s => updateDeps: ds, dds ds => updateDeps: dds
Which results in dds being updated twice.
Thoughts?
Thanks for your help!
Best regards, Alex
Issue Analytics
- State:
- Created 7 years ago
- Comments:9 (3 by maintainers)
Hello @paldepind & @c-dante - any updates on this issue?
PS: I should have started by saying thank you for this great composable FRP lib, so here you go 😃 I am evaluating it for a new frontend project where Rx would be an overkill and I’m getting hooked to it. I really like the fact it plays well with Ramda and FP principles, fantasy land etc unlike most other established libs.
With all due respect, I just wanted to know if the project is still alive and maintainable, cause it seems that lately there are both trivial & serious issues like this one that are hanging around…
Kind Regards
I think, i just fixed it.
npm install https://github.com/garkin/flyd/releases/tag/v0.2.4-forked