base.js revision cc05f14a87293a437bcbe67deac2da7edad2a120
/**
* Base class support for objects requiring managed attributes and acting as event targets.
*
* The base module also provides an augmentable PluginHost interface.
*
* @module base
*/
/**
* An augmentable class, which when added to a "Base" based class, allows
* the class to support Plugins, providing plug and unplug methods.
*
* The PlugHost's _initPlugins and _destroyPlugins should be invoked by the
* host class at the appropriate point in the classes lifecyle. This is done
* by default for Base class.
*
* @class PluginHost
*/
var L = Y.Lang;
function PluginHost(config) {
this._plugins = {};
}
PluginHost.prototype = {
/**
* Register and instantiate a plugin with the Widget.
*
* @method plug
* @chainable
* @param p {Function | Object |Array} Accepts the plugin class, or an
* object literal with a "fn" property specifying the Plugin class and
* a "cfg" property specifying the configuration for the Plugin.
* <p>
* Additionally an Array can also be passed in, with the above function or
* Object literal values, allowing for multiple plugin registration in a single call.
* </p>
* @param config Optional. If the first argument is the plugin class, the second argument
* can be the configuration for the plugin.
*/
if (p) {
if (L.isFunction(p)) {
} else if (L.isArray(p)) {
this.plug(p[i]);
}
} else {
}
}
return this;
},
/**
* Unregister and destroy a plugin already instantiated on the host.
*
* @method unplug
* @param {String | Function} plugin The namespace of the Plugin, or the Plugin class with the static NS namespace property defined. If not provided,
* all registered plugins are unplugged.
* @chainable
*/
if (plugin) {
} else {
var ns;
}
}
}
return this;
},
/**
* Determines if a plugin has been registered and instantiated
* for this widget.
*
* @method hasPlugin
* @public
* @return {Boolean} returns true, if the plugin has been applied
* to this widget.
*/
},
/**
* Initializes static plugins registered on the host (using the
* Base.plug static method) and any plugins passed in for the
* instance through the "plugins" configuration property.
*
* @method _initPlugins
* @param {Config} the user configuration object for the host.
* @private
*/
_initPlugins: function(config) {
// Class Configuration
var classes = this._getClasses(),
plug = [],
unplug = {},
//TODO: Room for optimization. Can we apply statically/unplug in same pass?
constructor = classes[i];
if (classUnplug) {
// subclasses over-write
}
if (classPlug) {
// subclasses over-write
}
}
for (pluginClassName in plug) {
if (!unplug[pluginClassName]) {
}
}
}
// User Configuration
}
},
/**
* Private method used to unplug and destroy all plugins on the host
* @method _destroyPlugins
* @private
*/
_destroyPlugins: function() {
this._unplug();
},
/**
* Private method used to instantiate and attach plugins to the host
* @method _plug
* @param {Function} PluginClass The plugin class to instantiate
* @param {Object} config The configuration object for the plugin
* @private
*/
// Update config
} else {
// Create new instance
}
}
},
/**
* Private method used to unregister and destroy a plugin already instantiated with the host.
*
* @method _unplug
* @private
* @param {String | Function} plugin The namespace for the Plugin, or a Plugin class, with the static NS property defined.
*/
if (L.isFunction(plugin)) {
ns = null;
}
}
if (ns) {
if (this[ns]) {
delete this[ns];
}
}
}
}
};
/**
* Registers plugins to be instantiated at the class level (plugins
* which should be plugged into every instance of the class by default).
*
* @method PluginHost.plug
* @static
*
* @param {Function} hostClass The host class on which to register the plugins
* @param {Function | Array} plugin Either the plugin class, or an array of plugin classes/plugin fn, cfg object literals
* @param {Object} config If plugin is the plugin class, the configuration for the plugin can be passed
* as the configuration for the plugin
*/
// Cannot plug into Base, since Plugins derive from Base [ will cause infinite recurrsion ]
var p, i, l, name;
if (config) {
}
}
p = plugin[i];
}
}
};
/**
* Unregisters plugins which have been registered by the host class, or any
* other class in the hierarchy.
*
* @method PluginHost.unplug
* @static
*
* @param {Function} hostClass The host class from which to unregister the plugins
* @param {Function | Array} plugin The plugin class, or an array of plugin classes
*/
var p, i, l, name;
}
p = plugin[i];
} else {
}
}
}
};
/**
* Base class support for objects requiring managed attributes and acting as event targets.
*
* The base module also provides an augmentable PluginHost interface.
*
* @module base
*/
/**
* The base-base sub-module provides the Base class, without Base.build functionality
*
* @module base
* @sub-module base-base
*/
var O = Y.Object,
DOT = ".",
DESTROY = "destroy",
INIT = "init",
INITIALIZED = "initialized",
DESTROYED = "destroyed",
INITIALIZER = "initializer",
DEEP = "deep",
SHALLOW = "shallow",
VALUE = "value",
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() {
this._silentInit = this._silentInit || false;
if (this._lazyAddAttrs !== false) { this._lazyAddAttrs = true; }
}
/**
* The list of properties which can be configured for
* each attribute (e.g. setter, getter, writeOnce etc.)
*
* @property Base._ATTR_CFG
* @type Array
* @static
* @private
*/
/**
* <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
*/
if (!this._silentInit) {
queuable:false,
defaultFn:this._defInitFn
});
}
if (config) {
}
}
}
if (!this._silentInit) {
} else {
}
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._initPlugins(e.cfg);
if (!this._silentInit) {
this._set(INITIALIZED, true);
} else {
}
},
/**
* Default destroy event handler
*
* @method _defDestroyFn
* @param {Event.Facade} e Event object
* @protected
*/
_defDestroyFn : function(e) {
this._destroyHierarchy();
this._destroyPlugins();
},
/**
* 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
*/
if (attrs) {
}
}
}
return cfgs;
},
/**
* @method _initHierarchyData
* @private
*/
_initHierarchyData : function() {
var c = this.constructor,
classes = [],
attrs = [];
while (c) {
// Add to classes
// Add to attributes
if (c.ATTRS) {
}
}
},
/**
* @method _aggregateAttrs
* @private
* @param {Object} allAttrs
*/
_aggregateAttrs : function(allAttrs) {
var attr,
cfg,
val,
path,
i,
aggAttrs = {};
if (allAttrs) {
// Protect config passed in
if (val) {
if ( (clone === undefined && (OBJECT_CONSTRUCTOR === val.constructor || L.isArray(val))) || clone === DEEP || clone === true) {
}
// else if (clone === false), don't clone the static default value.
// It's intended to be used by reference.
}
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(userVals) {
var lazy = this._lazyAddAttrs,
ci,
ei,
el,
classes = this._getClasses(),
attrCfgs = 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
/**
* The base-build sub-module provides the Base.build functionality
*
* @module base
* @sub-module base-build
*/
L = Y.Lang;
/**
* The build configuration for the Base class.
* Defines the static fields which need to be aggregated,
* when this class is used as the main class passed to
* the <a href="#method_build">Base.build</a> method.
*
* @property _buildCfg
* @type Object
* @static
* @final
* @private
*/
};
/**
* <p>
* Builds a constructor function (class) from the
* main function, and array of extension functions (classes)
* provided.
* </p>
* <p>
* The cfg object literal supports the following properties
* </p>
* <dl>
* <dt>dynamic <boolean></dt>
* <dd>
* <p>If true (default), a completely new class
* is created which extends the main class, and acts as the
* host on which the extension classes are augmented.</p>
* <p>If false, the extensions classes are augmented directly to
* the main class, modifying the main classes prototype.</p>
* </dd>
* <dt>aggregates <String[]></dt>
* <dd>An array of static property names, which will get aggregated
* on to the built class, in addition to the default properties build
* will always aggregate as defined by the main class' _buildCfg
* property.
* </dd>
* </dl>
*
* @method build
* @static
* @param {Function} main The name of the new class
* @param {Function} main The main class on which to base the built class
* @param {Function[]} extensions The set of extension classes which will be
* augmented/aggregated to the built class.
* @param {Object} cfg Optional. Configuration for the class.
* @return {Function} A custom class, created from the provided main and extension classes
*/
// Shallow isolate aggregates
if (dynamic) {
if (aggregates) {
val = aggregates[i];
}
}
}
}
extClass = extensions[i];
if (aggregates) {
}
// Old augment
}
if (dynamic) {
}
return builtClass;
};
function BuiltClass() {
l = f.length,
i;
for (i = 0; i < l; i++) {
}
return this;
}
return BuiltClass;
},
if (this.constructor._yuibuild) {
l = f.length,
i;
for (i = 0; i < l; i++) {
if (f[i] === extClass) {
return true;
}
}
}
return false;
},
builtClass._yuibuild = {
id: null,
exts : [],
};
return builtClass;
},
var aggr = [],
c = main,
while (c && c.prototype) {
if (classAggr) {
}
}
if (cfgAggr) {
}
return aggr;
}
});