Well Bacon is still one big surprise for me...
bus = new Bacon.Bus()
busProperty = bus.toProperty()
bus.push 'someValue'
busProperty.onValue (val) ->
console.log val
This way, nothing is logged to console at all. I am probably looking from the wrong angle, but I would be expecting, that Property provides whatever was the latest value. Apparently, it's not that easy...
busProperty.log()
bus.push 'someValue'
busProperty.onValue (val) ->
console.log val
Suddenly I am getting 'someValue' logged twice. That means the Property doesn't care about stream values until there is consumer ? Is it possible to overcome this somehow ? It seems rather silly that I would need to attach empty consumer just for the kicks of storing value into Property.
This is part of my app design, that stream receives value before any consumers are attached. However I do care about that value from the past. Essentially I am looking for synchronous version of Promise/A :)
This is a known issue, but "by design". The FAQ entry Why isn't my Property updated? explains:
What's happening here is that your Property won't get updated when there are no listeners. Before you add an actual listener using onValue, the Property is not active; it's not listening to the underlying Bus. It ignores input until someone's interested. So it all boils down to the "laziness" of all Bacon streams and properties. This is a key feature too: the streams automatically "plug in" to their sources when a subscriber is added, and "unplug" when there are no more subscribers.
You may consider using a Bacon.Model instead. That'll give you a "settable property" with a bunch of additional features.