1 | // Type definitions for D3JS d3-dispatch module 2.0
|
2 | // Project: https://github.com/d3/d3-dispatch/, https://d3js.org/d3-dispatch
|
3 | // Definitions by: Tom Wanzek <https://github.com/tomwanzek>
|
4 | // Alex Ford <https://github.com/gustavderdrache>
|
5 | // Boris Yankov <https://github.com/borisyankov>
|
6 | // denisname <https://github.com/denisname>
|
7 | // Nathan Bierema <https://github.com/Methuselah96>
|
8 | // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
9 |
|
10 | // Last module patch version validated against: 2.0.0
|
11 |
|
12 | export interface Dispatch<T extends object> {
|
13 | /**
|
14 | * Like `function.apply`, invokes each registered callback for the specified type,
|
15 | * passing the callback the specified arguments, with `that` as the `this` context.
|
16 | *
|
17 | * @param type A specified event type.
|
18 | * @param that The `this` context for the callback.
|
19 | * @param args Additional arguments to be passed to the callback.
|
20 | * @throws "unknown type" on unknown event type.
|
21 | */
|
22 | apply(type: string, that?: T, args?: any[]): void;
|
23 |
|
24 | /**
|
25 | * Like `function.call`, invokes each registered callback for the specified type,
|
26 | * passing the callback the specified arguments, with `that` as the `this` context.
|
27 | * See dispatch.apply for more information.
|
28 | *
|
29 | * @param type A specified event type.
|
30 | * @param that The `this` context for the callback.
|
31 | * @param args Additional arguments to be passed to the callback.
|
32 | * @throws "unknown type" on unknown event type.
|
33 | */
|
34 | call(type: string, that?: T, ...args: any[]): void;
|
35 |
|
36 | /**
|
37 | * Returns a copy of this dispatch object.
|
38 | * Changes to this dispatch do not affect the returned copy and vice versa.
|
39 | */
|
40 | copy(): Dispatch<T>;
|
41 |
|
42 | /**
|
43 | * Returns the callback for the specified typenames, if any.
|
44 | * If multiple typenames are specified, the first matching callback is returned.
|
45 | *
|
46 | * @param types An event typename.
|
47 | * @param callback A callback.
|
48 | */
|
49 | on(typenames: string): ((this: T, ...args: any[]) => void) | undefined;
|
50 | /**
|
51 | * Removes the callback for the specified typenames.
|
52 | * To remove all callbacks for a given name `foo`, say `dispatch.on(".foo", null).`
|
53 | *
|
54 | * @param types An event typename.
|
55 | */
|
56 | on(typenames: string, callback: null): this;
|
57 | /**
|
58 | * Adds the callback for the specified typenames.
|
59 | * The callback is registered for the specified (fully-qualified) typenames.
|
60 | * If a callback was already registered for the given typenames,
|
61 | * the existing callback is removed before the new callback is added.
|
62 | *
|
63 | * @param types An event typename.
|
64 | * @param callback A callback.
|
65 | */
|
66 | on(typenames: string, callback: (this: T, ...args: any[]) => void): this;
|
67 | }
|
68 |
|
69 | /**
|
70 | * Creates a new dispatch for the specified event types. Each type is a string, such as "start" or "end".
|
71 | *
|
72 | * @param types The event types.
|
73 | * @throws "illegal type" on empty string or duplicated event types.
|
74 | */
|
75 | export function dispatch<T extends object>(...types: string[]): Dispatch<T>;
|
76 |
|
\ | No newline at end of file |