Skip to content

Instantly share code, notes, and snippets.

@christocracy
Created June 23, 2011 12:13
Show Gist options
  • Select an option

  • Save christocracy/1042436 to your computer and use it in GitHub Desktop.

Select an option

Save christocracy/1042436 to your computer and use it in GitHub Desktop.
Plugin lifecycle
// @_jdg Ok, I think I see where you're going, you're saying you can't do this:
//
Ext.define('MyClass', {
extend: 'Ext.panel.Panel',
initComponent: function() {
Ext.apply(this, {
plugins: ['my-plugin'],
.
.
.
});
}
});
// But why not do this?
Ext.define('MyClass', {
extend: 'Ext.panel.Panel',
plugins: ['my-plugin']
});
if (me.plugins) {
me.plugins = [].concat(me.plugins);
for (i = 0, len = me.plugins.length; i < len; i++) {
// 1. Instantiate plugins before #initComponent. This is nice because it give plugins
// a chance to manipulate assets of this component as *literals*.
// Things such as #items, #dockedItems, etc.
//
me.plugins[i] = me.constructPlugin(me.plugins[i]);
}
}
// 2. #initComponent fires...
me.initComponent();
.
.
.
// 3. Usual plugin init phase *after* #initComponent
if (me.plugins) {
me.plugins = [].concat(me.plugins);
for (i = 0, len = me.plugins.length; i < len; i++) {
me.plugins[i] = me.initPlugin(me.plugins[i]);
}
}
@jaygarcia
Copy link

The second example (line 17) is very rigid for a lot of complex apps that i've worked with, where having proper abstract classes require easy dynamic enabling of plugins.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment