PDA

View Full Version : Ext.clone a store



Webtel
19 Mar 2012, 3:19 AM
i have a store_A and i want to have one more, similar to this (model,proxy) but loaded independent.

when i do it like : (ExtJS 4.07)

store_B = Ext.clone(store_A);

and then :


store_A.load();
store_B.removeAll();


... both are empty in the end (like they were one object - but documentation says reference should be dropped by Ext.clone.. )

Is it a bug? or am i doing something wrong?

Is it obligatory to define whole new store separately just for having 2 data sets of same model and source?

PS. following makes no difference.

var store_B = Ext.apply({},store_A);

Webtel
19 Mar 2012, 3:47 AM
to achieve store cloning i use function similar to following:


clone = function(dict){
return Ext.create(dict.$className,{
proxy:{
url:dict.proxy.url,
type: 'ajax',
extraParams:dict.proxy.extraParams,
simpleSortMode : true,
reader: {
type: 'json',
root: 'rows',
totalProperty:'total',
successProperty: 'success',
idProperty:dict.proxy.reader.idProperty
}
}
});
}

chramer
19 Mar 2012, 3:53 AM
or maybe just :


Ext.define('definedStore', {...});
storeA = Ext.create('definedStore');
storeB = Ext.create('definedStore');

evant
19 Mar 2012, 4:06 AM
Clone is only intended to be used on "primitive" type objects, data stores have a whole bunch of complexity that mean they can't really be cloned in a generic manner.

Webtel
19 Mar 2012, 4:07 AM
@chramer (http://www.sencha.com/forum/member.php?240566-chramer)
actualy i have one generic store class for all combos. then i create instances of particular lists only chainging proxy extra params.

so i need a copy of already created store because :
- i dont want to rewrite each proxy by hand
- and also i dont want to have 200 separate store class definitions.(for readability sake)

going Your way leads to deifining 200 classes only differing with one extraParam (wile i need just one). Plus 300 instantiations.

The other way is like 1 class definition. Plus 200 instantiations. Plus 100 cloning.