Skip to content

Events

Tim Branyen edited this page Feb 11, 2015 · 7 revisions

Events are important, yet the source of mismanaged memory in Backbone applications. LayoutManager has been designed to provide you useful events and cleaning them up correctly.

Built in events

There are two built in events inside of LayoutManager: beforeRender and afterRender.

beforeRender

This event is called on the View that had render triggered on it. You must have this event bound before rendering. This is useful for modifying the state of the layout, before it is rendered. It is triggered after the beforeRender function.

myLayout.on("beforeRender", function(view) {
  // Do something to view, before rendered.
});

afterRender

This event is called on the View that had render triggered on it. You must have this event bound before rendering. This is useful for modifying the rendered contents of the layout, after it is rendered. It is triggered after the afterRender function.

myLayout.on("afterRender", function(view) {
  // Do something to view, after rendered.
});

empty

This event is called on a View when all of its nested child Views have been removed.

myLayout.on("empty", function(view) {
  // Do something to view, after all nested Views are removed.
});

Cleanup

Assuming you have an event-driven application designed, you'll need to ensure those events are properly cleaned up. As of Backbone 0.9.9 any events bound with listenTo will be automatically cleaned up after calling stopListening. LayoutManager will automatically perform this task for you at the appropriate time. It will also continue to clean up events bound with on on the model and collection properties.

Something went wrong with that request. Please try again.