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 * @docauthor Evan Trimboli <evan@sencha.com>
18 * Contains a collection of all stores that are created that have an identifier. An identifier can be assigned by
19 * setting the {@link Ext.data.AbstractStore#storeId storeId} property. When a store is in the StoreManager, it can be
20 * 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.
31 * If a store is registered with the StoreManager, you can also refer to the store by it's identifier when registering
32 * 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
45 Ext.define('Ext.data.StoreManager', {
46 extend: 'Ext.util.MixedCollection',
47 alternateClassName: ['Ext.StoreMgr', 'Ext.data.StoreMgr', 'Ext.StoreManager'],
49 uses: ['Ext.data.ArrayStore'],
52 * @cfg {Object} listeners @hide
56 * Registers one or more Stores with the StoreManager. You do not normally need to register stores manually. Any
57 * store initialized with a {@link Ext.data.Store#storeId} will be auto-registered.
58 * @param {Ext.data.Store...} stores Any number of Store instances
60 register : function() {
61 for (var i = 0, s; (s = arguments[i]); i++) {
67 * Unregisters one or more Stores with the StoreManager
68 * @param {String/Object...} stores Any number of Store instances or ID-s
70 unregister : function() {
71 for (var i = 0, s; (s = arguments[i]); i++) {
72 this.remove(this.lookup(s));
77 * Gets a registered Store by id
78 * @param {String/Object} store The id of the Store, or a Store instance, or a store configuration
79 * @return {Ext.data.Store}
81 lookup : function(store) {
82 // handle the case when we are given an array or an array of arrays.
83 if (Ext.isArray(store)) {
84 var fields = ['field1'],
85 expand = !Ext.isArray(store[0]),
92 for (i = 0, len = store.length; i < len; ++i) {
93 data.push([store[i]]);
96 for(i = 2, len = store[0].length; i <= len; ++i){
97 fields.push('field' + i);
100 return Ext.create('Ext.data.ArrayStore', {
109 if (Ext.isString(store)) {
111 return this.get(store);
113 // store instance or store config
114 return Ext.data.AbstractStore.create(store);
118 // getKey implementation for MixedCollection
119 getKey : function(o) {
124 * Creates a new store for the given id and config, then registers it with the {@link Ext.data.StoreManager Store Mananger}.
127 * Ext.regStore('AllUsers', {
131 * // the store can now easily be used throughout the application
137 * @param {String} id The id to set on the new store
138 * @param {Object} config The store config
142 Ext.regStore = function(name, config) {
145 if (Ext.isObject(name)) {
148 config.storeId = name;
151 if (config instanceof Ext.data.Store) {
154 store = Ext.create('Ext.data.Store', config);
157 return Ext.data.StoreManager.register(store);
161 * Shortcut to {@link Ext.data.StoreManager#lookup}.
164 * @alias Ext.data.StoreManager#lookup
166 Ext.getStore = function(name) {
167 return Ext.data.StoreManager.lookup(name);