paldepind / flyd

The minimalistic but powerful, modular, functional reactive programming library in JavaScript.
MIT License
1.56k stars 85 forks source link

Merge stream delay #185

Closed meepeek closed 6 years ago

meepeek commented 6 years ago

As the following code:

const mixStream = flyd.merge(stream1, stream2)

const mixScan = flyd.scan((o, n) => { return {
  a: scanStream1(),
  b: scanStream2()
} }, {
  a: 0,
  b: 0
}, mixStream)

I expect mixScan to show the result from both stream 1 and 2 updates. I did, but with a 1 step behind. Given stream1 <-- [1,2,3] then stream2 [4,5,6], this is the result for mixScan

mixScan stream1 stream2
{a:0, b:0}
{a:0, b:0} 1
{a:1, b:0} 2
{a:2, b:0} 3
{a:3, b:0} 4
{a:3, b:4} 5
{a:3, b:5} 6

Please find https://github.com/meepeek/meiosis-react-example for working example

nordfjord commented 6 years ago

Hey @meepeek Thank you for the issue.

I'm not sure I quite follow your text though, perhaps you could clarify a few things for me.

Is this bin not as expected: https://jsbin.com/bazibuzobu/edit?html,js,output

?

nordfjord commented 6 years ago

2018-08-29-123252_1921x647_scrot

meepeek commented 6 years ago

screen shot 2561-08-30 at 11 23 40

I followed your link but cannot get the output.

Could you clone https://github.com/meepeek/meiosis-react-example then run ? You will see that clicking buttons in the example and the state tracer for mixListener (scanner) would lag behind 1 step, but tapping the tracer for each individual streams work just fine. (You will have to click on each button once for mixListener to start working, not sure why.)

nordfjord commented 6 years ago

I honestly don't have the time to do that currently.

But if you can provide me a minimal flyd only reproducible issue, then I'd be happy to take a look.

also it seems you were routed to some strange url, this is the link to the bin: https://jsbin.com/bazibuzobu/edit?html,js,output

Feel free to use it as a baseline for your own reproducible case.

nordfjord commented 6 years ago

Okay I looked at your App.jsx file since I happened to have time.

https://github.com/meepeek/meiosis-react-example/blob/master/src/App.js#L12

Change this line from

const mixUpdate = flyd.merge(componentA.update, componentB.update)

to

const mixUpdate = flyd.merge(componentA.listener, componentB.listener)

And things will work like you expect

nordfjord commented 6 years ago

I take it by the thumbs up this issue is resolved, I'll close it, but feel free to reopen if this did not help.