Created
June 23, 2011 12:13
-
-
Save christocracy/1042436 to your computer and use it in GitHub Desktop.
Plugin lifecycle
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
| // @_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]); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.