ArgumentPassingMode: ExcludeEvent
ArgumentPassingMode: IncludeEvent
ArgumentPassingMode: ExcludeEvent
Add the callback to the dispatcher to listen to event.
The listener is added to the end of the listener list.
Return a handle object which represents the listener. The handle can be used to remove this listener or insert other listener before this listener.
If appendListener
is called in another listener during a dispatching, the new listener is guaranteed not triggered during the same dispatching.
If the same callback is added twice, it results duplicated listeners.
The time complexity is O(1).
Dispatch an event.
The listeners are called with arguments arg1
, arg2
, etc.
Note the arguments are passed in an array, similar to Function.prototype.apply.
Dispatch an event.
The listeners are called with arguments arg1
, arg2
, etc.
Apply func
to all listeners of event
. func
must return a boolean value, and if the return value is false, forEachIf stops the looping immediately.
Return true
if all listeners are invoked, or event
is not found, false
if func
returns false
.
Return true if the dispatcher contains any callback.
Return true if the dispatcher contains callback.
callback can be a callback function, or a handle object.
Insert the callback to the dispatcher to listen to event before the listener handle before. If before is not found, callback is added at the end of the listener list.
before can be a callback function, or a handle object.
Return a handle object which represents the listener. The handle can be used to remove this listener or insert other listener before this listener.
If insertListener
is called in another listener during a dispatching, the new listener is guaranteed not triggered during the same dispatching.
The time complexity is O(1).
Add the callback to the dispatcher to listen to event.
The listener is added to the beginning of the listener list.
Return a handle object which represents the listener. The handle can be used to remove this listener or insert other listener before this listener.
If prependListener
is called in another listener during a dispatching, the new listener is guaranteed not triggered during the same dispatching.
The time complexity is O(1).
Remove the listener callback which listens to event from the dispatcher.
callback can be a callback function, or a handle object.
Return true if the listener is removed successfully, false if the listener is not found.
The time complexity is O(1).
Generated using TypeDoc
EventDispatcher is something like a map between the
EventType
andCallbackList
.EventDispatcher holds a map of
<EventType, CallbackList>
pairs. On dispatching, EventDispatcher finds the CallbackList of the event type, then invoke the callback list. The invocation is always synchronous. The listeners are triggered when EventDispatcher.dispatch is called.Nested listener safety