UniversalEvents
UniversalEvents is a class for managing events
Each event has a name, which is a string, which allows one UniversalEvents object to receive and coordinate multiple types of event.
There are 2 methods for listening for an event.
The first is to attach a handler function with UniversalEvents#on.
The second is to await an event with UniversalEvents#await which returns a Promise
.
Events can then be raised with emit
, optionally with arbitrary data which is passed to those listening for that event.
Constructor Summary
Public Constructor | ||
public |
constructor(validEvents: Set<string> | Array<string>) Create a UniversalEvents object
|
Method Summary
Public Methods | ||
public |
addEventListener(eventName: string, handler: function(data: Object)): UniversalEvents Listen for an event.
|
|
public |
Await an event for success and another event for failure.
|
|
public |
Raise an event.
|
|
public |
on(eventName: string, handler: function(data: Object)): UniversalEvents Listen for an event.
|
|
public |
raiseEvent(eventName: string, data: Object): boolean Raise an event.
|
|
public |
removeEventListener(eventName: string, handler: function(data: Object)): UniversalEvents Remove a listener for an event.
|
Public Constructors
Public Methods
public addEventListener(eventName: string, handler: function(data: Object)): UniversalEvents source
Listen for an event. Alias for UniversalEvents#on
public await(successEventName: string, failureEventName: string): Promise source
Await an event for success and another event for failure.
public emit(eventName: string, data: Object): boolean source
Raise an event. Causes all listeners of this event to run. Alias of UniversalEvents#raiseEvent
public on(eventName: string, handler: function(data: Object)): UniversalEvents source
Listen for an event. Alias for UniversalEvents#addEventListener
public raiseEvent(eventName: string, data: Object): boolean source
Raise an event. Causes all listeners of this event to run. Alias of UniversalEvents#emit
public removeEventListener(eventName: string, handler: function(data: Object)): UniversalEvents source
Remove a listener for an event. Be careful when doing this, you should only really remove listeners that were added by you.