Skip to content

Instantly share code, notes, and snippets.

@lupos
Created December 15, 2015 16:51
Show Gist options
  • Select an option

  • Save lupos/bff3eddcb00720024a2a to your computer and use it in GitHub Desktop.

Select an option

Save lupos/bff3eddcb00720024a2a to your computer and use it in GitHub Desktop.
A sample of a custom render function for server side rendering
/**
* Override the Marionette.ItemView.render to help us with server-side renders
*
* @todo Add check to only do this if it's the inital render (use router + global to keep track)
*/
var oldRender = Marionette.ItemView.prototype.render;
Marionette.ItemView.prototype.render = function() {
var el;
// safety check incase id wasn't defined
if( !_.isUndefined( this.el.id ) && !_.isEmpty( this.el.id ) ) {
el = document.getElementById( this.el.id );
} else {
return oldRender.apply(this, arguments);
}
// if we have an id and the element already exists, it was rendered server-side
if( !_.isUndefined( el ) && el && QZ.initialRender ) {
//console.log(this.el.id + ' rendered server-side');
this.el = el;
this._ensureViewIsIntact();
this.triggerMethod('before:render', this);
this.setElement( this.el );
this.isRendered = true;
this.bindUIElements();
this.triggerMethod('render', this);
return this;
// normal render
} else {
//console.log(this.el.id + ' rendered client-side');
return oldRender.apply(this, arguments);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment