UNPKG

2.49 kBTypeScriptView Raw
1/**
2 * Handles named events.
3 * @experimental
4 *
5 * This is basically a (better typed) duplicate of Observable, which will replace Observable in the
6 * next release.
7 *
8 * @template {{[key in keyof EVENTS]: function(...any):void}} EVENTS
9 */
10export class ObservableV2<EVENTS extends { [key in keyof EVENTS]: (...arg0: any[]) => void; }> {
11 /**
12 * Some desc.
13 * @type {Map<string, Set<any>>}
14 */
15 _observers: Map<string, Set<any>>;
16 /**
17 * @template {keyof EVENTS & string} NAME
18 * @param {NAME} name
19 * @param {EVENTS[NAME]} f
20 */
21 on<NAME extends keyof EVENTS & string>(name: NAME, f: EVENTS[NAME]): EVENTS[NAME];
22 /**
23 * @template {keyof EVENTS & string} NAME
24 * @param {NAME} name
25 * @param {EVENTS[NAME]} f
26 */
27 once<NAME_1 extends keyof EVENTS & string>(name: NAME_1, f: EVENTS[NAME_1]): void;
28 /**
29 * @template {keyof EVENTS & string} NAME
30 * @param {NAME} name
31 * @param {EVENTS[NAME]} f
32 */
33 off<NAME_2 extends keyof EVENTS & string>(name: NAME_2, f: EVENTS[NAME_2]): void;
34 /**
35 * Emit a named event. All registered event listeners that listen to the
36 * specified name will receive the event.
37 *
38 * @todo This should catch exceptions
39 *
40 * @template {keyof EVENTS & string} NAME
41 * @param {NAME} name The event name.
42 * @param {Parameters<EVENTS[NAME]>} args The arguments that are applied to the event listener.
43 */
44 emit<NAME_3 extends keyof EVENTS & string>(name: NAME_3, args: Parameters<EVENTS[NAME_3]>): void;
45 destroy(): void;
46}
47/**
48 * Handles named events.
49 *
50 * @deprecated
51 * @template N
52 */
53export class Observable<N> {
54 /**
55 * Some desc.
56 * @type {Map<N, any>}
57 */
58 _observers: Map<N, any>;
59 /**
60 * @param {N} name
61 * @param {function} f
62 */
63 on(name: N, f: Function): void;
64 /**
65 * @param {N} name
66 * @param {function} f
67 */
68 once(name: N, f: Function): void;
69 /**
70 * @param {N} name
71 * @param {function} f
72 */
73 off(name: N, f: Function): void;
74 /**
75 * Emit a named event. All registered event listeners that listen to the
76 * specified name will receive the event.
77 *
78 * @todo This should catch exceptions
79 *
80 * @param {N} name The event name.
81 * @param {Array<any>} args The arguments that are applied to the event listener.
82 */
83 emit(name: N, args: Array<any>): void;
84 destroy(): void;
85}
86//# sourceMappingURL=observable.d.ts.map
\No newline at end of file