Skip to content

Instantly share code, notes, and snippets.

@bazilio91
Created February 11, 2014 09:35
Show Gist options
  • Save bazilio91/8931828 to your computer and use it in GitHub Desktop.
Save bazilio91/8931828 to your computer and use it in GitHub Desktop.
Caching Region for Marionette.js
define(['marionette', 'underscore'], function (Marionette, _) {
/**
* @class CachingRegion
*/
return Marionette.Region.extend({
show: function (view) {
this.ensureEl();
this.currentView = view;
if (!_.isUndefined(view.cached)) {
this.open(view);
Marionette.triggerMethod.call(this, 'show', view);
Marionette.triggerMethod.call(view, 'show');
return;
}
view.cached = true;
view.render();
this.open(view);
Marionette.triggerMethod.call(this, 'show', view);
Marionette.triggerMethod.call(view, 'show');
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment