import { AsyncTeardownManager, type Subscription } from "../teardown-manager.js"; import type { AllEventKeys, EventBus, SpecialEvents } from "./event-bus.js"; import { Event, type EventArgs, type EventKeys, type EventListener, type EventOptions, type EventReturnType, type IEvent } from "./shared.js"; export type AllEvents = T & SpecialEvents; /** * EventEmitter class to manage events and listeners. * @template T * @implements {Disposable} */ export declare class EventEmitter; } = Record>> extends AsyncTeardownManager implements EventBus { /** * Checks if there are listeners for a given event. * @template TKey * @param {TKey} name - The name of the event. * @returns {boolean} - True if there are listeners, false otherwise. */ hasListener>(name: TKey): boolean; protected readonly events: Partial>; maxListeners: number; /** * Gets the defined events. * @returns {AllEventKeys[]} - An array of defined event names. */ get definedEvents(): EventKeys[]; /** * Creates an instance of EventEmitter. * @param {number | T} [init] - Initial value or number of max listeners. */ constructor(init?: number | T, abort?: AbortSignal); protected eventFactory>(_name: TEvent): AllEvents[TEvent]; /** * Sets an event. * @template TEvent * @param {TEvent} eventName - The name of the event. * @param {AllEvents[TEvent]} event - The event to set. */ set>(eventName: TEvent, event: AllEvents[TEvent]): void; /** * Gets an event. * @template TEvent * @param {TEvent} eventName - The name of the event. * @returns {AllEvents[TEvent]} - The event. */ get>(eventName: TEvent): AllEvents[TEvent]; /** * Gets or creates an event. * @template TEvent * @param {TEvent} eventName - The name of the event. * @returns {AllEvents[TEvent]} - The event. */ getOrCreate>(eventName: TEvent): AllEvents[TEvent]; /** * Sets the maximum number of listeners for an event. * @template TEvent * @param {number} maxListeners - The maximum number of listeners. * @param {TEvent} [event] - The event to set the max listeners for. */ setMaxListeners>(maxListeners: number, event?: TEvent): void; /** * Emits an event. * @template TEvent * @param {TEvent} event - The event to emit. * @param {...EventArgs} args - The arguments to pass to the event listeners. * @returns {false | EventReturnType} - The return value of the event listeners or false if the event does not exist. */ emit>(event: TEvent, ...args: EventArgs[TEvent]>): false | EventReturnType[TEvent]>; /** * Adds a listener for an event. * @template TEvent * @param {TEvent} event - The event to listen to. * @param {EventListener[TEvent]>} handler - The event handler. * @param {EventOptions[TEvent]>} [options] - The event options. * @returns {Subscription} - The subscription. */ on>(event: TEvent, handler: EventListener[TEvent]>, options?: EventOptions[TEvent]>): Subscription; /** * Adds a one-time listener for an event. * @template TEvent * @param {TEvent} event - The event to listen to. * @param {EventListener[TEvent]>} handler - The event handler. * @param {Omit[TEvent]>, 'once'>} [options] - The event options. * @returns {Subscription} - The subscription. */ once>(event: TEvent, handler: EventListener[TEvent]>, options?: Omit[TEvent]>, 'once'>): Subscription; /** * Removes a listener for an event. * @template TEvent * @param {TEvent} event - The event to remove the listener from. * @param {EventListener[TEvent]>} handler - The event handler. * @returns {boolean} - True if the listener was removed, false otherwise. */ off>(event: TEvent, handler: EventListener[TEvent]>): boolean; /** * Disposes the event emitter. */ [Symbol.dispose](): void; } export declare class TopDownNamespaceEventEmitter> = Record>> extends EventEmitter { on>(event: TEvent, handler: EventListener[TEvent]>, options?: EventOptions[TEvent]>): Subscription; } export declare class BottomUpNamespaceEventEmitter> = Record>> extends EventEmitter { emit>(event: TEvent, ...args: EventArgs[TEvent]>): false | EventReturnType[TEvent]>; }