我是否需要取消订阅以 Kefir 结尾的流的收听者?

Do I need to unsubscribe a listener to stream that ends in Kefir?

我正在从 BaconJS 转移,这不是问题,因为您可以在订阅者中 return Bacon.noMore 取消订阅。在 Kefir 中,取消订阅更多的是样板文件,因此自然的问题是——对于结束的流,您是否需要取消订阅监听器(又名回调)或者 Kefir 是否自动为您处理?

const oneTimeStream = Kefir.constant('foo') // this ends after firing foo
const listener = function() { //... }

oneTimeStream.onValue(listener)
// do I need to unsubscribe #listener?

根据图书馆作者的说法,答案是 "No":https://github.com/rpominov/kefir/issues/182

Yeah, you don't need to. All listeners automatically removed on end. Also when you subscribe to an ended stream it's a noop.

Btw, because of that you can often avoid manual unsubscribing by limiting stream with take/takeWhile/takeUntilBy/etc.

stream.take(1).onValue(fn)