kefirjs / kefir

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

filterBy activation #167

Closed iofjuupasli closed 8 years ago

iofjuupasli commented 9 years ago
var Kefir = require("kefir");
var a = Kefir.sequentially(1000, [1, 2, 3]);
var b = Kefir.sequentially(1000, [false, false, false]);
a.filterBy(b).log();
console.log(a._active); // true

Seems that a shouldn't be active until b is truthy

rpominov commented 9 years ago

Yeah, you're probably right. And same for skipUntilBy.

Also marking this as [breaking] because this change may potentially break people's code.

iofjuupasli commented 8 years ago

Does it means, that in case a.filterBy(b) errors from a will not flow?

rpominov commented 8 years ago

Hm, yes. I'm not sure which behavior is better here then.

iofjuupasli commented 8 years ago

should be ended if primary was ended also can't be implemented. Only when secondary is truthy.

My case for deactivation - I have external process which is represented as endless stream. It starts external process in stream declaration, and ends it using callback in stream declaration for deactivation. It's important to have child process only when application needs it, listen to it. There is another observable which declare whether this stream required now.

So for my case:

a$.flatMapLatest(a => a ? external$ : Kefir.never())

And it works ok for me. Its behavior almost same as external$.filterBy(a$) except things discussed here.

So we can leave filterBy as is for cases when 'errors' and 'end' are important, and it's ok that primary activated.

rpominov commented 8 years ago

Sounds good to me. I'll close this then, and we can revisit this later.