PDA

View Full Version : Bug in plugins Initialization ?



alainparis16
14 Jan 2012, 4:53 AM
Hi,
I have define (Ext.define) an object myObject which extend a grid (it could be any other widget).
In the InitComponent of myObject, I add some pluggins : this.plugins = [myNewPlugin] ;
When ExtJS build the object (code of Ext.define('Ext.AbstractComponent', ...), the sequence is:
... me.renderSelectors = me.renderSelectors || {};

if (me.plugins) {
me.plugins = [].concat(me.plugins);
me.constructPlugins();
}
me.initComponent();

Ext.ComponentManager.register(me);

me.mixins.observable.constructor.call(me);

me.mixins.state.constructor.call(me, config);

this.addStateEvents('resize');

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]);
}
}
In fact, me.constructPlugins(); is before me.initComponent(); and the initialization of plugins (me.plugins[i] = me.initPlugin(me.plugins[i]);) is after.
The result is if you redefine plugins inside your initComponent method, they will not be construct !

Why not construct plugins just before init them (and after initComponent) ?
I did it and it seems to work but I don't know if there other effect.

Maybe the dev team could give his feedback.
Thanks.

mitchellsimoens
15 Jan 2012, 2:50 PM
This is working for me:


Ext.define('MyPlugin', {
extend : 'Ext.AbstractPlugin',
alias : 'plugin.myplugin',

init : function(cmp) {
cmp.on('afterrender', function() {
cmp.update('test');
}, this, { single : true });
}
});

Ext.define('MyPanel', {
extend : 'Ext.panel.Panel',

initComponent: function() {
this.plugins = [
{
ptype : 'myplugin'
}
];

this.callParent(arguments);
}
});

Ext.onReady(function() {

new MyPanel({
renderTo : Ext.getBody(),
width : 400,
height : 400,
title : 'Test'
});

});

jay@moduscreate.com
24 Jan 2012, 9:26 AM
Hi,
I have define (Ext.define) an object myObject which extend a grid (it could be any other widget).
In the InitComponent of myObject, I add some pluggins : this.plugins = [myNewPlugin] ;
When ExtJS build the object (code of Ext.define('Ext.AbstractComponent', ...), the sequence is:
... me.renderSelectors = me.renderSelectors || {};

if (me.plugins) {
me.plugins = [].concat(me.plugins);
me.constructPlugins();
}
me.initComponent();

Ext.ComponentManager.register(me);

me.mixins.observable.constructor.call(me);

me.mixins.state.constructor.call(me, config);

this.addStateEvents('resize');

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]);
}
}
In fact, me.constructPlugins(); is before me.initComponent(); and the initialization of plugins (me.plugins[i] = me.initPlugin(me.plugins[i]);) is after.
The result is if you redefine plugins inside your initComponent method, they will not be construct !

Why not construct plugins just before init them (and after initComponent) ?
I did it and it seems to work but I don't know if there other effect.

Maybe the dev team could give his feedback.
Thanks.

I had this argument almost a year ago. The reason is because the "new" way for plugin initialization is via constructor, not the init method. This is what the plugins in the framework operate.

The init method is purely for backwards compatibility.