kefirjs / kefir

A Reactive Programming library for JavaScript
https://kefirjs.github.io/kefir/
MIT License
1.87k stars 97 forks source link

BufferWhileBy should flush source stream on falsy events from "otherObs" #116

Closed shamansir closed 9 years ago

shamansir commented 9 years ago

Instead of flushing on the next event from the source stream. So it should rather be like:

var foo = Kefir.sequentially(100, [1, 2, 3, 4, 5, 6, 7, 8]);
var bar = Kefir.sequentially(200, [false, true, false]).delay(40);
var result = foo.bufferWhileBy(bar);
result.log();
> [sequentially.bufferWhileBy] <value> [1, 2]
> [sequentially.bufferWhileBy] <value> [3]
> [sequentially.bufferWhileBy] <value> [4]
> [sequentially.bufferWhileBy] <value> [5, 6]
> [sequentially.bufferWhileBy] <value> [7]
> [sequentially.bufferWhileBy] <value> [8]
> [sequentially.bufferWhileBy] <end>
foo:     ----1----2----3----4----5----6----7----8X
bar:     -----------f---------t---------fX

result:  -----------•--•----•-----------•--•----•X
               [1, 2] [3]  [4]     [5, 6] [7]  [8]
rpominov commented 9 years ago

I've added an option for this. Will it solve your problem? Also can you try it out before we release (it in master now)?

shamansir commented 9 years ago

Here's my implementation where it is flushed this way by default. I'll try your version in few minutes, thank you!

shamansir commented 9 years ago

Yes, it works the same way as I expected with even fewer changes, thank you once again! :)

rpominov commented 9 years ago

Released in 2.7.0