CustomEvent Class
The CustomEvent class lets you define events for your application that can be subscribed to by one or more independent component.
Constructor
Item Index
Methods
- _broadcast
- _delete
- _notify
- _on
- _procSubs
- after
- applyConfig
- detach
- detachAll
- fire
- fireSimple
- getSubs
- halt
- hasSubs
- log
- monitor
- on
- preventDefault
- stopImmediatePropagation
- stopPropagation
- subscribe deprecated
- unsubscribe deprecated
- unsubscribeAll deprecated
Properties
- _afters
- _subscribers
- afters
- async
- broadcast
- bubbles
- context
- defaultFn
- emitFacade
- fired
- firedWith
- fireOnce
- host
- keepDeprecatedSubs static deprecated
- monitored
- preventable
- prevented
- preventedFn
- queuable
- signature
- silent
- stopped
- stoppedFn
- subscribers deprecated
- type
Methods
_broadcast
-
args
Notifies the YUI instance if the event is configured with broadcast = 1, and both the YUI instance and Y.Global if configured with broadcast = 2.
Parameters:
-
args
ArrayArguments sent to fire()
_delete
-
s
-
subs
-
index
Deletes the subscriber from the internal store of on() and after() subscribers.
_notify
-
s
-
args
Notify a single subscriber
Parameters:
-
s
Subscriberthe subscriber.
-
args
Arraythe arguments array to apply to the listener.
_on
-
fn
-
[context]
-
[args]
-
[when]
Create the Subscription for subscribing function, context, and bound arguments. If this is a fireOnce event, the subscriber is immediately notified.
Parameters:
Returns:
_procSubs
-
subs
-
args
-
ef
Notifies a list of subscribers.
Returns:
after
-
fn
-
context
-
arg
Listen for this event after the normal subscribers have been notified and the default behavior has been applied. If a normal subscriber prevents the default behavior, it also prevents after listeners from firing.
Parameters:
Returns:
applyConfig
-
o
-
force
Apply configuration properties. Only applies the CONFIG whitelist
detach
-
fn
-
context
Detach listeners.
Parameters:
Returns:
detachAll
()
Int
Removes all listeners
Returns:
fire
-
arguments
Notifies the subscribers. The callback functions will be executed from the context specified when the event was created, and with the following parameters:
- The type of event
- All of the arguments fire() was executed with as an array
- The custom object (if any) that was passed into the subscribe() method
Parameters:
-
arguments
Object*an arbitrary set of parameters to pass to the handler.
Returns:
fireSimple
-
args
Set up for notifying subscribers of non-emitFacade events.
Parameters:
-
args
ArrayArguments passed to fire()
Returns:
getSubs
()
Array
Get all of the subscribers to this event and any sibling event
Returns:
halt
-
immediate
Stops the event propagation and prevents the default event behavior.
Parameters:
-
immediate
Booleanif true additional listeners on the current target will not be executed
hasSubs
()
Returns the number of subscribers for this event as the sum of the on() subscribers and after() subscribers.
Returns:
log
-
msg
-
cat
Logger abstraction to centralize the application of the silent flag
monitor
-
what
Monitor the event state for the subscribed event. The first parameter is what should be monitored, the rest are the normal parameters when subscribing to an event.
Parameters:
-
what
Stringwhat to monitor ('detach', 'attach', 'publish').
Returns:
on
-
fn
-
context
-
arg
Listen for this event
Parameters:
Returns:
preventDefault
()
Prevents the execution of this event's defaultFn
stopImmediatePropagation
()
Stops propagation to bubble targets, and prevents any remaining subscribers on the current target from executing.
stopPropagation
()
Stop propagation to bubble targets
subscribe
-
fn
Listen for this event
Parameters:
-
fn
FunctionThe function to execute.
Returns:
unsubscribe
-
fn
-
context
Detach listeners.
Parameters:
Returns:
unsubscribeAll
()
Int
deprecated
Removes all listeners
Returns:
Properties
_afters
Subscriber
private
'After' subscribers
_subscribers
Subscriber
private
The subscribers to this event
broadcast
Int
If 0, this event does not broadcast. If 1, the YUI instance is notified every time this event fires. If 2, the YUI instance and the YUI global (if event is enabled on the global) are notified every time this event fires.
bubbles
Boolean
Specifies whether or not a subscriber can stop the event propagation via stopPropagation(), stopImmediatePropagation(), or halt()
Events can only bubble if emitFacade is true.
Default: true
defaultFn
Function
The default function to execute after event listeners have fire, but only if the default action was not prevented.
emitFacade
Boolean
If set to true, the custom event will deliver an EventFacade object that is similar to a DOM event object.
Default: false
fireOnce
Boolean
This event should only fire one time if true, and if it has fired, any new subscribers should be notified immediately.
Default: false;
keepDeprecatedSubs
Boolean
deprecated
static
Static flag to enable population of the subscribers
and afters
properties held on a CustomEvent
instance.
These properties were changed to private properties (_subscribers
and _afters
), and
converted from objects to arrays for performance reasons.
Setting this property to true will populate the deprecated subscribers
and afters
properties for people who may be using them (which is expected to be rare). There will
be a performance hit, compared to the new array based implementation.
If you are using these deprecated properties for a use case which the public API does not support, please file an enhancement request, and we can provide an alternate public implementation which doesn't have the performance cost required to maintiain the properties as objects.
Default: false
preventable
Boolean
Specifies whether or not this event's default function can be cancelled by a subscriber by executing preventDefault() on the event facade
Default: true
prevented
Int
Flag for preventDefault that is modified during fire(). if it is not 0, the default behavior for this event
queuable
Boolean
Specifies whether this event should be queued when the host is actively processing an event. This will effect exectution order of the callbacks for the various events.
Default: false
signature
Int
Supports multiple options for listener signatures in order to port YUI 2 apps.
Default: 9
silent
Boolean
By default all custom events are logged in the debug build, set silent to true to disable debug outpu for this event.
stopped
Int
Flag for stopPropagation that is modified during fire() 1 means to stop propagation to bubble targets. 2 means to also stop additional subscribers on this target.
stoppedFn
Function
The function to execute if a subscriber calls stopPropagation or stopImmediatePropagation