EventWatcher
Class: EventWatcher
A generic class that provides event handling functionality.
Constructor
constructor()
Creates a new instance of EventWatcher.
Methods
bind
bind(name: T, callback: (...data: any[]) => void): void
Binds an event handler to a specific event name.
- Parameters:
name: The event namecallback: The function to be called when the event is triggered
- Returns: void
unbind
unbind(name: T): void
Removes all event handlers for a specific event name.
- Parameters:
name: The event name to unbind
- Returns: void
emit
emit(name: T, ...data: any[]): void
Triggers an event with the specified name and data.
- Parameters:
name: The event name to trigger...data: Optional data to pass to the event handlers
- Returns: void
once
once(name: T, callback: (...data: any[]) => void): void
Binds an event handler that will be called only once when the event is triggered.
- Parameters:
name: The event namecallback: The function to be called when the event is triggered
- Returns: void