baconjs / bacon.model

Model plugin for bacon.js
MIT License
64 stars 15 forks source link

unsubscribe after model.apply #8

Open also opened 10 years ago

also commented 10 years ago

I need to unsubscribe a model from a source added with model.apply.

The unplug function returned by bus.plug isn't returned (https://github.com/baconjs/bacon.model/blob/master/src/bacon.model.coffee#L47), so I can't see how to use the model without leaking memory.

raimohanska commented 10 years ago

My idea is to add an end condition to the source instead. For instance

model.apply(changes.takeUntil(end))

Would this suit your needs? Bus will take care of cleaning up the references on End event, so you don't have to worry about memory.