StoreManager.html 5.6 KB

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