These are chat archives for pozadi/kefir

8th
Feb 2015
David Thompson
@davexunit
Feb 08 2015 03:07
hello all. trying out Kefir. so far I like it more than Bacon.js, but I have one little nit that I can't quite figure out.
it has to do with Kefir.combine
according to the docs, a combined signal will not emit a value until all of the inputs have emitted at least once. I interpreted "at least once" to mean "at least once ever", but from trying it out it seems to mean "at least after the combined stream has been created"
is this correct?
David Thompson
@davexunit
Feb 08 2015 03:13
for a simple example: I would like to define 2 streams that emit initial values immediately, then define a third stream that combines those two, and since they've already emitted a value in the past, this third stream emits the combined value.
this way, the code is more declarative. I don't have to explicitly emit values after everything has been built.
Roman Pominov
@rpominov
Feb 08 2015 07:08

"at least after the combined stream has been created"

this is correct

we can make it work as you subscribed, but there is two issues with it:
1) we will have to make all streams store last emitted value, just like properties do
2) it would be correct semantically, as combined stream emits values at same time one of it sources emits a value. and since both values was emitted in the past, combined stream must emit before it was created, which is impossible of course :)
Roman Pominov
@rpominov
Feb 08 2015 07:15
but you can achieve what you described with properties, as they do store last value, and there is nothing wrong semantically as this value is a "current" value which subscribers get at the moment of subscription
there is a little trick kefir do that you have to know:
stream also might emit "current" values sometimes, one of the example if you combine two properties then result stream will emit a "current" value
but when a stream emits current value it's different from subscribers perspective than with properties
Roman Pominov
@rpominov
Feb 08 2015 07:21
when a stream emits current value in response of first subscription only first subscriber gets this value
to sum up: you have to convert both you streams to properties, then combine those properties, and also convert the result stream to a property
(last bit in case you want all subscribers of combined observable to get first value)
Roman Pominov
@rpominov
Feb 08 2015 07:27
btw, when a stream emits a value immediately — in response to first subscription (which can be done if you emit in .fromBinder callback for example), this value also will be marked as "current"
another example when stream emits "current", is when you .merge properties

2) it would be correct semantically

sorry, it should be "would not" here

Roman Pominov
@rpominov
Feb 08 2015 07:35
i probably should add "streams and current values" section to the docs
David Thompson
@davexunit
Feb 08 2015 14:17
thanks for the explanation @pozadi