Reputation: 25112
Is it possible to subscribe on event when backbonejs view is removed from dom?
I need to handle this to unsubscribe from websocket connection.
Upvotes: 2
Views: 472
Reputation: 25112
It is possible using Jquery UI. I've described solution in my blog: http://zakharov.posterous.com/how-to-handle-when-backbonejs-view-is-remove
Upvotes: 1
Reputation: 9705
You can trigger a custom event on the method which is being called to close down the view. Then just have something listening to this event.
Upvotes: 0
Reputation: 6183
What triggers the removal of the view from the DOM? If the view is managing this removal, whomever created the view or has a reference to the view can register to receive an event that the view can trigger when this DOM removal happens.
I haven't tried it, but you might be able to wire up the DOMNodeRemoved event as an event that the view registers a function for. You would then bubble this DOM event up through your app for any interested listener to respond to.
Upvotes: 0