Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/views/view.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ class Mildred.View extends Backbone.View
@listenTo @collection, 'dispose', (subject) =>
@dispose() if not subject or subject is @collection

# Wrap render method with after and before callbacks
@render = _.wrap(@render, (render) =>
@beforeRender()
render()
@afterRender()
)

# Render automatically if set by options or instance property.
@render() if @autoRender

Expand Down Expand Up @@ -320,6 +327,12 @@ class Mildred.View extends Backbone.View
# Return the view.
this

# Default void callbacks for before and after rendering
# The key different between `afterRender` to `attach` method is attach
# executed only once after initializing the view and not after each render.
beforeRender: ->
afterRender: ->

# This method is called after a specific `render` of a derived class.
attach: ->
# Automatically append to DOM if the container element is set.
Expand Down