UNPKG

1.11 kBTypeScriptView Raw
1/**
2 * Intentionally very simple event emitter.
3 *
4 * @privateRemarks
5 * This is essentially a stripped down copy of EventHooks in hooks.ts.
6 */
7export declare class EventDispatcher<T extends Record<keyof T, unknown[]>> {
8 private _listeners;
9 /**
10 * Starts listening to an event.
11 * @param event the event to listen to.
12 * @param listener function to be called when an this event is emitted.
13 * @param priority optional priority to insert this hook with.
14 */
15 on<K extends keyof T>(event: K, listener: (this: undefined, ...args: T[K]) => void, priority?: number): void;
16 /**
17 * Stops listening to an event.
18 * @param event the event to stop listening to.
19 * @param listener the function to remove from the listener array.
20 */
21 off<K extends keyof T>(event: K, listener: (this: undefined, ...args: T[K]) => void): void;
22 /**
23 * Emits an event to all currently subscribed listeners.
24 * @param event the event to emit.
25 * @param args any arguments required for the event.
26 */
27 trigger<K extends keyof T>(event: K, ...args: T[K]): void;
28}
29
\No newline at end of file