forked from developit/mitt
-
Notifications
You must be signed in to change notification settings - Fork 3
/
emitt.d.ts
49 lines (42 loc) · 1.37 KB
/
emitt.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
declare var emitt: emitt.EMittStatic;
export = emitt;
export as namespace emitt;
declare namespace emitt {
type Handler = (event?: any, ...args: any[]) => void;
type WildcardHandler = (type?: string, event?: any) => void;
interface EMittStatic {
(all?: {[key: string]: Handler}): Emitter;
}
interface Emitter {
/**
* Register an event handler for the given type.
*
* @param {string} type Type of event to listen for, or `"*"` for all events.
* @param {Handler} handler Function to call in response to the given event.
*
* @memberOf Emitt
*/
on(type: string, handler: Handler): void;
on(type: "*", handler: WildcardHandler): void;
/**
* Function to call in response to the given event
*
* @param {string} type Type of event to unregister `handler` from, or `"*"`
* @param {Handler} handler Handler function to remove.
*
* @memberOf Emitt
*/
off(type: string, handler: Handler): void;
off(type: "*", handler: WildcardHandler): void;
/**
* Invoke all handlers for the given type.
* If present, `"*"` handlers are invoked prior to type-matched handlers.
*
* @param {string} type The event type to invoke
* @param {any[]} [...event_args] arguments passed to each handler
*
* @memberOf Emitt
*/
emit(type: string, ...event_args: any[]): void;
}
}