These are chat archives for pozadi/kefir

11th
Feb 2015
Ulric Wilfred
@shamansir
Feb 11 2015 17:16
is it possible to implement something like .repeat() in Kefir, i.e. when given stream ends, emit values again from the start?. It’s an emitter-based stream, btw.
Ulric Wilfred
@shamansir
Feb 11 2015 17:56
PS. I think on renaming RPD to Ayran.js, someone suggested it to me and I think it perfectly fits :D. Built on Kefir.js, Reactive...
Roman Pominov
@rpominov
Feb 11 2015 18:36
heh, because of Bacon all frp related stuff will be named after some food :)
about .repeat(), it's possible to implement but there will be not much help from Kefir methods, if you implement it yourself
you'll need to record events log from the observable, and then rerun that log somehow
recording can be done using .timestamp and .reduce
Roman Pominov
@rpominov
Feb 11 2015 18:42
but i think there is no methods that could help to rerun log like that
not sure about adding .repeat() to the core
Ulric Wilfred
@shamansir
Feb 11 2015 18:47
In my case emitter is actually based on some function (fromBinder), so I could just re-spawn it. I am also not sure about adding it -> if there’s no such way from the core now already, so be it :).
Roman Pominov
@rpominov
Feb 11 2015 18:49
ah, if you have source that could just emit all events again it became much easier
Ulric Wilfred
@shamansir
Feb 11 2015 18:50
yeah, I just realized that for my case it really is. thank you!
Roman Pominov
@rpominov
Feb 11 2015 18:50
i'm thinking of adding .looper method described here baconjs/bacon.js#521
if i understand your case correctly you'll be able to make use of .looper
Ulric Wilfred
@shamansir
Feb 11 2015 20:49
yeah, it would be cool! I also kinda dislike the timeout-driven way.
Ulric Wilfred
@shamansir
Feb 11 2015 21:15
seems, being translated to Kefir terms it looks like:
function looper(fn) {
  return Kefir.fromBinder(function(sink) {
    var stream, valHandler, endHandler;
    function sub() {
        valHandler = function(v) { sink.emit(v); };
        endHandler = function() { sub() };
        stream = fn(); 
        stream.onValue(valHandler).onEnd(endHandler);
    }
    sub();
    return function() {
      stream.offValue(valHandler).offEnd(endHandler);
    };
  });
}
a dangerous thing, though, if you turn on the .log for the resulting stream :)
Ulric Wilfred
@shamansir
Feb 11 2015 21:24
but also I realized that my problem is a bit more complex. I actually want to zip several streams the way like if one of them was finished before the others, this stream [re-spawns and] loops from the start, but the zipped stream should end when last inner stream was finished—and I am still unable to determine which one is the “longest” one.
Ulric Wilfred
@shamansir
Feb 11 2015 21:29
…at least unless I add some counter which will reduce when one of the streams was restarted :)
Ulric Wilfred
@shamansir
Feb 11 2015 22:55
may be it’s wrong to use onValue here, since this way sub() keeps to be called even if the resulting stream was stopped by takeWhile.
oh, withHandler. got it :)