export type ValidReturnValue = void | undefined | boolean; export type ValidEventTypes = Record ValidReturnValue>; /** * Listener is object that is listening for specified event type emissions and is running when that kind of event was emitted */ declare class Listener ValidReturnValue> { readonly eventName: EventName; private readonly callback; private readonly context; private readonly once?; private active; /** * * @param eventName name of event that listener is related to * @param callback function runs when listener is triggered * @param context context to run callback function on * @param once information that listener will be runned only once or on each time when event will emit */ constructor(eventName: EventName, callback: EventCallback, context: unknown, once?: boolean | undefined); /** * Makes listener active. In effect it will **run** when event will emit */ on(): void; /** * Makes listener inactive. In effect it will **not run** if event will emit */ off(): void; /** * Method to run listener registered callback function * @param args arguments for callback function * @returns */ run(...args: Parameters): ValidReturnValue; /** * Gets information that listener is activated or not. If not then its callback will not run if event will emit * @returns */ isActive(): boolean; /** * Gets information that listener waits for first event emission only or for each next * @returns */ isOnce(): boolean; } /** * Event emitter allows to register listeners for various event types, and trigger that events. After each event emission, all active listeners are running. */ export declare class EventEmitter { private readonly context; private readonly listeners; /** * @param context context to run listeners callback on */ constructor(context: unknown); /** * Registers new listener for event type * @param eventName name of event type to register listener into * @param callback function runs when listener was triggered * @returns instance of created listener */ on(eventName: K, callback: T[K]): Listener; /** * Registers new listener for event type, but that kind of listener will run only once, then removed from event emitter * @param eventName name of event type to register listener into * @param callback function runs when listener was triggered * @returns instance of created listener */ once(eventName: K, callback: T[K]): Listener; /** * Emits event of passed type. In consequence it runs all active listeners. * @param eventName Name of event type to run * @param args arguments to pass to all listeners callbacks * @returns true value if any of listeners callbacks returned true, otherwise false * * @example * ``` * const value = events.emit('afterHide', id); * // value is information if any of callbacks returned true value or not, it could be used to determine any next actions * ``` */ emit(eventName: K, ...args: Parameters): boolean; } export {}; //# sourceMappingURL=EventEmitter.d.ts.map