Base.js revision 698543a874206e0c411b376e0c2892233a6a8fef
/**
* Base class support for objects requiring managed attributes and acting as event targets.
*
* The base module also provides an augmentable PluginHost interface.
*
* @module base
*/
var O = Y.Object,
DOT = ".",
DESTROY = "destroy",
INIT = "init",
INITIALIZED = "initialized",
DESTROYED = "destroyed",
INITIALIZER = "initializer",
DESTRUCTOR = "destructor";
/**
* <p>
* Provides a base class for managed attribute based
* objects, which handles the chaining of initializer and destructor methods
* across the hierarchy during init and destroy lifecycle methods and
* handles automatic configuration of registered Attributes, through
* the static <a href="#property_ATTRS">ATTRS</a> property.
* </p>
*
* <p>The Base class also handles prefixing of event types with the static <a href="#property_NAME">NAME</a>
* property for all events fired from instances of classes derived from Base.</p>
*
* @constructor
* @class Base
* @uses Attribute, Plugin.Host
*
*/
function Base() {
}
/**
* <p>
* Name string to be used to identify instances of
* this class, for example in prefixing events.
* </p>
* <p>
* Classes extending Base, should define their own
* static NAME property.
* </p>
* @property NAME
* @type String
* @static
*/
/**
* Object literal defining the set of attributes which
* will be available for instances of this class, and
* how they are configured. See Attributes addAtt method
* for a description of configuration options available
* for each attribute.
*
* @property ATTRS
* @type Object
* @static
*/
/**
* Flag indicating whether or not this object
* has been through the init lifecycle phase.
*
* @attribute initialized
* @readOnly
* @default false
* @type boolean
*/
initialized: {
readOnly:true,
value:false
},
/**
* Flag indicating whether or not this object
* has been through the destroy lifecycle phase.
*
* @attribute destroyed
* @readOnly
* @default false
* @type boolean
*/
destroyed: {
readOnly:true,
value:false
}
};
/**
* Init lifecycle method, invoked during construction.
* Fires the init event prior to invoking initializers on
* the class hierarchy.
*
* @method init
* @final
* @chainable
* @return {Base} A reference to this object
*/
/**
* The name string to be used to identify
* this instance of object.
* @property name
* @type String
*/
/**
* <p>
* Lifecycle event for the init phase, fired prior to initialization.
* Invoking the preventDefault method on the event object provided
* to subscribers will prevent initialization from occuring.
* </p>
* <p>
* Subscribers to the "after" momemt of this event, will be notified
* after initialization of the object is complete (and therefore
* cannot prevent initialization).
* </p>
*
* @event init
* @preventable _defInitFn
* @param {Event.Facade} e Event object
*/
queuable:false,
defaultFn:this._defInitFn
});
// TODO: Look at why this needs to be done after publish.
return this;
},
/**
* <p>
* Destroy lifecycle method. Fires the destroy
* event, prior to invoking destructors for the
* class hierarchy.
* </p>
* <p>
* Subscribers to the destroy
* event can invoke preventDefault on the event object, to prevent destruction
* from proceeding.
* </p>
* @method destroy
* @return {Base} A reference to this object
* @final
* @chainable
*/
destroy: function() {
/**
* <p>
* Lifecycle event for the destroy phase,
* fired prior to destruction. Invoking the preventDefault
* method on the event object provided to subscribers will
* prevent destruction from proceeding.
* </p>
* <p>
* Subscribers to the "after" moment of this event, will be notified
* after destruction is complete (and as a result cannot prevent
* destruction).
* </p>
* @event destroy
* @preventable _defDestroyFn
* @param {Event.Facade} e Event object
*/
queuable:false,
defaultFn: this._defDestroyFn
});
return this;
},
/**
* Default init event handler
*
* @method _defInitFn
* @param {Event.Facade} e Event object
* @protected
*/
_defInitFn : function(e) {
this._initHierarchy(e.cfg);
this._set(INITIALIZED, true);
},
/**
* Default destroy event handler
*
* @method _defDestroyFn
* @param {Event.Facade} e Event object
* @protected
*/
_defDestroyFn : function(e) {
this._destroyHierarchy();
},
/**
* Returns the class hierarchy for this object, with Base being the last class in the array.
*
* @method _getClasses
* @protected
* @return {Function[]} An Array of classes (constructor functions), making up the class hierarchy for this object
*/
_getClasses : function() {
if (!this._classes) {
this._initHierarchyData();
}
return this._classes;
},
/**
* Returns an aggregated set of attribute configurations, by traversing the class hierarchy.
*
* @method _getAttrCfgs
* @protected
* @return {Object} The hash of attribute configurations, aggregated across classes in the hierarchy
*/
_getAttrCfgs : function() {
if (!this._attrs) {
this._initHierarchyData();
}
return this._attrs;
},
/**
* @method _filterAttrCfs
* @private
* @param {Function} clazz
* @param {Objects} allCfgs
*/
var cfgs = {};
if (allCfgs[k]) {
delete allCfgs[k];
}
});
}
return cfgs;
},
/**
* @method _initHierarchyData
* @private
*/
_initHierarchyData : function() {
var c = this.constructor,
classes = [],
attrs = [];
while (c && c.prototype) {
// Add to classes
// Add to attributes
if (c.ATTRS) {
}
}
},
/**
* @method _aggregateAttrs
* @private
* @param {Object} allAttrs
*/
_aggregateAttrs : function(allAttrs) {
aggAttrs = {};
if (allAttrs) {
// Protect
}
path = null;
}
} else if (!path){
} else {
}
}
}
}
}
}
return aggAttrs;
},
/**
* Initializes the class hierarchy rooted at this base class,
* which includes initializing attributes for each class defined
* in the class's static <a href="#property_ATTRS">ATTRS</a> property and invoking the initializer
* method on the prototype of each class in the hierarchy.
*
* @method _initHierarchy
* @private
*/
_initHierarchy : function(userConf) {
var constr,
ci,
ei,
el,
classes = this._getClasses(),
mergedCfgs = this._getAttrCfgs();
}
}
}
}
},
/**
* Destroys the class hierarchy rooted at this base class by invoking
* the descructor method on the prototype of each class in the hierarchy.
*
* @method _destroyHierarchy
* @private
*/
_destroyHierarchy : function() {
var constr,
classes = this._getClasses();
}
}
},
/**
* Default toString implementation. Provides the constructor NAME
* and the instance ID.
*
* @method toString
* @return {String} String representation for this object
*/
toString: function() {
}
};
// Straightup augment, no wrapper functions
// Fix constructor