PageRenderTime 49ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/ajax/libs/yui/3.10.0/base-observable/base-observable-debug.js

https://gitlab.com/Mirros/cdnjs
JavaScript | 209 lines | 72 code | 30 blank | 107 comment | 12 complexity | 8d40607a2022fb3b87fbfadb5b4706f5 MD5 | raw file
  1. YUI.add('base-observable', function (Y, NAME) {
  2. /**
  3. The `base-observable` submodule adds observability to Base's lifecycle and
  4. attributes, and also make it an `EventTarget`.
  5. @module base
  6. @submodule base-observable
  7. **/
  8. var L = Y.Lang,
  9. DESTROY = "destroy",
  10. INIT = "init",
  11. BUBBLETARGETS = "bubbleTargets",
  12. _BUBBLETARGETS = "_bubbleTargets",
  13. AttributeObservable = Y.AttributeObservable,
  14. BaseCore = Y.BaseCore;
  15. /**
  16. Provides an augmentable implementation of lifecycle and attribute events for
  17. `BaseCore`.
  18. @class BaseObservable
  19. @extensionfor BaseCore
  20. @uses AttributeObservable
  21. @uses EventTarget
  22. @since 3.8.0
  23. **/
  24. function BaseObservable() {}
  25. BaseObservable._ATTR_CFG = AttributeObservable._ATTR_CFG.concat();
  26. BaseObservable._NON_ATTRS_CFG = ["on", "after", "bubbleTargets"];
  27. BaseObservable.prototype = {
  28. /**
  29. * Initializes Attribute
  30. *
  31. * @method _initAttribute
  32. * @private
  33. */
  34. _initAttribute: function() {
  35. BaseCore.prototype._initAttribute.apply(this, arguments);
  36. AttributeObservable.call(this);
  37. this._eventPrefix = this.constructor.EVENT_PREFIX || this.constructor.NAME;
  38. this._yuievt.config.prefix = this._eventPrefix;
  39. },
  40. /**
  41. * Init lifecycle method, invoked during construction.
  42. * Fires the init event prior to setting up attributes and
  43. * invoking initializers for the class hierarchy.
  44. *
  45. * @method init
  46. * @chainable
  47. * @param {Object} config Object with configuration property name/value pairs
  48. * @return {Base} A reference to this object
  49. */
  50. init: function(config) {
  51. /**
  52. * <p>
  53. * Lifecycle event for the init phase, fired prior to initialization.
  54. * Invoking the preventDefault() method on the event object provided
  55. * to subscribers will prevent initialization from occuring.
  56. * </p>
  57. * <p>
  58. * Subscribers to the "after" momemt of this event, will be notified
  59. * after initialization of the object is complete (and therefore
  60. * cannot prevent initialization).
  61. * </p>
  62. *
  63. * @event init
  64. * @preventable _defInitFn
  65. * @param {EventFacade} e Event object, with a cfg property which
  66. * refers to the configuration object passed to the constructor.
  67. */
  68. // PERF: Using lower level _publish() for
  69. // critical path performance
  70. var type = this._getFullType(INIT),
  71. e = this._publish(type);
  72. e.emitFacade = true;
  73. e.fireOnce = true;
  74. e.defaultTargetOnly = true;
  75. e.defaultFn = this._defInitFn;
  76. this._preInitEventCfg(config);
  77. this.fire(type, {cfg: config});
  78. return this;
  79. },
  80. /**
  81. * Handles the special on, after and target properties which allow the user to
  82. * easily configure on and after listeners as well as bubble targets during
  83. * construction, prior to init.
  84. *
  85. * @private
  86. * @method _preInitEventCfg
  87. * @param {Object} config The user configuration object
  88. */
  89. _preInitEventCfg : function(config) {
  90. if (config) {
  91. if (config.on) {
  92. this.on(config.on);
  93. }
  94. if (config.after) {
  95. this.after(config.after);
  96. }
  97. }
  98. var i, l, target,
  99. userTargets = (config && BUBBLETARGETS in config);
  100. if (userTargets || _BUBBLETARGETS in this) {
  101. target = userTargets ? (config && config.bubbleTargets) : this._bubbleTargets;
  102. if (L.isArray(target)) {
  103. for (i = 0, l = target.length; i < l; i++) {
  104. this.addTarget(target[i]);
  105. }
  106. } else if (target) {
  107. this.addTarget(target);
  108. }
  109. }
  110. },
  111. /**
  112. * <p>
  113. * Destroy lifecycle method. Fires the destroy
  114. * event, prior to invoking destructors for the
  115. * class hierarchy.
  116. * </p>
  117. * <p>
  118. * Subscribers to the destroy
  119. * event can invoke preventDefault on the event object, to prevent destruction
  120. * from proceeding.
  121. * </p>
  122. * @method destroy
  123. * @return {Base} A reference to this object
  124. * @chainable
  125. */
  126. destroy: function() {
  127. Y.log('destroy called', 'life', 'base');
  128. /**
  129. * <p>
  130. * Lifecycle event for the destroy phase,
  131. * fired prior to destruction. Invoking the preventDefault
  132. * method on the event object provided to subscribers will
  133. * prevent destruction from proceeding.
  134. * </p>
  135. * <p>
  136. * Subscribers to the "after" moment of this event, will be notified
  137. * after destruction is complete (and as a result cannot prevent
  138. * destruction).
  139. * </p>
  140. * @event destroy
  141. * @preventable _defDestroyFn
  142. * @param {EventFacade} e Event object
  143. */
  144. this.publish(DESTROY, {
  145. fireOnce:true,
  146. defaultTargetOnly:true,
  147. defaultFn: this._defDestroyFn
  148. });
  149. this.fire(DESTROY);
  150. this.detachAll();
  151. return this;
  152. },
  153. /**
  154. * Default init event handler
  155. *
  156. * @method _defInitFn
  157. * @param {EventFacade} e Event object, with a cfg property which
  158. * refers to the configuration object passed to the constructor.
  159. * @protected
  160. */
  161. _defInitFn : function(e) {
  162. this._baseInit(e.cfg);
  163. },
  164. /**
  165. * Default destroy event handler
  166. *
  167. * @method _defDestroyFn
  168. * @param {EventFacade} e Event object
  169. * @protected
  170. */
  171. _defDestroyFn : function(e) {
  172. this._baseDestroy(e.cfg);
  173. }
  174. };
  175. Y.mix(BaseObservable, AttributeObservable, false, null, 1);
  176. Y.BaseObservable = BaseObservable;
  177. }, '@VERSION@', {"requires": ["attribute-observable"]});