These are chat archives for pozadi/kefir

14th
Aug 2015
findjashua
@findjashua
Aug 14 2015 04:15
hi @rpominov, i was wondering if there is a counterpart to rxjs's forkJoin in kefir
forkJoin is basically combineFinal or Promise.all
make requests concurrently, but arrange responses in the order of the requests
Roman Pominov
@rpominov
Aug 14 2015 06:24
@findjashua I think Kefir.combine([foo, bar, baz]).last() should do the same job.
findjashua
@findjashua
Aug 14 2015 07:45
thanks @rpominov!
Ulric Wilfred
@shamansir
Aug 14 2015 13:29

I have a situation like:

streamOne.bufferWhileBy(streamTwo.filter(someFilter)
                                     .mapTo(false)
                                     .toProperty(true), 
                                     { flushOnChange: true })
             .take(1).flatten().onValue(handlerOne)
                               .onEnd(handlerTwo);

This way I wanted to ensure handlerTwo will be called after at least one value from streamTwo will fire and all the corresponding handlerOne calls (as a reactions to streamOne events) will perfom before handlerTwo. But then I realized I also need to call handlerTwo even when no streamOne events were fired before streamTwo call. But so there’s no event before take(1). Is there way to do with minimum changes to this construction?

(fixed the code :))
Ulric Wilfred
@shamansir
Aug 14 2015 13:37
in other words: I am listening for a first event from streamTwo to collect all the events happened before in streamOne and perform handlerOne for every such event, and then (and only after) I need to call handlerTwo, to confirm I finished processing streamOne. But if no events were fired in streamOne before there was an event in streamTwo, I also need to call handlerTwo, but I can not find the proper place to put this call here.
Ulric Wilfred
@shamansir
Aug 14 2015 14:10
even if I add withHandler to streamTwo to immediately end() at a first falsy value from streamTwo, since streamOne haven’t fired anything, I found no way to call handlerTwo.
Roman Pominov
@rpominov
Aug 14 2015 14:48

@shamansir hm, is

streamOne.bufferWhileBy(streamTwo.filter(someFilter)
                                     .mapTo(false)
                                     .toProperty(true), 
                                     { flushOnChange: true })

fire anything in case "when no streamOne events were fired before streamTwo call"?

Ulric Wilfred
@shamansir
Aug 14 2015 14:49
no, unfortunately, I subscribed to it and it fired nothing
at least in my case
Roman Pominov
@rpominov
Aug 14 2015 14:50

what about

streamTwo.filter(someFilter)
                                     .mapTo(false)
                                     .toProperty(true)

? What it emits?

Ulric Wilfred
@shamansir
Aug 14 2015 14:54
it emits false, that works ok.
Roman Pominov
@rpominov
Aug 14 2015 14:54
also . toProperty should take a functions as argument :)
shouldn't it emit true, false?
Ulric Wilfred
@shamansir
Aug 14 2015 14:54
yeah, that’s fixed in my code, but I got a habit :)
yeah, true, false
I’ll make a fiddle
could be my environment, would be nice to test it isolated
Roman Pominov
@rpominov
Aug 14 2015 14:56
that should help!
Yep, Kefir.later(1000000000, 1).bufferWhileBy(Kefir.later(1000, false).toProperty(function(){return true}), {flushOnChange: true}).log() also doesn't emit anything.
Ulric Wilfred
@shamansir
Aug 14 2015 15:00
I think it should, or am I wrong?
Roman Pominov
@rpominov
Aug 14 2015 15:02
https://github.com/rpominov/kefir/blob/master/src/two-sources/buffer-while-by.js#L18 — seems like bufferWhileBy never emits empty buffers :(
I think we fixed that in bufferBy, but not in bufferWhileBy
Ulric Wilfred
@shamansir
Aug 14 2015 15:03
yeah, could be :)
Roman Pominov
@rpominov
Aug 14 2015 15:03
I'll take a closer look later!
Ulric Wilfred
@shamansir
Aug 14 2015 15:04
but actually for my case that’s not enough, since it will be called before .take(1)
… though this way I may flatMap it to end if buffer is empty and that would be cool.
Roman Pominov
@rpominov
Aug 14 2015 15:08
I think if we fix it, the following stream will emit [], end, so onEnd handler will be called:
streamOne.bufferWhileBy(streamTwo.filter(someFilter)
                                     .mapTo(false)
                                     .toProperty(true), 
                                     { flushOnChange: true })
             .take(1)
Ulric Wilfred
@shamansir
Aug 14 2015 15:09
oh, yeah, that’s right