Skip to content

Instantly share code, notes, and snippets.

@chrif
Last active December 11, 2015 08:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrif/4573772 to your computer and use it in GitHub Desktop.
Save chrif/4573772 to your computer and use it in GitHub Desktop.
Ext.override(Ext.data.Store, {
constructor: function(config) {
this.initConfig(config);
this.callParent(arguments);
this.addEvents(
/**
* @event clone
* Fires when a store is cloned
* @param {Ext.data.Store} this
* @param {Ext.data.Store} clone The new clone
*/
'clone'
);
},
/**
* @param preserveLocalCache Preserve local cache of records
* @param cloneRecords If preserveLocalCache is true, also clone local cache of records
* @return {Ext.data.Store}
*/
clone: function(preserveLocalCache, cloneRecords) {
var localCache = this.snapshot || this.data,
config = this.getInitialConfig(),
clone,
records = [];
if (preserveLocalCache) {
if (cloneRecords) {
localCache.each(function(record) {
records.push(record.copy());
});
config.data = records;
} else {
config.data = localCache.items;
}
}
clone = new this.self(config);
this.fireEvent('clone', this, clone);
return clone;
}
});
Ext.override(Ext.form.field.ComboBox, {
/**
* @cfg {Boolean} cloneStore
* Whether to clone the store instance passed in the config
*/
cloneStore: false,
initComponent: function() {
var store = this.store,
preserveLocalCache = this.queryMode == 'local';
if (Ext.isString(store)) {
store = Ext.data.StoreManager.get(store);
}
if (this.cloneStore && store instanceof Ext.data.Store) {
this.store = store.clone(preserveLocalCache);
}
this.callParent();
}
});
@fafk
Copy link

fafk commented Aug 23, 2013

Useful! Good job. :_)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment