The type of the events that this EventDispatcher is expected to dispatch. To
allow for multiple event classes, use a union type here. If you don't specify an event type,
any event that extends
AbstractEvent can be dispatched, but you won't get automatic typing
for event handlers.
Creates an EventDispatcher instance.
If set, registers the given EventDispatcher instance as parent. This child-parent relationship is used in the event chain during the capture phase of events and the bubbling phase of bubbling events. For more information on event bubbling and capturing, see dispatchEvent
If set, will set the target attribute of all events dispatched by this EventDispatcher to the given object. If not set, will use this instance as a target for dispatched events.
An object containing all event listeners by event type. Each value on this object is an Array of EventListenerData objects for each event listener added with that type.
The parent EventDispatcher instance. If this instance has no parent, this value will be
set to null
. The parent is used in the bubbling and capturing phases of events.
The value that will be set as target on events that are dispatched by this EventDispatcher instance. Set to the value passed to the constructor
Adds a new event listener. The given handler function will be called in the following cases:
eventType
is dispatched
on this EventDispatcher instance.eventType
is dispatched
on a child EventDispatcher, and the useCapture
parameter is set to true
true
and a type that
is equal to the given eventType
is dispatched on a child EventDispatcher, and the
useCapture
parameter is set to false
The eventType to listen for
The handler function that will be called when a matching event is dispatched. This function will retrieve the dispatched event as a parameter
Indicates if this handler should be called during the capturing phase
of an event chain. If and only if this is set to false
will this handler be called
during the bubbling phase of an event chain.
A number that indicates the priority of this event listener relative to other event listeners of the same type on this EventDispatcher instance. A higher number indicates that this listener will be called earlier.
An object describing the listener that has a dispose() method to remove the listener.
Dispatches the given event. The dispatch consists of three phases:
useCapture
argument
set to true
and the eventType
set to the same type as
the given event.
If this EventDispatcher has no parent, this phase will be skipped.true
. If so, we will again walk through
all ancestors of this EventDispatcher, but in the reverse order: the direct parent
of this instance first and the top-most parent last. On every ancestor, we will call
all event handlers that are added with the useCapture
argument set to false
and the
eventType
set to the same type as the given event.If any of the event handlers call stopPropagation(), we will skip all event handlers that occur on a target later in the event chain. If an event handler calls stopImmediatePropagation(), we will also skip any event handlers on the same target in the event chain.
The event to dispatch
If one of the handlers that have been called during this dispatch
called event.preventDefault(), this method will return false
.
If no handlers have been called or none of the handlers have called
event.preventDefault(), this method will return true
.
Please note: preventDefault() can only be called on events that have their cancelable property set to
true
Cleans up this EventListener instance. No event handlers on this EventDispatcher will be called and future calls to dispatchEvent() will be ignored.
Checks if an event listener matching the given parameters exists on this EventDispatcher instance.
Will only look for event listeners with this eventType
If set, will only match event listeners that have the same handler function
If set, will only match event listeners that have the same useCapture
argument.
Please note: if no
useCapture
argument was provided to addEventListener, it is set tofalse
by default
True if one or more event listeners exist
After dispose has been called, this method returns true. Use this method to determine whether dispose() should be run again.
Method that is used to sort arrays of event listeners based on their priority property. Higher priority will be sorted before lower priority values.
The first event listener to compare
The other event listener to compare to
A number that indicates the sorting according to the JS sort() method.
Removes all event listeners that have a type of the given eventType
from this EventDispatcher instance, regardless of their handler or
useCapture property.
Please note: if you remove an event listener during the dispatch of an event it will not be called anymore, even if it was supposed to be called in the same event chain
The type of event to remove. If not provided, all event listeners will be removed regardless of their type.
Removes all event listeners that match the given parameters from this EventDispatcher instance.
Please note: if you remove an event listener during the dispatch of an event it will not be called anymore, even if it was supposed to be called in the same event chain
Only event listeners of that have this eventType
are removed
Only event listeners that have this handler function will be removed
Only event listeners that have been added with the same useCapture
parameter will be removed. Please note: if no useCapture argument is provided, only
event listeners that have useCapture set to false will be removed.
Checks if an event listener with a type of the given eventType
exists
on this EventDispatcher or any ancestor EventDispatcher instance.
The event type to check for
true
if a matching listener is found
Generated using TypeDoc
Base class that adds the ability to dispatch events and attach handlers that should be called when such events are triggered.
This EventDispatcher also supports event capturing and bubbling phases, heavily inspired by existing event dispatching systems like the functionality described in the DOM Event W3 spec