walmartlabs / thorax

Strengthening your Backbone
http://thoraxjs.org/
Other
1.32k stars 129 forks source link

LayoutView will unbind all DOM events when deactivating a retained view #332

Closed jasonwebster closed 10 years ago

jasonwebster commented 10 years ago

I'm using a LayoutView where I'm retaining the views, so they are not destroyed on change. However, setView will still nuke all DOM events bound to the view's element due to it calling oldView.$el.remove().

2 lines later, it also calls this._removeChild(oldView) which will call _destroy on the old view if the retain count is zero (which in turn calls Backbone.View.prototype.remove(), which in turn calls $el.remove).

Current functionality is preserved and reusing view instances is not buggy if we simply change:

oldView.$el && oldView.$el.remove()

to

oldView.$el && oldView.$el.detach()

https://github.com/walmartlabs/thorax/blob/master/src/layout.js#L33

jasonwebster commented 10 years ago

From jQuery docs:

In addition to the elements themselves, all bound events and jQuery data associated with the elements are removed. To remove the elements without removing data and events, use .detach() instead.

jasonwebster commented 10 years ago

Fixed via https://github.com/walmartlabs/thorax/pull/333

kpdecker commented 10 years ago

Released in v3.0.0-alpha.1