UNPKG

1.3 kBTypeScriptView Raw
1import type { Fn } from "./fn.js";
2import type { IID } from "./id.js";
3/**
4 * Event listener for {@link Event}.
5 */
6export type Listener<T extends string = string> = Fn<Event<T>, void>;
7/**
8 * Event type used in combination with {@link INotify}.
9 */
10export interface Event<T extends string = string> extends IID<T> {
11 target?: any;
12 canceled?: boolean;
13 value?: any;
14}
15/**
16 * Interface to provide event emitter functionality. Also see
17 * {@link INotifyMixin} decorator mixin.
18 *
19 * The type param `T` can be used to constrain the event type/id.
20 */
21export interface INotify<T extends string = string> {
22 addListener(id: T, fn: Listener<T>, scope?: any): boolean;
23 removeListener(id: T, fn: Listener<T>, scope?: any): boolean;
24 /**
25 * Broadcasts all registered listeners for given event type (in order
26 * registration) and returns true if any of them have been successfully
27 * notified.
28 *
29 * @remarks
30 * If a listener canceled the event (by setting {@link Event.canceled}), the
31 * function will stop notifying other listeners and return false. If no
32 * listeners are registered for the event, the function will also return
33 * false.
34 *
35 * @param event
36 */
37 notify(event: Event<T>): boolean;
38}
39//# sourceMappingURL=event.d.ts.map
\No newline at end of file