UNPKG

2.35 kBTypeScriptView Raw
1import type { ApiInterfaceEvents } from '../types';
2export declare class Events {
3 #private;
4 protected emit(type: ApiInterfaceEvents, ...args: unknown[]): boolean;
5 /**
6 * @description Attach an eventemitter handler to listen to a specific event
7 *
8 * @param type The type of event to listen to. Available events are `connected`, `disconnected`, `ready` and `error`
9 * @param handler The callback to be called when the event fires. Depending on the event type, it could fire with additional arguments.
10 *
11 * @example
12 * <BR>
13 *
14 * ```javascript
15 * api.on('connected', (): void => {
16 * console.log('API has been connected to the endpoint');
17 * });
18 *
19 * api.on('disconnected', (): void => {
20 * console.log('API has been disconnected from the endpoint');
21 * });
22 * ```
23 */
24 on(type: ApiInterfaceEvents, handler: (...args: any[]) => any): this;
25 /**
26 * @description Remove the given eventemitter handler
27 *
28 * @param type The type of event the callback was attached to. Available events are `connected`, `disconnected`, `ready` and `error`
29 * @param handler The callback to unregister.
30 *
31 * @example
32 * <BR>
33 *
34 * ```javascript
35 * const handler = (): void => {
36 * console.log('Connected !);
37 * };
38 *
39 * // Start listening
40 * api.on('connected', handler);
41 *
42 * // Stop listening
43 * api.off('connected', handler);
44 * ```
45 */
46 off(type: ApiInterfaceEvents, handler: (...args: any[]) => any): this;
47 /**
48 * @description Attach an one-time eventemitter handler to listen to a specific event
49 *
50 * @param type The type of event to listen to. Available events are `connected`, `disconnected`, `ready` and `error`
51 * @param handler The callback to be called when the event fires. Depending on the event type, it could fire with additional arguments.
52 *
53 * @example
54 * <BR>
55 *
56 * ```javascript
57 * api.once('connected', (): void => {
58 * console.log('API has been connected to the endpoint');
59 * });
60 *
61 * api.once('disconnected', (): void => {
62 * console.log('API has been disconnected from the endpoint');
63 * });
64 * ```
65 */
66 once(type: ApiInterfaceEvents, handler: (...args: any[]) => any): this;
67}