3 This file is part of Ext JS 4
5 Copyright (c) 2011 Sencha Inc
7 Contact: http://www.sencha.com/contact
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
16 * @class Ext.data.StoreManager
17 * @extends Ext.util.MixedCollection
18 * <p>Contains a collection of all stores that are created that have an identifier.
19 * An identifier can be assigned by setting the {@link Ext.data.AbstractStore#storeId storeId}
20 * property. When a store is in the StoreManager, it can be referred to via it's identifier:
22 Ext.create('Ext.data.Store', {
27 var store = Ext.data.StoreManager.lookup('myStore');
29 * Also note that the {@link #lookup} method is aliased to {@link Ext#getStore} for convenience.</p>
31 * If a store is registered with the StoreManager, you can also refer to the store by it's identifier when
32 * registering it with any Component that consumes data from a store:
34 Ext.create('Ext.data.Store', {
39 Ext.create('Ext.view.View', {
41 // other configuration here
46 * @docauthor Evan Trimboli <evan@sencha.com>
47 * TODO: Make this an AbstractMgr
49 Ext.define('Ext.data.StoreManager', {
50 extend: 'Ext.util.MixedCollection',
51 alternateClassName: ['Ext.StoreMgr', 'Ext.data.StoreMgr', 'Ext.StoreManager'],
53 uses: ['Ext.data.ArrayStore'],
56 * @cfg {Object} listeners @hide
60 * Registers one or more Stores with the StoreManager. You do not normally need to register stores
61 * manually. Any store initialized with a {@link Ext.data.Store#storeId} will be auto-registered.
62 * @param {Ext.data.Store} store1 A Store instance
63 * @param {Ext.data.Store} store2 (optional)
64 * @param {Ext.data.Store} etc... (optional)
66 register : function() {
67 for (var i = 0, s; (s = arguments[i]); i++) {
73 * Unregisters one or more Stores with the StoreManager
74 * @param {String/Object} id1 The id of the Store, or a Store instance
75 * @param {String/Object} id2 (optional)
76 * @param {String/Object} etc... (optional)
78 unregister : function() {
79 for (var i = 0, s; (s = arguments[i]); i++) {
80 this.remove(this.lookup(s));
85 * Gets a registered Store by id
86 * @param {String/Object} id The id of the Store, or a Store instance, or a store configuration
87 * @return {Ext.data.Store}
89 lookup : function(store) {
90 // handle the case when we are given an array or an array of arrays.
91 if (Ext.isArray(store)) {
92 var fields = ['field1'],
93 expand = !Ext.isArray(store[0]),
100 for (i = 0, len = store.length; i < len; ++i) {
101 data.push([store[i]]);
104 for(i = 2, len = store[0].length; i <= len; ++i){
105 fields.push('field' + i);
108 return Ext.create('Ext.data.ArrayStore', {
117 if (Ext.isString(store)) {
119 return this.get(store);
121 // store instance or store config
122 return Ext.data.AbstractStore.create(store);
126 // getKey implementation for MixedCollection
127 getKey : function(o) {
132 * <p>Creates a new store for the given id and config, then registers it with the {@link Ext.data.StoreManager Store Mananger}.
135 Ext.regStore('AllUsers', {
139 //the store can now easily be used throughout the application
145 * @param {String} id The id to set on the new store
146 * @param {Object} config The store config
147 * @param {Constructor} cls The new Component class.
151 Ext.regStore = function(name, config) {
154 if (Ext.isObject(name)) {
157 config.storeId = name;
160 if (config instanceof Ext.data.Store) {
163 store = Ext.create('Ext.data.Store', config);
166 return Ext.data.StoreManager.register(store);
170 * Gets a registered Store by id (shortcut to {@link Ext.data.StoreManager#lookup})
171 * @param {String/Object} id The id of the Store, or a Store instance
172 * @return {Ext.data.Store}
176 Ext.getStore = function(name) {
177 return Ext.data.StoreManager.lookup(name);