var _x = 0, _xChanges = new Bacon.Bus()
function getX(){ return _x }
function setX(x2){ _x = x2 }
var x = _xChanges.toProperty(_x)
And eventually the x property will be wired up to some UI thing, i.e. x.onValue(...). But before that, I call setX(somethingElse). The problem is that if I call setX before actually wiring it up, the x property still has an initial value of 0, instead of the desired somethingElse. When I added a .log('value of x:') to the definition of x, the behavior changed to what I expected.
A slightly more distilled version:
var changes = new Bacon.Bus(),
vals = changes.toProperty(0)
changes.push(3)
vals.log('value:')
// prints "value: 0", but I expected "value: 3"
Is this behavior intentional? Do I need to make sure I'm adding some listener to the property before attempting to change its value?
I've got a setup along the lines of
And eventually the
x
property will be wired up to some UI thing, i.e.x.onValue(...)
. But before that, I callsetX(somethingElse)
. The problem is that if I callsetX
before actually wiring it up, thex
property still has an initial value of 0, instead of the desiredsomethingElse
. When I added a.log('value of x:')
to the definition ofx
, the behavior changed to what I expected.A slightly more distilled version:
Is this behavior intentional? Do I need to make sure I'm adding some listener to the property before attempting to change its value?