baconjs / bacon.js

Functional reactive programming library for TypeScript and JavaScript

Home Page:https://baconjs.github.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Stream converted to property lost its value when combined

dtinth opened this issue · comments

Somehow, when an EventStream is converted to a property, it fails to emit event if these properties based on the same EventStream is combined in some way:

var x = Bacon.once(1)

var a = x.map(n => n + 1).toProperty()
var b = x.map(n => n + 2).toProperty()

Bacon.combineAsArray(a, b).log()

I expected that [ 2, 3 ] would be printed out, but it just ends:

<end>

Let’s give them an initial value:

var x = Bacon.once(1)

var a = x.map(n => n + 1).toProperty(0)
var b = x.map(n => n + 2).toProperty(0)

Bacon.combineAsArray(a, b).log()
[ 2, 0 ]
<end>

Here, the value 1 did get to a but did not get to b, so it has a value of 0, which is really weird. The behavior here depends on which property gets combined first.


Workaround: Right now I worked around it delaying the Bacon.once by 0 milliseconds. This is far from ideal, but works:

var x = Bacon.once(1).delay(0)

var a = x.map(n => n + 1).toProperty()
var b = x.map(n => n + 2).toProperty()

Bacon.combineAsArray(a, b).log()
[ 2, 3 ]
<end>

The classic synchronous stream problem, once again. I'm travelling, cannot look up the orig issue.

Found it in FAQ:

https://github.com/baconjs/bacon.js/wiki/FAQ#why-isnt-my-subscriber-called

I think I can close this issue now, as it seems to be a well known one.