Skip to content

Instantly share code, notes, and snippets.

@ExtAnimal
Created July 15, 2013 01:47
Show Gist options
  • Star 15 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ExtAnimal/c93148f5194f2a232464 to your computer and use it in GitHub Desktop.
Save ExtAnimal/c93148f5194f2a232464 to your computer and use it in GitHub Desktop.
LazyItems plugin
/**
* This plugin defers the execution cost of the instantiation and initialization of child components of unrendered items.
*
* For example, in a {@link Ext.tab.Panel#deferredRender deferredRender} {Ext.tab.Panel TabPanel}, the unrendered tabs
* do not have to incur the cost of instantiating and initializing their descendant components until render.
*
* This plugin allows that.
*
* Add the items to the plugin:
*
* {
* xtype: 'tabpanel',
* items: [{
* title: 'Tab One',
* plugins: {
* ptype: 'lazyitems',
* items: [... tab's child items...]
* }
* }, {
* title: 'Tab One',
* plugins: {
* ptype: 'lazyitems',
* items: [... tab's child items...]
* }
* }]
* }
*
*/
Ext.define('Ext.LazyItems', {
extend: 'Ext.AbstractPlugin',
alias: 'plugin.lazyitems',
init: function(comp) {
this.callParent(arguments);
if (this.items) {
// Eager instantiation means create the child items now
if (this.eagerInstantiation) {
this.items = comp.prepareItems(this.items);
}
}
// We need to jump in right before the beforeRender call
comp.beforeRender = Ext.Function.createInterceptor(comp.beforeRender, this.beforeComponentRender, this);
},
// Add the child items at the last possible moment.
beforeComponentRender: function() {
this.cmp.add(this.items);
// Remove the interceptor
delete this.cmp.beforeComponentRender;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment