Last active
December 12, 2015 09:59
-
-
Save thanpolas/4755808 to your computer and use it in GitHub Desktop.
LayoutManager `beforeRender()` and `render()` callback scaffoldings.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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