kefirjs / kefir

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

question: how to "end" a fromEvents stream #187

Closed boneskull closed 8 years ago

boneskull commented 8 years ago

(Sorry for spamming with questions)

I have a stream created via fromEvents() which will at some point no longer be useful. I'd like to clean it up. How can I cause this stream to end? stream._emit('end') exists, but this is obviously not a public API.

boneskull commented 8 years ago

ok, it appears that fromEvents() will unsubscribe upon deactivation. But I'm having a tough time understanding what deactivation looks like.

rpominov commented 8 years ago

Yeah, you don't have to end each stream in order for it to be garbage collected.

var foo = Kefir.fromEvents(target, 'foo')
foo.onValue(fn)

// now if we want to dispose all resources, all we need to do is:
foo.offValue(fn)
foo = null 

But I'm having a tough time understanding what deactivation looks like.

Did you read this section in the docs? http://rpominov.github.io/kefir/#active-state

boneskull commented 8 years ago

@rpominov Yes...many times, unfortunately. Perhaps that section needs more clarification. I get it now, thanks.