- Known Subclasses:
-
DataSource.Local
Widget
Plugin.Base
ImgLoadImgObj
LiveSearch
CharCounter
TreeData
DD.Drop
NestedList
ImgLoadGroup
Plugin.NodeFX
OverlayManager
Paginator
DD.Delegate
Plugin.DDConstrained
DD.Drag
ProgressBar
PortalLayout
DD.Scroll
Anim
Plugin.DDProxy
DD.DDM
Resize
Sortable
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.
Constructor
Base
(
config
)
- 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.
Properties
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.
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";).
name
- String
The string used to identify the class of this object.
Deprecated: Use this.constructor.NAME
Configuration Attributes
Flag indicating whether or not this object
has been through the destroy lifecycle phase.
Default Value: false
Flag indicating whether or not this object
has been through the init lifecycle phase.
Default Value: false
Methods
protected
void
_defDestroyFn
(
e
)
Default destroy event handler
- Parameters:
-
e
<EventFacade>
Event object
protected
void
_defInitFn
(
e
)
Default init event handler
- Parameters:
-
e
<EventFacade>
Event object, with a cfg property which
refers to the configuration object passed to the constructor.
protected
Object
_getAttrCfgs
(
)
Returns an aggregated set of attribute configurations, by traversing the class hierarchy.
- Returns:
Object
- The hash of attribute configurations, aggregated across classes in the hierarchy
This value is cached the first time the method, or _getClasses, is invoked. Subsequent invocations return
the cached value.
protected
Function[]
_getClasses
(
)
Returns the class hierarchy for this object, with Base being the last class in the array.
- Returns:
Function[]
- An array of classes (constructor functions), making up the class hierarchy for this object.
This value is cached the first time the method, or _getAttrCfgs, is invoked. Subsequent invocations return the
cached value.
void
_preInitEventCfg
(
config
)
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
static
Function
Base.build
(
name
,
main
,
extensions
,
cfg
)
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.
- Parameters:
-
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).
- Returns:
Function
- A custom class, created from the provided main and extension classes
static
Function
Base.create
(
name
,
main
,
extensions
)
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.
- Returns:
Function
- The newly created class.
static
Function
Base.mix
(
main
,
extensions
)
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.
- Returns:
Function
- The modified main class, with extensions mixed in.
static
void
Base.plug
(
)
Alias for
Plugin.Host.plug. See aliased
method for argument and return value details.
static
void
Base.unplug
(
)
Alias for
Plugin.Host.unplug. See the
aliased method for argument and return value details.
final
Base
destroy
(
)
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.
- Returns:
Base
- A reference to this object
Chainable: This method is chainable.
final
Base
init
(
config
)
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
- Returns:
Base
- A reference to this object
Chainable: This method is chainable.
String
toString
(
)
Default toString implementation. Provides the constructor NAME
and the instance ID.
- Returns:
String
- String representation for this object
Events
destroy
(
e
)
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).
- Parameters:
-
e<EventFacade>
Event object
Preventable:
This event is preventable by method e.preventDefault(). The default function executed by this event is _defDestroyFn.
destroyedChange
(
event
)
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.
- Parameters:
-
event<Event.Facade>
An Event Facade object with the following attribute specific properties added: - prevVal
- The value of the attribute, prior to it being set
- newVal
- The value the attribute is to be set to
- attrName
- The name of the attribute being set
- subAttrName
- If setting a property within the attribute's value, the name of the sub-attribute property being set
init
(
e
)
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).
- Parameters:
-
e<EventFacade>
Event object, with a cfg property which
refers to the configuration object passed to the constructor.
Preventable:
This event is preventable by method e.preventDefault(). The default function executed by this event is _defInitFn.
initializedChange
(
event
)
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.
- Parameters:
-
event<Event.Facade>
An Event Facade object with the following attribute specific properties added: - prevVal
- The value of the attribute, prior to it being set
- newVal
- The value the attribute is to be set to
- attrName
- The name of the attribute being set
- subAttrName
- If setting a property within the attribute's value, the name of the sub-attribute property being set