123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
-
- export interface EventsMap {
- [event: string]: any;
- }
-
-
- export interface DefaultEventsMap {
- [event: string]: (...args: any[]) => void;
- }
-
-
- export type EventNames<Map extends EventsMap> = keyof Map & (string | symbol);
-
-
- export type EventParams<
- Map extends EventsMap,
- Ev extends EventNames<Map>
- > = Parameters<Map[Ev]>;
-
-
- export type ReservedOrUserEventNames<
- ReservedEventsMap extends EventsMap,
- UserEvents extends EventsMap
- > = EventNames<ReservedEventsMap> | EventNames<UserEvents>;
-
-
- export type ReservedOrUserListener<
- ReservedEvents extends EventsMap,
- UserEvents extends EventsMap,
- Ev extends ReservedOrUserEventNames<ReservedEvents, UserEvents>
- > = FallbackToUntypedListener<
- Ev extends EventNames<ReservedEvents>
- ? ReservedEvents[Ev]
- : Ev extends EventNames<UserEvents>
- ? UserEvents[Ev]
- : never
- >;
-
-
- type FallbackToUntypedListener<T> = [T] extends [never]
- ? (...args: any[]) => void | Promise<void>
- : T;
-
-
- export class Emitter<
- ListenEvents extends EventsMap,
- EmitEvents extends EventsMap,
- ReservedEvents extends EventsMap = {}
- > {
-
-
- on<Ev extends ReservedOrUserEventNames<ReservedEvents, ListenEvents>>(
- ev: Ev,
- listener: ReservedOrUserListener<ReservedEvents, ListenEvents, Ev>
- ): this;
-
-
-
- once<Ev extends ReservedOrUserEventNames<ReservedEvents, ListenEvents>>(
- ev: Ev,
- listener: ReservedOrUserListener<ReservedEvents, ListenEvents, Ev>
- ): this;
-
-
-
- off<Ev extends ReservedOrUserEventNames<ReservedEvents, ListenEvents>>(
- ev?: Ev,
- listener?: ReservedOrUserListener<ReservedEvents, ListenEvents, Ev>
- ): this;
-
-
-
- emit<Ev extends EventNames<EmitEvents>>(
- ev: Ev,
- ...args: EventParams<EmitEvents, Ev>
- ): this;
-
-
-
- protected emitReserved<Ev extends EventNames<ReservedEvents>>(
- ev: Ev,
- ...args: EventParams<ReservedEvents, Ev>
- ): this;
-
-
-
- listeners<Ev extends ReservedOrUserEventNames<ReservedEvents, ListenEvents>>(
- event: Ev
- ): ReservedOrUserListener<ReservedEvents, ListenEvents, Ev>[];
-
-
-
- hasListeners<
- Ev extends ReservedOrUserEventNames<ReservedEvents, ListenEvents>
- >(event: Ev): boolean;
-
-
-
- removeListener<
- Ev extends ReservedOrUserEventNames<ReservedEvents, ListenEvents>
- >(
- ev?: Ev,
- listener?: ReservedOrUserListener<ReservedEvents, ListenEvents, Ev>
- ): this;
-
-
-
- removeAllListeners<
- Ev extends ReservedOrUserEventNames<ReservedEvents, ListenEvents>
- >(ev?: Ev): this;
- }
|