Class Base
Uses: Attribute Plugin.HostClass defined in:
base/js/Base.js:33
A base class which objects requiring attributes and custom event support can extend. Base also handles the chaining of initializer and destructor methods across the hierarchy as part of object construction and destruction. Additionally, attributes configured through the static ATTRS property for each class in the hierarchy will be initialized by Base.
The static NAME property of each class extending from Base will be used as the identifier for the class, and is used by Base to prefix all events fired by instances of that class.
Base
( config
)
base/js/Base.js:33
Parameters:
-
config
<Object> Object with configuration property name/value pairs. The object can be used to provide default values for the objects published attributes. The config object can also contain the following non-attribute properties, providing a convenient way to configure events listeners and plugins for the instance, as part of the constructor call:- on
- An event name to listener function map, to register event listeners for the "on" moment of the event. A constructor convenience property for the on method.
- after
- An event name to listener function map, to register event listeners for the "after" moment of the event. A constructor convenience property for the after method.
- bubbleTargets
- An object, or array of objects, to register as bubble targets for bubbled events fired by this instance. A constructor convenience property for the addTarget method.
- plugins
- A plugin, or array of plugins to be plugged into the instance (see PluginHost's plug method for signature details). A constructor convenience property for the plug method.
_aggregateAttrs
( allAttrs
) /* private method */
base/js/Base.js:427
A helper method, used by _initHierarchyData to aggregate attribute configuration across the instances class hierarchy.
The method will potect the attribute configuration value to protect the statically defined default value in ATTRS if required (if the value is an object literal, array or the attribute configuration has cloneDefaultValue set to shallow or deep).
Parameters:-
allAttrs
<Array> An array of ATTRS definitions across classes in the hierarchy (subclass first, Base last)
_defDestroyFn
( e
) /* protected method */
base/js/Base.js:320
Default destroy event handler
Parameters:-
e
<EventFacade> Event object
_defInitFn
( e
) /* protected method */
base/js/Base.js:303
Default init event handler
Parameters:-
e
<EventFacade> Event object, with a cfg property which refers to the configuration object passed to the constructor.
_destroyHierarchy
(
) /* private method */
base/js/Base.js:541
Destroys the class hierarchy for this instance by invoking the descructor method on the prototype of each class in the hierarchy.
_filterAttrCfs
( clazz, allCfgs
) /* private method */
base/js/Base.js:367
A helper method used when processing ATTRS across the class hierarchy during initialization. Returns a disposable object with the attributes defined for the provided class, extracted from the set of all attributes passed in .
Parameters:-
clazz
<Function> The class for which the desired attributes are required. -
allCfgs
<Object> The set of all attribute configurations for this instance. Attributes will be removed from this set, if they belong to the filtered class, so that by the time all classes are processed, allCfgs will be empty.
_getAttrCfgs
(
) /* protected method */
base/js/Base.js:351
Returns an aggregated set of attribute configurations, by traversing the class hierarchy.
_getClasses
(
) /* protected method */
base/js/Base.js:335
Returns the class hierarchy for this object, with Base being the last class in the array.
_initHierarchy
( userVals
) /* private method */
base/js/Base.js:500
Initializes the class hierarchy for the instance, which includes initializing attributes for each class defined in the class's static ATTRS property and invoking the initializer method on the prototype of each class in the hierarchy.
Parameters:-
userVals
<Object> Object with configuration property name/value pairs
_initHierarchyData
(
) /* private method */
base/js/Base.js:399
A helper method used by _getClasses and _getAttrCfgs, which determines both the array of classes and aggregate set of attribute configurations across the class hierarchy for the instance.
_preInitEventCfg
( config
) /* private method */
base/js/Base.js:222
Handles the special on, after and target properties which allow the user to easily configure on and after listeners as well as bubble targets during construction, prior to init.
Parameters:-
config
<Object> The user configuration object
Base.build
( name, main, extensions, cfg
)
base/js/BaseBuild.js:188
Builds a custom constructor function (class) from the main function, and array of extension functions (classes) provided. The NAME field for the constructor function is defined by the first argument passed in.
The cfg object supports the following properties
- dynamic <boolean>
- 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. If false, the extensions classes are augmented directly to the main class, modifying the main class' prototype.
- aggregates <String[]>
- 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' static _buildCfg property.
-
name
<Function> The name of the new class. Used to defined the NAME property for the new class. -
main
<Function> The main class on which to base the built class -
extensions
<Function[]> The set of extension classes which will be augmented/aggregated to the built class. -
cfg
<Object> Optional. Build configuration for the class (see description).
Base.create
( name, main, extensions, px, sx
)
base/js/BaseBuild.js:229
Creates a new class (constructor function) which extends the base class passed in as the second argument, and mixes in the array of extensions provided.
Prototype properties or methods can be added to the new class, using the px argument (similar to Y.extend). Static properties or methods can be added to the new class, using the sx argument (similar to Y.extend).
Parameters:-
name
<Function> The name of the newly created class. Used to defined the NAME property for the new class. -
main
<Function> The base class which the new class should extend. This class needs to be Base or a class derived from base (e.g. Widget). -
extensions
<Function[]> The list of extensions which will be mixed into the built class. -
px
<Object> The set of prototype properties/methods to add to the built class. -
sx
<Object> The set of static properties/methods to add to the built class.
Base.mix
( main, extensions
)
base/js/BaseBuild.js:250
Mixes in a list of extensions to an existing class.
Parameters:-
main
<Function> The existing class into which the extensions should be mixed. The class needs to be Base or class derived from base (e.g. Widget) -
extensions
<Function[]> The set of extension classes which will mixed into the existing main class.
Base.plug
(
)
base/js/BasePluginHost.js:15
Alias for Plugin.Host.plug. See aliased method for argument and return value details.
Base.unplug
(
)
base/js/BasePluginHost.js:24
Alias for Plugin.Host.unplug. See the aliased method for argument and return value details.
final
Base destroy
(
)
base/js/Base.js:256
Destroy lifecycle method. Fires the destroy event, prior to invoking destructors for the class hierarchy.
Subscribers to the destroy event can invoke preventDefault on the event object, to prevent destruction from proceeding.
final
Base init
( config
)
base/js/Base.js:175
Init lifecycle method, invoked during construction. Fires the init event prior to setting up attributes and invoking initializers for the class hierarchy.
Parameters:-
config
<Object> Object with configuration property name/value pairs
toString
(
)
base/js/Base.js:563
Default toString implementation. Provides the constructor NAME and the instance guid, if set.
Base._ATTR_CFG
<Array>base/js/Base.js:102
The list of properties which can be configured for each attribute (e.g. setter, getter, writeOnce, readOnly etc.)
Base._buildCfg
<Object> (final)base/js/BaseBuild.js:262
The build configuration for the Base class.
Defines the static fields which need to be aggregated when the Base class is used as the main class passed to the Base.build method.
Base.ATTRS
<Object>base/js/Base.js:129
The default set of attributes which will be available for instances of this class, and their configuration. In addition to the configuration properties listed by Attribute's addAttr method, the attribute can also be configured with a "cloneDefaultValue" property, which defines how the statically defined value field should be protected ("shallow", "deep" and false are supported values).
By default if the value is an object literal or an array it will be "shallow" cloned, to protect the default value.
Base.NAME
<String>base/js/Base.js:113
The string to be used to identify instances of this class, for example in prefixing events.
Classes extending Base, should define their own static NAME property, which should be camelCase by convention (e.g. MyClass.NAME = "myClass";).
initialized
<boolean>
base/js/Base.js:144
Flag indicating whether or not this object has been through the init lifecycle phase.
initializedChange(e)
Fires when the value for the configuration attribute initialized
is changed. You can listen for the event using the on
method if you wish to be notified before the attribute's value has changed, or using the after
method if you wish to be notified after the attribute's value has changed.
e
<EventFacade> An Event Facade object with the following attribute specific properties added:
prevVal
The value of the attribute, prior to it being setnewVal
The value the attribute is to be set toattrName
The name of the attribute being setsubAttrName
If setting a property within the attribute's value, the name of the sub-attribute property being set
destroyed
<boolean>
base/js/Base.js:158
Flag indicating whether or not this object has been through the destroy lifecycle phase.
destroyedChange(e)
Fires when the value for the configuration attribute destroyed
is changed. You can listen for the event using the on
method if you wish to be notified before the attribute's value has changed, or using the after
method if you wish to be notified after the attribute's value has changed.
e
<EventFacade> An Event Facade object with the following attribute specific properties added:
prevVal
The value of the attribute, prior to it being setnewVal
The value the attribute is to be set toattrName
The name of the attribute being setsubAttrName
If setting a property within the attribute's value, the name of the sub-attribute property being set
init
base/js/Base.js:191
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.
Subscribers to the "after" momemt of this event, will be notified after initialization of the object is complete (and therefore cannot prevent initialization).
Extra event object properties:-
e
<EventFacade> Event object, with a cfg property which refers to the configuration object passed to the constructor.
destroy
base/js/Base.js:275
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.
Subscribers to the "after" moment of this event, will be notified after destruction is complete (and as a result cannot prevent destruction).
Extra event object properties:-
e
<EventFacade> Event object