2 YUI 3.13.0 (build 508226d)
3 Copyright 2013 Yahoo! Inc. All rights reserved.
4 Licensed under the BSD License.
5 http://yuilibrary.com/license/
8 YUI.add('base-observable', function (Y, NAME) {
11 The `base-observable` submodule adds observability to Base's lifecycle and
12 attributes, and also make it an `EventTarget`.
15 @submodule base-observable
22 BUBBLETARGETS = "bubbleTargets",
23 _BUBBLETARGETS = "_bubbleTargets",
25 AttributeObservable = Y.AttributeObservable,
26 BaseCore = Y.BaseCore;
29 Provides an augmentable implementation of lifecycle and attribute events for
33 @extensionfor BaseCore
34 @uses AttributeObservable
38 function BaseObservable() {}
40 BaseObservable._ATTR_CFG = AttributeObservable._ATTR_CFG.concat();
41 BaseObservable._NON_ATTRS_CFG = ["on", "after", "bubbleTargets"];
43 BaseObservable.prototype = {
46 * Initializes Attribute
48 * @method _initAttribute
51 _initAttribute: function() {
52 BaseCore.prototype._initAttribute.apply(this, arguments);
53 AttributeObservable.call(this);
55 this._eventPrefix = this.constructor.EVENT_PREFIX || this.constructor.NAME;
56 this._yuievt.config.prefix = this._eventPrefix;
60 * Init lifecycle method, invoked during construction.
61 * Fires the init event prior to setting up attributes and
62 * invoking initializers for the class hierarchy.
66 * @param {Object} config Object with configuration property name/value pairs
67 * @return {Base} A reference to this object
69 init: function(config) {
73 * Lifecycle event for the init phase, fired prior to initialization.
74 * Invoking the preventDefault() method on the event object provided
75 * to subscribers will prevent initialization from occuring.
78 * Subscribers to the "after" momemt of this event, will be notified
79 * after initialization of the object is complete (and therefore
80 * cannot prevent initialization).
84 * @preventable _defInitFn
85 * @param {EventFacade} e Event object, with a cfg property which
86 * refers to the configuration object passed to the constructor.
89 // PERF: Using lower level _publish() for
90 // critical path performance
92 var type = this._getFullType(INIT),
93 e = this._publish(type);
97 e.defaultTargetOnly = true;
98 e.defaultFn = this._defInitFn;
100 this._preInitEventCfg(config);
102 if (e._hasPotentialSubscribers()) {
103 this.fire(type, {cfg: config});
106 this._baseInit(config);
108 // HACK. Major hack actually. But really fast for no-listeners.
109 // Since it's fireOnce, subscribers may come along later, so since we're
110 // bypassing the event stack the first time, we need to tell the published
111 // event that it's been "fired". Could extract it into a CE method?
113 e.firedWith = [{cfg:config}];
120 * Handles the special on, after and target properties which allow the user to
121 * easily configure on and after listeners as well as bubble targets during
122 * construction, prior to init.
125 * @method _preInitEventCfg
126 * @param {Object} config The user configuration object
128 _preInitEventCfg : function(config) {
134 this.after(config.after);
139 userTargets = (config && BUBBLETARGETS in config);
141 if (userTargets || _BUBBLETARGETS in this) {
142 target = userTargets ? (config && config.bubbleTargets) : this._bubbleTargets;
144 if (L.isArray(target)) {
145 for (i = 0, l = target.length; i < l; i++) {
146 this.addTarget(target[i]);
149 this.addTarget(target);
156 * Destroy lifecycle method. Fires the destroy
157 * event, prior to invoking destructors for the
161 * Subscribers to the destroy
162 * event can invoke preventDefault on the event object, to prevent destruction
166 * @return {Base} A reference to this object
169 destroy: function() {
173 * Lifecycle event for the destroy phase,
174 * fired prior to destruction. Invoking the preventDefault
175 * method on the event object provided to subscribers will
176 * prevent destruction from proceeding.
179 * Subscribers to the "after" moment of this event, will be notified
180 * after destruction is complete (and as a result cannot prevent
184 * @preventable _defDestroyFn
185 * @param {EventFacade} e Event object
187 this.publish(DESTROY, {
189 defaultTargetOnly:true,
190 defaultFn: this._defDestroyFn
199 * Default init event handler
202 * @param {EventFacade} e Event object, with a cfg property which
203 * refers to the configuration object passed to the constructor.
206 _defInitFn : function(e) {
207 this._baseInit(e.cfg);
211 * Default destroy event handler
213 * @method _defDestroyFn
214 * @param {EventFacade} e Event object
217 _defDestroyFn : function(e) {
218 this._baseDestroy(e.cfg);
222 Y.mix(BaseObservable, AttributeObservable, false, null, 1);
224 Y.BaseObservable = BaseObservable;
227 }, '3.13.0', {"requires": ["attribute-observable"]});