PDA

View Full Version : How are you supposed to use initConfig?



mark0978
13 Nov 2014, 11:56 AM
The docs for initConfig are quite confusing. When I look at the code below, it looks like I'm overriding constructor, but instead of doing this.callParent, I'm calling initConfig.

I'm trying to see what is creating a store in my app. There is no explicit creation of the store, yet I see the proxy making a request for data. I'm trying to figure out how this is happening. I was going to attack the problem by overriding initComponent, but DBStores are evidently not components. They have this initConfig, but the docs for initConfig raise more questions than they answer.

http://docs.sencha.com/extjs/4.2.2/#!/api/Ext.Base-method-initConfig



Ext.define('My.awesome.Class', {
// The default config
config: {
name: 'Awesome',
isAwesome: true
},


constructor: function(config) {
this.initConfig(config);
}
});


var awesome = new My.awesome.Class({
name: 'Super Awesome'
});


alert(awesome.getName()); // 'Super Awesome'


Looks to me like the docs are flawed. By throwing in a debugger; statement, it looks like you need to change the constructor call to at least be



constructor: function(config) {
return this.initConfig(config);
}

since the default constructor is


constructor: function(config) {
return this;
}

and without it


x = Ext.create(....)

would not assign anything.

Also seems that if you follow the docs, the object is not correctly constructed. In the case of a store, the store is NOT added to the StoreManager.

slemmon
17 Nov 2014, 1:39 PM
Hi,

If you're working with a store you won't need to call initConfig directly (most classes you'll work with call that internally for you).

dhk

carol.ext
18 Nov 2014, 10:33 AM
Mark, are you still working on this?

Did you look for a proxy on a model? Put some breakpoints in the Store code? Look at what stores are registered?


console.dir(Ext.StoreManager.getRange());