Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save thanpolas/4755808 to your computer and use it in GitHub Desktop.
Save thanpolas/4755808 to your computer and use it in GitHub Desktop.
LayoutManager `beforeRender()` and `render()` callback scaffoldings.
/**
* The beforeRender callback scaffolding.
*
* @param {Backbone.Layout} view The instance of the LayoutManager.
* @return {void} Don't care.
*/
beforeRender: function( view ) {
console.log(view.template); // show the template of the view instance
// optionally beforeRender can be async
var done = this.async();
asyncMethod( function() {
// do not perform render, render() callback is never called
view.preventDOM();
// pass controll back to LM
done();
});
},
/**
* The render callback scaffolding.
*
* @param {Function} template The template func.
* @param {Object} context The context of the template.
* @param {Backbone.Layout} view The instance of the LayoutManager.
* @return {string} The rendered templated.
*/
render: function( template, context, view ) {
console.log(view.template); // show the template of the view instance
// optionally beforeRender can be async
var done = this.async();
asyncMethod( function() {
// do not perform render, render() callback is never called
view.preventDOM();
// pass controll back to LM, no need to pass arguments.
done();
});
// ... or plainly render the template
return template( context );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment