baconjs / bacon.js

Functional reactive programming library for TypeScript and JavaScript
https://baconjs.github.io
MIT License
6.47k stars 330 forks source link

Bacon.when doesn't respect the syncronization pattern, unless I subscribe to the source stream #764

Open eguneys opened 4 years ago

eguneys commented 4 years ago

I have this stream by using Bacon.when

let esDrags = Bacon.when(
  [dDraw.esDrags, revents.drags, _ => _],
  [dStacks.drags, revents.drags, _ => ({
    stack: 'stack' + _.initial,
    ..._
  })],
  [revents.drags, _ => ({
    stack: 'event' + _.initial,
    ..._
  })]
);

//dStacks.drags.onValue();
esDrags.map(_ => _.stack).log();

// These streams are like:

revents.drags = Bacon.fromEvent(document, 'mousemove');
dStacks.drags = revents.drags.filter(whereDragIsInBounds);

The problem is esDrags emits two events that happen simultaneously one from dStacks.drags one from revents.drags. The weird thing is if I uncomment the line dStacks.drags.onValue the problem dissapears and I see correct behaviour.

I couldn't reproduce the issue here: https://jsfiddle.net/bwgv97tn/ My project is at https://github.com/eguneys/tapper/tree/bacon