new EventManager()
Allows for registering, unregistering, and emitting custom events.
- Source:
Methods
clearAll()
Removes all listeners for all events. Use with caution (e.g., for full engine reset).
- Source:
emit(eventName, …args)
Emits an event, calling all subscribed callback functions.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
eventName |
string | The name of the event to emit. | |
args |
any |
<repeatable> |
Arguments to pass to the callback functions. |
- Source:
off(eventName, callback, contextopt)
Unsubscribes a callback function from a specific event.
For this to work reliably, the same function reference used for `on` must be provided.
If context was provided during `on`, it should ideally be matched too for more specific unsubscription,
but this basic version primarily relies on the callback reference.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
eventName |
string | The name of the event to unsubscribe from. | ||
callback |
function | The callback function to remove. | ||
context |
any |
<optional> |
null | Optional: The context that was used during subscription. |
- Source:
on(eventName, callback, contextopt, onceopt)
Subscribes a callback function to a specific event.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
eventName |
string | The name of the event to subscribe to. | ||
callback |
function | The function to call when the event is emitted. | ||
context |
any |
<optional> |
null | The `this` context for the callback function. |
once |
boolean |
<optional> |
false | If true, the listener will be removed after the first time it's triggered. |
- Source:
once(eventName, callback, contextopt)
Subscribes a callback function to a specific event, to be triggered only once.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
eventName |
string | The name of the event to subscribe to. | ||
callback |
function | The function to call when the event is emitted. | ||
context |
any |
<optional> |
null | The `this` context for the callback function. |
- Source:
removeAllListeners(eventName)
Removes all listeners for a specific event.
Parameters:
Name | Type | Description |
---|---|---|
eventName |
string | The name of the event. |
- Source: