Event Dispatcher
Event dispatcher enabled classes to listen to and fire events.
you can inherit from EventDispatcher or use as instance.
Global Event Dispatcher instance in available on app
context or can be injected.
#
Usage#
Inherit#
Instance#
Global Dispatcher#
API#
onon(event,callback,[scope],[options])
#
add an event listener
- event - event name routing key also supported.
- callback - callback function that will triggered on event name.
- scope - optional, the scope of the callback function default: this.
- options
- once?: boolean - remove the handler after the first call.
- await?: boolean - await the handler promise default false
- parallel?: boolean - await the handler in parallel default true
- timeout?: number - one timeout in await mode.
- order?: number - handler order in callbacks lower will execute first
#
onceonce(event,[callback],[scope],[options])
#
add an event listener will be called only once if no callback passed a promise will be returned
- event - event name.
- callback - callback function that will triggered on event name.
- scope - optional, the scope of the callback function default: this.
- options - same as
on
#
unun(event,callback,[scope])
#
remove an event listener. All the arguments must be === to the onces used in the on method, or else it won`t be removed.
- event - event name.
- callback - callback function.
- scope - optional, the scope of the callback function.
#
fireEventfireEvent(event,[arguments])
#
fireEvent - triggers the callback functions of a given event name
- eventName - name of the event
- arguments - all other arguments will be passed to the callback function
#
fireEventAsyncfireEventAsync(event,[arguments])
#
fireEvent - triggers the callback functions of a given event name and wait for handlers callback promise to resolve.
- eventName - name of the event
- arguments - all other arguments will be passed to the callback function
#
removeAllListenersremoveAllListeners()
#
removes all event listeners
#
removeListenersByScoperemoveListenersByScope(scope)
#
removes all event listeners by given scope
#
hasListenerhasListener(event,callback,[scope]):boolean
#
return true if listener exists
#
bubblebubble(event: string, scope: IEventDispatcher)
#
fire event given event on given scope
#
listenerCount(event: string): number
#
return number of listener for given event
#
iteratoriterator<T>(event: string | string[], options?: { limit?: number }): AsyncIterableIterator<T>
#
return AsyncIterableIterator for given event