1 |
|
2 |
|
3 | export interface Dispatch<T extends object> {
|
4 | |
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | apply(type: string, that?: T, args?: any[]): void;
|
14 |
|
15 | |
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 | call(type: string, that?: T, ...args: any[]): void;
|
26 |
|
27 | |
28 |
|
29 |
|
30 |
|
31 | copy(): Dispatch<T>;
|
32 |
|
33 | |
34 |
|
35 |
|
36 |
|
37 | on(typenames: string): ((this: T, ...args: any[]) => void) | undefined;
|
38 | /**
|
39 | * Adds or removes the callback for the specified typenames.
|
40 | * If a callback function is specified, it is registered for the specified (fully-qualified) typenames.
|
41 | * If a callback was already registered for the given typenames, the existing callback is removed before the new callback is added.
|
42 | * The specified typenames is a string, such as start or end.foo.
|
43 | * The type may be optionally followed by a period (.) and a name; the optional name allows multiple callbacks to be registered to receive events of the same type, such as start.foo and start.bar.
|
44 | * To specify multiple typenames, separate typenames with spaces, such as start end or start.foo start.bar.
|
45 | * To remove all callbacks for a given name foo, say dispatch.on(".foo", null).
|
46 | */
|
47 | on(typenames: string, callback: null | ((this: T, ...args: any[]) => void)): this;
|
48 | }
|
49 |
|
50 | /**
|
51 | * Creates a new dispatch for the specified event types. Each type is a string, such as "start" or "end".
|
52 | *
|
53 | * @param types The event types.
|
54 | * @throws "illegal type" on empty string or duplicated event types.
|
55 | */
|
56 | // eslint-disable-next-line @definitelytyped/no-unnecessary-generics
|
57 | export function dispatch<T extends object>(...types: string[]): Dispatch<T>;
|
58 |
|
\ | No newline at end of file |