PDA

View Full Version : Are Stores sharing the same Model objects?



tangix
29 Aug 2012, 12:55 AM
In my app I have the need to display grids of redeemed/non-redeemed vouchers. I setup one Model ("VoucherModel") and configures two JsonP Stores - one for redeemed and one for non-redeemed and ties them up to the VoucherModel. The VoucherModel contains the JsonP Proxy to point to the server. The grids are displayed on separate tabs so I'd like to load them when needed.

When the user logs in I setup the stores with the URLs:

Ext.getStore('ActiveVoucherStore').getProxy().url = UP8.config.backend + 'voucher/active';
Ext.getStore('RedeemedVoucherStore').getProxy().url = UP8.config.backend + 'voucher/redeemed';

The actual result is however that both stores loads the redeemed voucher, leading me to suspect that the Stores shares the Model object.
I have worked around this by defining the JsonP Proxy directly on each Store and it now works - but will the shared Model bite me later?

Thanks,
/Mattias

scottmartin
29 Aug 2012, 6:09 PM
How are you defining your models? Are you placing the details (proxy,etc) in a constructor so they both can create their own instance?

Scott.

tangix
29 Aug 2012, 9:35 PM
I'm using Sencha Architect to create the Model and bind to the Stores. Maybe this is the problem - as I have defined the proxy on the Model I simply deleted it from the Store... I'll try to add the Ext.data.proxy.JsonP to each of the Stores and delete it from the Model.

Ext.define('MyApp.model.VoucherModel', {
extend: 'Ext.data.Model',
alias: 'model.vouchermodel',

proxy: {
type: 'jsonp',
reader: {
type: 'json'
}
}
});

The Store's code is generated as:

Ext.define('MyApp.store.RedeemedVoucherStore', {
extend: 'Ext.data.Store',
alias: 'store.redeemedvoucherstore',

requires: [
'MyApp.model.VoucherModel'
],

constructor: function(cfg) {
var me = this;
cfg = cfg || {};
me.callParent([Ext.apply({
storeId: 'MyJsonPStore1',
model: 'MyApp.model.VoucherModel',
proxy: {
type: 'jsonp',
reader: {
type: 'json'
}
}
}, cfg)]);
}
});