kefirjs / kefir

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

Autobind Stream Instance Methods? #204

Closed mAAdhaTTah closed 8 years ago

mAAdhaTTah commented 8 years ago

In the emitter section, it explains that the emitter's emit method(s) are autobound to the instance so they can be passed in. Is it possible to have a stream's methods bound to its instance as well?

In my case, I'm trying to do something like this:

const stream = Kefir.pool();
events.map(event => fromEvents(event.el, event.type))
  .forEach(stream.plug);

But the plug call fails because this._add does not exist because the this isn't bound correctly. I'm doing forEach(stream.plug.bind(stream)) for now, but that always feels a little ugly.

Thoughts?

rpominov commented 8 years ago

This will be pretty expensive in terms of memory usage per each Stream instance.

mAAdhaTTah commented 8 years ago

Fair enough. I'll stick with stream.plug.bind(stream) method then. Thanks!