Skip to content
This repository has been archived by the owner on Jan 6, 2019. It is now read-only.

Auto Remove

William Meleyal edited this page May 30, 2013 · 3 revisions

Backbone.Widget can optionally remove itself on a given event.

This can be useful if you're using pjax / turbolinks and need to routinely cleanup views between "page loads".

Define the uninstall event

Backbone.Widget.removeEvent = 'page:change'

Default remove()

View.remove() will now automatically be called whenever the removeEvent fires.

Custom remove()

If you define your own remove method, you need to also call "super" so Backbone.Widget can perform it's own cleanup. This will hopefully be fixed in a future release.

JavaScript
MyView = Backbone.Widget.extend({
  remove: function() {
    Backbone.Widget.prototype.remove.call(this) // 'super'
    // your custom cleanup...
  }
})
CoffeeScript
MyView extends Backbone.Widget
  remove: ->
    super
    # your custom cleanup...
Clone this wiki locally