Closed RGBboy closed 9 years ago
This isn't a bug. This is happening because until you subscribe to the scan
observable it doesn't subscribe to it's parent (emitter
observable). So scan
doesn't consumes first two values from emitter
.
A little more details in the doc http://pozadi.github.io/kefir/#active-state
This idea of lazy subscription is the core of all three libraries (Kefir.js, Bacon.js, and RxJS), although it not ideal it allows to achieve decent performance.
What is the recommended way to achieve what I intended?
Given this code example the only thing that comes to my mind is to add dummy subscriber at the beginning to activate the stream. If you describe bigger problem you trying to solve maybe i'll be able to recommend better solution.
Here is what I am trying to achieve. I have server that is accepting connections. On each connection I want to send the client the history of events that has happened so far (ideally as a single object) and also stream new events as they happen.
Yep, I think adding a dummy subscriber at the beginning is a way to go here.
I'm having an issue with the scan method but I am not sure if it just my lack of understanding or if it is a bug.
Here is a stripped down version of what I am trying to achieve:
From this I would expect the following log:
But instead I get:
If I add a subscription to
scan
withscan.log();
orscan.onValue(function () {});
before emitting anything I get the expected result.