gmac / backbone.epoxy

Declarative data binding and computed models for Backbone
http://epoxyjs.org
MIT License
615 stars 89 forks source link

How to properly clean up collection/model? #76

Closed Prinzhorn closed 10 years ago

Prinzhorn commented 10 years ago

I have a collection binding which renders dozens of Backbone.Epoxy.Models.

If the user updates the search parameters, I use collection.fetch({reset: true}) to fetch new models. (Note: without reset: true I get errors when Backbone tries to merge the models. But I don't need this anyway, reset is fine).

I guess since reset() is used, epoxy will internally use clean to remove all views. Right?

Will this clean up/destroy the model as well? I want the model to be completely cleaned up as well (remove all listeners etc.). I'm asking because after using fetch a second time, the app slowly gets unresponsive.

Edit: Would this be enough before calling reset (I don't need to remotely DELETE the model)?

this.each(function(model) {
    model.clearComputeds();
    model.stopListening();
});
this.fetch({reset: true});
gmac commented 10 years ago

You should just be able to run collection.invoke("clearComputeds"); to remove Epoxy-specific configuration from an entire collection.