PDA

View Full Version : Override config object definition being reused



allistar
4 Feb 2013, 7:01 PM
Hi there,
If we have a component override defined and that override defined an object as part of the config, then it appears like that object is being reused amongst all instances of the component. E.g:



Ext.define('Test.view.NewGrid', {
extend: 'Ext.grid.Panel',

someConfig: { value: 1},

constructor: function() {
me.callParent(arguments);

console.log(me.someConfig.value);
me.someConfig.value = me.someConfig.value + 1
}
});


If you display multiple separate instances of this grid in the browser, the console will have "1, 2, 3, 4" etc.) written to it.

Why is the "someConfig" object being shared amongst all instances of this grid override?

sriram139
5 Feb 2013, 9:28 AM
Nested config is the issue here.
If you try below code, it will work fine where config has value directly, without any sub fields in it.


Ext.define('Test.view.NewGrid', {
extend: 'Ext.grid.Panel',

someConfig: 1,

constructor: function() {
var me = this;
me.callParent(arguments);

console.log(me.someConfig);
me.someConfig= me.someConfig+ 1;
}
});

allistar
5 Feb 2013, 3:34 PM
Hi there,
Yes, I know this problem is with subobjects and not single primitives - the question is "why does it behave like this"?

Thanks,
Allistar.

allistar
12 Feb 2013, 12:20 PM
Anyone? I'd like an understanding of why it behaves like this as it seems pretty fundamental to the way I implement extensions and plugins.