Bindable.html 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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-util-Bindable'>/**
  19. </span> * This class is used as a mixin.
  20. *
  21. * This class is to be used to provide basic methods for binding/unbinding stores to other
  22. * classes. In general it will not be used directly.
  23. */
  24. Ext.define('Ext.util.Bindable', {
  25. <span id='Ext-util-Bindable-method-bindStore'> /**
  26. </span> * Binds a store to this instance.
  27. * @param {Ext.data.AbstractStore/String} [store] The store to bind or ID of the store.
  28. * When no store given (or when `null` or `undefined` passed), unbinds the existing store.
  29. * @param {Boolean} [initial=false] True to not remove listeners from existing store.
  30. */
  31. bindStore: function(store, initial){
  32. var me = this,
  33. oldStore = me.store;
  34. if (!initial &amp;&amp; me.store) {
  35. // Perform implementation-specific unbinding operations *before* possible Store destruction.
  36. me.onUnbindStore(oldStore, initial);
  37. if (store !== oldStore &amp;&amp; oldStore.autoDestroy) {
  38. oldStore.destroyStore();
  39. } else {
  40. me.unbindStoreListeners(oldStore);
  41. }
  42. }
  43. if (store) {
  44. store = Ext.data.StoreManager.lookup(store);
  45. me.bindStoreListeners(store);
  46. me.onBindStore(store, initial);
  47. }
  48. me.store = store || null;
  49. return me;
  50. },
  51. <span id='Ext-util-Bindable-method-getStore'> /**
  52. </span> * Gets the current store instance.
  53. * @return {Ext.data.AbstractStore} The store, null if one does not exist.
  54. */
  55. getStore: function(){
  56. return this.store;
  57. },
  58. <span id='Ext-util-Bindable-method-unbindStoreListeners'> /**
  59. </span> * Unbinds listeners from this component to the store. By default it will remove
  60. * anything bound by the bindStoreListeners method, however it can be overridden
  61. * in a subclass to provide any more complicated handling.
  62. * @protected
  63. * @param {Ext.data.AbstractStore} store The store to unbind from
  64. */
  65. unbindStoreListeners: function(store) {
  66. // Can be overridden in the subclass for more complex removal
  67. var listeners = this.storeListeners;
  68. if (listeners) {
  69. store.un(listeners);
  70. }
  71. },
  72. <span id='Ext-util-Bindable-method-bindStoreListeners'> /**
  73. </span> * Binds listeners for this component to the store. By default it will add
  74. * anything bound by the getStoreListeners method, however it can be overridden
  75. * in a subclass to provide any more complicated handling.
  76. * @protected
  77. * @param {Ext.data.AbstractStore} store The store to bind to
  78. */
  79. bindStoreListeners: function(store) {
  80. // Can be overridden in the subclass for more complex binding
  81. var me = this,
  82. listeners = Ext.apply({}, me.getStoreListeners());
  83. if (!listeners.scope) {
  84. listeners.scope = me;
  85. }
  86. me.storeListeners = listeners;
  87. store.on(listeners);
  88. },
  89. <span id='Ext-util-Bindable-method-getStoreListeners'> /**
  90. </span> * Gets the listeners to bind to a new store.
  91. * @protected
  92. * @return {Object} The listeners to be bound to the store in object literal form. The scope
  93. * may be omitted, it is assumed to be the current instance.
  94. */
  95. getStoreListeners: Ext.emptyFn,
  96. <span id='Ext-util-Bindable-method-onUnbindStore'> /**
  97. </span> * Template method, it is called when an existing store is unbound
  98. * from the current instance.
  99. * @protected
  100. * @param {Ext.data.AbstractStore} store The store being unbound
  101. * @param {Boolean} initial True if this store is being bound as initialization of the instance.
  102. */
  103. onUnbindStore: Ext.emptyFn,
  104. <span id='Ext-util-Bindable-method-onBindStore'> /**
  105. </span> * Template method, it is called when a new store is bound
  106. * to the current instance.
  107. * @protected
  108. * @param {Ext.data.AbstractStore} store The store being bound
  109. * @param {Boolean} initial True if this store is being bound as initialization of the instance.
  110. */
  111. onBindStore: Ext.emptyFn
  112. });
  113. </pre>
  114. </body>
  115. </html>