StoreManager.html
5.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>The source code</title>
<link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../resources/prettify/prettify.js"></script>
<style type="text/css">
.highlight { display: block; background-color: #ddd; }
</style>
<script type="text/javascript">
function highlight() {
document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
}
</script>
</head>
<body onload="prettyPrint(); highlight();">
<pre class="prettyprint lang-js"><span id='Ext-data-StoreManager'>/**
</span> * @docauthor Evan Trimboli <evan@sencha.com>
*
* Contains a collection of all stores that are created that have an identifier. An identifier can be assigned by
* setting the {@link Ext.data.AbstractStore#storeId storeId} property. When a store is in the StoreManager, it can be
* referred to via it's identifier:
*
* Ext.create('Ext.data.Store', {
* model: 'SomeModel',
* storeId: 'myStore'
* });
*
* var store = Ext.data.StoreManager.lookup('myStore');
*
* Also note that the {@link #lookup} method is aliased to {@link Ext#getStore} for convenience.
*
* If a store is registered with the StoreManager, you can also refer to the store by it's identifier when registering
* it with any Component that consumes data from a store:
*
* Ext.create('Ext.data.Store', {
* model: 'SomeModel',
* storeId: 'myStore'
* });
*
* Ext.create('Ext.view.View', {
* store: 'myStore',
* // other configuration here
* });
*
*/
Ext.define('Ext.data.StoreManager', {
extend: 'Ext.util.MixedCollection',
alternateClassName: ['Ext.StoreMgr', 'Ext.data.StoreMgr', 'Ext.StoreManager'],
singleton: true,
uses: ['Ext.data.ArrayStore'],
<span id='Ext-data-StoreManager-cfg-listeners'> /**
</span> * @cfg {Object} listeners
* @private
*/
<span id='Ext-data-StoreManager-method-register'> /**
</span> * Registers one or more Stores with the StoreManager. You do not normally need to register stores manually. Any
* store initialized with a {@link Ext.data.Store#storeId} will be auto-registered.
* @param {Ext.data.Store...} stores Any number of Store instances
*/
register : function() {
for (var i = 0, s; (s = arguments[i]); i++) {
this.add(s);
}
},
<span id='Ext-data-StoreManager-method-unregister'> /**
</span> * Unregisters one or more Stores with the StoreManager
* @param {String/Object...} stores Any number of Store instances or ID-s
*/
unregister : function() {
for (var i = 0, s; (s = arguments[i]); i++) {
this.remove(this.lookup(s));
}
},
<span id='Ext-data-StoreManager-method-lookup'> /**
</span> * Gets a registered Store by id
* @param {String/Object} store The id of the Store, or a Store instance, or a store configuration
* @return {Ext.data.Store}
*/
lookup : function(store) {
// handle the case when we are given an array or an array of arrays.
if (Ext.isArray(store)) {
var fields = ['field1'],
expand = !Ext.isArray(store[0]),
data = store,
i,
len;
if(expand){
data = [];
for (i = 0, len = store.length; i < len; ++i) {
data.push([store[i]]);
}
} else {
for(i = 2, len = store[0].length; i <= len; ++i){
fields.push('field' + i);
}
}
return new Ext.data.ArrayStore({
data : data,
fields: fields,
autoDestroy: true,
autoCreated: true,
expanded: expand
});
}
if (Ext.isString(store)) {
// store id
return this.get(store);
} else {
// store instance or store config
return Ext.data.AbstractStore.create(store);
}
},
// getKey implementation for MixedCollection
getKey : function(o) {
return o.storeId;
}
}, function() {
<span id='Ext-method-regStore'> /**
</span> * Creates a new store for the given id and config, then registers it with the {@link Ext.data.StoreManager Store Manager}.
* Sample usage:
*
* Ext.regStore('AllUsers', {
* model: 'User'
* });
*
* // the store can now easily be used throughout the application
* new Ext.List({
* store: 'AllUsers',
* ... other config
* });
*
* @param {String} id The id to set on the new store
* @param {Object} config The store config
* @member Ext
* @method regStore
*/
Ext.regStore = function(name, config) {
var store;
if (Ext.isObject(name)) {
config = name;
} else {
config.storeId = name;
}
if (config instanceof Ext.data.Store) {
store = config;
} else {
store = new Ext.data.Store(config);
}
return Ext.data.StoreManager.register(store);
};
<span id='Ext-method-getStore'> /**
</span> * Shortcut to {@link Ext.data.StoreManager#lookup}.
* @member Ext
* @method getStore
* @inheritdoc Ext.data.StoreManager#lookup
*/
Ext.getStore = function(name) {
return Ext.data.StoreManager.lookup(name);
};
});
</pre>
</body>
</html>