2 * @class Ext.data.StoreManager
3 * @extends Ext.util.MixedCollection
4 * <p>Contains a collection of all stores that are created that have an identifier.
5 * An identifier can be assigned by setting the {@link Ext.data.AbstractStore#storeId storeId}
6 * property. When a store is in the StoreManager, it can be referred to via it's identifier:
8 Ext.create('Ext.data.Store', {
13 var store = Ext.data.StoreManager.lookup('myStore');
15 * Also note that the {@link #lookup} method is aliased to {@link Ext#getStore} for convenience.</p>
17 * If a store is registered with the StoreManager, you can also refer to the store by it's identifier when
18 * registering it with any Component that consumes data from a store:
20 Ext.create('Ext.data.Store', {
25 Ext.create('Ext.view.View', {
27 // other configuration here
32 * @docauthor Evan Trimboli <evan@sencha.com>
33 * TODO: Make this an AbstractMgr
35 Ext.define('Ext.data.StoreManager', {
36 extend: 'Ext.util.MixedCollection',
37 alternateClassName: ['Ext.StoreMgr', 'Ext.data.StoreMgr', 'Ext.StoreManager'],
39 uses: ['Ext.data.ArrayStore'],
42 * @cfg {Object} listeners @hide
46 * Registers one or more Stores with the StoreManager. You do not normally need to register stores
47 * manually. Any store initialized with a {@link Ext.data.Store#storeId} will be auto-registered.
48 * @param {Ext.data.Store} store1 A Store instance
49 * @param {Ext.data.Store} store2 (optional)
50 * @param {Ext.data.Store} etc... (optional)
52 register : function() {
53 for (var i = 0, s; (s = arguments[i]); i++) {
59 * Unregisters one or more Stores with the StoreManager
60 * @param {String/Object} id1 The id of the Store, or a Store instance
61 * @param {String/Object} id2 (optional)
62 * @param {String/Object} etc... (optional)
64 unregister : function() {
65 for (var i = 0, s; (s = arguments[i]); i++) {
66 this.remove(this.lookup(s));
71 * Gets a registered Store by id
72 * @param {String/Object} id The id of the Store, or a Store instance, or a store configuration
73 * @return {Ext.data.Store}
75 lookup : function(store) {
76 // handle the case when we are given an array or an array of arrays.
77 if (Ext.isArray(store)) {
78 var fields = ['field1'],
79 expand = !Ext.isArray(store[0]),
86 for (i = 0, len = store.length; i < len; ++i) {
87 data.push([store[i]]);
90 for(i = 2, len = store[0].length; i <= len; ++i){
91 fields.push('field' + i);
94 return Ext.create('Ext.data.ArrayStore', {
103 if (Ext.isString(store)) {
105 return this.get(store);
107 // store instance or store config
108 return Ext.data.AbstractStore.create(store);
112 // getKey implementation for MixedCollection
113 getKey : function(o) {
118 * <p>Creates a new store for the given id and config, then registers it with the {@link Ext.data.StoreManager Store Mananger}.
121 Ext.regStore('AllUsers', {
125 //the store can now easily be used throughout the application
131 * @param {String} id The id to set on the new store
132 * @param {Object} config The store config
133 * @param {Constructor} cls The new Component class.
137 Ext.regStore = function(name, config) {
140 if (Ext.isObject(name)) {
143 config.storeId = name;
146 if (config instanceof Ext.data.Store) {
149 store = Ext.create('Ext.data.Store', config);
152 return Ext.data.StoreManager.register(store);
156 * Gets a registered Store by id (shortcut to {@link #lookup})
157 * @param {String/Object} id The id of the Store, or a Store instance
158 * @return {Ext.data.Store}
162 Ext.getStore = function(name) {
163 return Ext.data.StoreManager.lookup(name);