2020-07-14 15:57:29 +00:00
|
|
|
export declare type EventType = string | symbol;
|
2020-07-29 11:11:40 +00:00
|
|
|
export declare type Handler<T = any> = (event?: T) => void;
|
2020-07-14 15:57:29 +00:00
|
|
|
export declare type WildcardHandler = (type: EventType, event?: any) => void;
|
|
|
|
export declare type EventHandlerList = Array<Handler>;
|
|
|
|
export declare type WildCardEventHandlerList = Array<WildcardHandler>;
|
|
|
|
export declare type EventHandlerMap = Map<EventType, EventHandlerList | WildCardEventHandlerList>;
|
|
|
|
export interface Emitter {
|
2020-07-29 11:11:40 +00:00
|
|
|
all: EventHandlerMap;
|
|
|
|
on<T = any>(type: EventType, handler: Handler<T>): void;
|
2020-07-14 15:57:29 +00:00
|
|
|
on(type: '*', handler: WildcardHandler): void;
|
2020-07-29 11:11:40 +00:00
|
|
|
off<T = any>(type: EventType, handler: Handler<T>): void;
|
2020-07-14 15:57:29 +00:00
|
|
|
off(type: '*', handler: WildcardHandler): void;
|
|
|
|
emit<T = any>(type: EventType, event?: T): void;
|
|
|
|
emit(type: '*', event?: any): void;
|
|
|
|
}
|
2020-07-29 11:11:40 +00:00
|
|
|
/**
|
|
|
|
* Mitt: Tiny (~200b) functional event emitter / pubsub.
|
|
|
|
* @name mitt
|
|
|
|
* @returns {Mitt}
|
2020-07-14 15:57:29 +00:00
|
|
|
*/
|
|
|
|
export default function mitt(all?: EventHandlerMap): Emitter;
|