Sencha concerns one copy of a store for several stores

So, I have two stores that use the same model, they are absolutely identical in all respects (except for their names, of course). I want two different shops.

app.stores.newsFeed = new Ext.data.Store({ model: 'app.models.feedData', proxy: { type: 'scripttag', url: 'http://query.yahooapis.com/v1/public/yql', extraParams: { format: 'json' }, reader: { root: 'query.results.item' } } }); app.stores.eventsFeed = new Ext.data.Store({ model: 'app.models.feedData', proxy: { type: 'scripttag', url: 'http://query.yahooapis.com/v1/public/yql', extraParams: { format: 'json' }, reader: { root: 'query.results.item' } } }); 

My question is, can I save space by getting rid of the code and using only one store instance, so I don’t need to declare a new new Ext.data.Store file again?

sort of:

 store = new Ext.data.Store(...); app.stores.newsFeed = store; app.stores.eventsFeed = store; 

I tried this before, but both of them were tied to the same repository, so when it was changed, it was different.

+4
source share
1 answer

Just extend the extJS component, and you can quickly get instances of your component:

 MyStore = Ext.extend(Ext.data.Store, { constructor : function(config) { config = Ext.apply({ model: 'app.models.feedData', proxy: { type: 'scripttag', url: 'http://query.yahooapis.com/v1/public/yql', extraParams: { format: 'json' }, reader: { root: 'query.results.item' } } }, config); MyStore.superclass.constructor.call(this, config); }, onDestroy : function(config) { MyStore.superclass.onDestroy.apply(this, arguments); } }); 

Create as many independent objects as you want:

 app.stores.newsFeed = Ext.create(MyStore, {}); app.stores.eventsFeed = Ext.create(MyStore, {}); 
+6
source