PDA

View Full Version : [CLOSED] when setting extraParams, it sets all instance of store.



k_cire0426
10 Oct 2014, 1:03 AM
when setting extraParams, it sets all instance of store.

https://fiddle.sencha.com/#fiddle/bjo

nikolay.bobrovskiy
10 Oct 2014, 10:53 PM
The stores are sharing the same proxy.

console.log(store1.getProxy() === store2.getProxy());
Returns true.
If you add proxy definition to store you'll see it behaves like you expect:

me.callParent([Ext.apply({ storeId : 'testStore',
model : 'App.model.Test',
proxy: {
type: 'ajax'
}
}, cfg)]);

k_cire0426
12 Oct 2014, 7:39 PM
What if the proxy definition defines on the model? Would it be still necessary to define the proxy whenever we create store? That is repetitive of work.

btw, sencha team, cannot reproduce this, but it clearly shows on the fiddle.

nikolay.bobrovskiy
12 Oct 2014, 9:04 PM
Maybe they consider it a feature to have a common proxy for all stores if proxy defined in model.

evant
12 Oct 2014, 9:33 PM
The notification says:



Looks like we can't reproduce the issue or there's a problem in the test case provided.


In this case it's the second one. As @nikolay.bobrovskiy stated above, if a store does not have a proxy, then it uses the shared instance on the Model.

k_cire0426
12 Oct 2014, 9:36 PM
Ok I understand now. It's just confusing, because I expect that new instance of store creates new instances as well of its config and properties.

nikolay.bobrovskiy
25 Oct 2014, 1:16 AM
One of possible workarounds:

Ext.define('MyStore', {
extend: 'Ext.data.Store',
model: 'MyModel',

proxy: Ext.apply({}, {
// Add here some proxy properties customizations for this store if needed.
},
MyModel.proxyConfig)
});

Mahmoud690
7 Dec 2014, 11:36 PM
But I think it is a bug! If not, SENCHA TEAM should point it clearly in documents. Expecting to use model proxy means use of its DEFINITION not sharing it among of all instances. If you think this functionality is good, you should add a new config feature to allow user enable/disable it.

Anyway , another work-around is :


Ext.override(Ext.data.Store, {
constructor: function () {
if (!this.config.proxy && this.config.model) {
var model = Ext.data.schema.Schema.lookupEntity(this.config.model);
this.config.proxy = model.proxyConfig;
}


return this.callParent(arguments);
},
}

nikolay.bobrovskiy
13 Dec 2014, 2:34 AM
I agree, at least docs should mention that model proxy is shared.

nikolay.bobrovskiy
21 Jan 2015, 4:37 PM
Because model proxy is reused in other places (besides store, for example, in Ext.data.session.BatchVisitor.getBatch()) I had to do the following override to have independent proxy instances:


Ext.define('OMR.override.data.Model', {
override: 'Ext.data.Model',


getProxy: function () {
delete this.self.proxy;
return this.callParent(arguments);
}
});