Skip to content

Instantly share code, notes, and snippets.

Created June 18, 2012 17:25
Show Gist options
  • Select an option

  • Save anonymous/2949517 to your computer and use it in GitHub Desktop.

Select an option

Save anonymous/2949517 to your computer and use it in GitHub Desktop.
// Virbone.View is a subclass of Backbone.View, with our own customizations of event-handling
MyView = Virbone.View.extend({
modelEvents: {
// the binding of modelEvents knows the special keywords
// `model` and `collection`
"change:data model": "onDataUpdate",
"add collection": "onModelAdded",
// if the subject is other than `model` and `collection`,
// the subject-key is looked up in the options-object
"change:otherData otherModelInOptions": "onOtherDataUpdate"
},
// bind events to the pub/sub-system
messengerEvents: {
"page.new": "onNewPage"
},
initialize: function() {
this.addSubView("otherView", new OtherView());
},
teardown: function() {
// this function will be called when the view is removed using remove().
// any custom events bound that is not model or messenger should be unbound here
}
});
myView = new MyView();
// Unbinds model and messenger updates and escaletas the remove-call to myView's subviews, and teardown()
// is called for the view
myView.remove();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment