Batman.View is rendered, it goes through many steps. Lifecycle callbacks allow you to hook into those steps and control or respond to the rendering process.
Listening for Lifecycle Events
To set up handlers for a
View's lifecycle, You can either call
on on the
class MyApp.FadingView extends Batman.View @::on 'viewWillAppear', -> $(@get('node')).hide() @::on 'viewDidAppear', -> $(@get('node')).fadeIn('fast') @::on 'viewWillDisappear', -> $(@get('node')).fadeOut('fast')
or define functions with the same name as the events:
class MyApp.FadingView extends Batman.View viewWillAppear: -> $(@get('node')).hide() viewDidAppear: -> $(@get('node')).fadeIn('fast') viewWillDisappear: -> $(@get('node')).fadeOut('fast')
Lifecycle Events and Subviews
View propagates its lifecycle events to its
subviews, so it's likely that a lifecycle event will be called more than once.
ready is an exception -- it's a one-shot event.
The view is about to be attached to the DOM. It has a
The view has just been attached to the DOM. Its
nodeis on the page and can be selected with
The view's bindings have been initialized. The view may or may not be in the DOM.
readyis a one-shot event.
diewas called on this view. It will be removed from its superview, removed from the DOM, and have all of its properties set to
The view has been attached to its
superview, but it is not yet in the DOM.
The view is about removed from its
superview, then it will be detached from the DOM.