Provides an augmentable implementation of lifecycle and attribute events for
BaseCore
.
_defAttrChangeFn
e
eventFastPath
Default function for attribute change events.
e
EventFacade
The event object for attribute change events.
eventFastPath
Boolean
Whether or not we're using this as a fast path in the case of no listeners or not
_defInitFn
e
Default init event handler
e
EventFacade
Event object, with a cfg property which refers to the configuration object passed to the constructor.
_fireAttrChange
attrName
subAttrName
currVal
newVal
opts
[cfg]
Utility method to help setup the event payload and fire the attribute change event.
attrName
String
The name of the attribute
subAttrName
String
The full path of the property being changed, if this is a sub-attribute value being change. Otherwise null.
currVal
Any
The current value of the attribute
newVal
Any
The new value of the attribute
opts
Object
Any additional event data to mix into the attribute change event's event facade.
[cfg]
Object
optional
The attribute config stored in State, if already available.
_getFullType
type
Returns the fully qualified type, given a short type string. That is, returns "foo:bar" when given "bar" if "foo" is the configured prefix.
NOTE: This method, unlike _getType, does no checking of the value passed in, and is designed to be used with the low level _publish() method, for critical path implementations which need to fast-track publish for performance reasons.
type
String
The short type to prefix
The prefixed type, if a prefix is set, otherwise the type passed in
_getType
If the instance has a prefix attribute and the event type is not prefixed, the instance prefix is applied to the supplied type.
_hasPotentialSubscribers
fullType
fullType
String
The fully prefixed type name
Whether the event has potential subscribers or not
_initAttribute
Initializes Attribute
_monitor
what
eventType
o
This is the entry point for the event monitoring system. You can monitor 'attach', 'detach', 'fire', and 'publish'. When configured, these events generate an event. click -> click_attach, click_detach, click_publish -- these can be subscribed to like other events to monitor the event system. Inividual published events can have monitoring turned on or off (publish can't be turned off before it it published) by setting the events 'monitor' config.
what
String
'attach', 'detach', 'fire', or 'publish'
eventType
String | CustomEvent
The prefixed name of the event being monitored, or the CustomEvent object.
o
Object
Information about the event interaction, such as fire() args, subscription category, publish config
_parseType
Returns an array with the detach key (if provided), and the prefixed event name from _getType Y.on('detachcategory| menu:click', fn)
_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.
config
Object
The user configuration object
_publish
fullType
etOpts
ceOpts
The low level event publish implementation. It expects all the massaging to have been done
outside of this method. e.g. the type
to fullType
conversion. It's designed to be a fast
path publish, which can be used by critical code paths to improve performance.
The published event. If called without etOpts
or ceOpts
, this will
be the default CustomEvent
instance, and can be configured independently.
_set
name
val
opts
Allows setting of readOnly/writeOnce attributes. See set for argument details.
A reference to the host object.
_setAttrs
attrs
opts
Implementation behind the public setAttrs method, to set multiple attribute values.
A reference to the host object.
addTarget
o
Registers another EventTarget as a bubble target. Bubble order is determined by the order registered. Multiple targets can be specified.
Events can only bubble if emitFacade is true.
Included in the event-custom-complex submodule.
o
EventTarget
the target to add
after
type
fn
[context]
[arg*]
Subscribe to a custom event hosted by this object. The supplied callback will execute after any listeners add via the subscribe method, and after the default function, if configured for the event, has executed.
A subscription handle capable of detaching the subscription
before
Executes the callback before a DOM event, custom event or method. If the first argument is a function, it is assumed the target is a method. For DOM and custom events, this is an alias for Y.on.
For DOM and custom events: type, callback, context, 0-n arguments
For methods: callback, object (method host), methodName, context, 0-n arguments
detach handle
bubble
evt
Propagate an event. Requires the event-custom-complex module.
evt
CustomEvent
the custom event to propagate
the aggregated return value from Event.Custom.fire
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.
A reference to this object
detach
type
fn
context
Detach one or more listeners the from the specified event
type
String | Object
Either the handle to the subscriber or the type of event. If the type is not specified, it will attempt to remove the listener from all hosted events.
fn
Function
The subscribed function to unsubscribe, if not supplied, all subscribers will be removed.
context
Object
The custom object passed to subscribe. This is optional, but if supplied will be used to disambiguate multiple listeners that are the same (e.g., you subscribe many object using a function that lives on the prototype)
the host
detachAll
type
Removes all listeners from the specified event. If the event type is not specified, all listeners from all hosted custom events will be removed.
type
String
The type, or name of the event
fire
type
arguments
Fire a custom event by name. The callback functions will be executed from the context specified when the event was created, and with the following parameters.
The first argument is the event type, and any additional arguments are passed to the listeners as parameters. If the first of these is an object literal, and the event is configured to emit an event facade, that object is mixed into the event facade and the facade is provided in place of the original object.
If the custom event object hasn't been created, then the event hasn't been published and it has no subscribers. For performance sake, we immediate exit in this case. This means the event won't bubble, so if the intention is that a bubble target be notified, the event must be published on this object first.
type
String | Object
The type of the event, or an object that contains a 'type' property.
arguments
Object*
an arbitrary set of parameters to pass to the handler. If the first of these is an object literal and the event is configured to emit an event facade, the event facade will replace that parameter after the properties the object literal contains are copied to the event facade.
True if the whole lifecycle of the event went through, false if at any point the event propagation was halted.
getEvent
type
prefixed
Returns the custom event of the provided type has been created, a falsy value otherwise
the custom event or null
getTargets
Returns an array of bubble targets for this object.
EventTarget[]
init
config
Init lifecycle method, invoked during construction. Fires the init event prior to setting up attributes and invoking initializers for the class hierarchy.
config
Object
Object with configuration property name/value pairs
A reference to this object
on
type
fn
[context]
[arg*]
Subscribe a callback function to a custom event fired by this object or from an object that bubbles its events to this object.
Callback functions for events published with emitFacade = true
will
receive an EventFacade
as the first argument (typically named "e").
These callbacks can then call e.preventDefault()
to disable the
behavior published to that event's defaultFn
. See the EventFacade
API for all available properties and methods. Subscribers to
non-emitFacade
events will receive the arguments passed to fire()
after the event name.
To subscribe to multiple events at once, pass an object as the first argument, where the key:value pairs correspond to the eventName:callback, or pass an array of event names as the first argument to subscribe to all listed events with the same callback.
Returning false
from a callback is supported as an alternative to
calling e.preventDefault(); e.stopPropagation();
. However, it is
recommended to use the event methods whenever possible.
A subscription handle capable of detaching that subscription
once
type
fn
[context]
[arg*]
Listen to a custom event hosted by this object one time.
This is the equivalent to on
except the
listener is immediatelly detached when it is executed.
A subscription handle capable of detaching the subscription
onceAfter
type
fn
[context]
[arg*]
Listen to a custom event hosted by this object one time.
This is the equivalent to after
except the
listener is immediatelly detached when it is executed.
A subscription handle capable of detaching that subscription
parseType
type
[pre]
Takes the type parameter passed to 'on' and parses out the various pieces that could be included in the type. If the event type is passed without a prefix, it will be expanded to include the prefix one is supplied or the event target is configured with a default prefix.
an array containing:
publish
type
opts
Creates a new custom event of the specified type. If a custom event by that name already exists, it will not be re-created. In either case the custom event is returned.
type
String
the type, or name of the event
opts
Object
optional config params. Valid properties are:
the custom event
set
name
value
opts
Sets the value of an attribute.
name
String
The name of the attribute. If the
current value of the attribute is an Object, dot notation can be used
to set the value of a property within the object (e.g. set("x.y.z", 5)
).
value
Any
The value to set the attribute to.
opts
Object
(Optional) Optional event data to be mixed into the event facade passed to subscribers of the attribute's change event. This can be used as a flexible way to identify the source of a call to set, allowing the developer to distinguish between set called internally by the host, vs. set called externally by the application developer.
A reference to the host object.
setAttrs
attrs
opts
Sets multiple attribute values.
A reference to the host object.
subscribe
subscribe to an event
unsubscribe
detach a listener
unsubscribeAll
type
Removes all listeners from the specified event. If the event type is not specified, all listeners from all hosted custom events will be removed.
type
String
The type, or name of the event
destroy
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).
e
EventFacade
Event object
init
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).
e
EventFacade
Event object, with a cfg property which refers to the configuration object passed to the constructor.