export = EventsHub; /** * @module shared/eventsHub */ /** * When there's a one time subscription, a wrapper function is created with a special * property to identify it and remove it once it gets triggered. The wrapper and the * original function are stored in case `off` is called before the wrapper gets triggered; * it will receive the original function, not the wrapper, so the class needs a way to map * them together. * * @typedef {Object} EventsHubWrapperInfo * @property {Function} wrapper The wrapper function that was created for the * subscription. * @property {Function} original The original listener that was sent. * @ignore */ /** * @callback EventsHubOnceWrapper * @param {...*} args The parameters for the original listener. * @property {boolean} [once=true] A flag so the class will identify the wrapper. * @returns {*} * @ignore */ /** * A minimal implementation of an events handler service. * * @parent module:shared/eventsHub * @tutorial eventsHub */ declare class EventsHub { /** * A dictionary of the events and their listeners. * * @type {Object.} * @access protected * @ignore */ _events: { [x: string]: Function[]; }; /** * A dictionary of wrappers that were created for "one time subscriptions". This is * used by the {@link EventsHub#off}: if it doesn't find the subscriber as it is, it * will look for a wrapper and remove it. * * @type {Object.} * @access protected * @ignore */ _onceWrappers: { [x: string]: EventsHubWrapperInfo[]; }; /** * Emits an event and call all its listeners. * * @param {string | string[]} event An event name or a list of them. * @param {...*} args A list of parameters to send to the listeners. */ emit(event: string | string[], ...args: any[]): void; /** * Removes an event listener. * * @param {string | string[]} event An event name or a list of them. * @param {Function} fn The listener function. * @returns {boolean | boolean[]} If `event` was a `string`, it will return whether or * not the listener was found and removed; but if `event` * was an `Array`, it will return a list of boolean * values. */ off(event: string | string[], fn: Function): boolean | boolean[]; /** * Adds a new event listener. * * @param {string | string[]} event An event name or a list of them. * @param {Function} fn The listener function. * @returns {Function} An unsubscribe function to remove the listener or listeners. */ on(event: string | string[], fn: Function): Function; /** * Adds an event listener that will only be executed once. * * @param {string | string[]} event An event name or a list of them. * @param {Function} fn The listener function. * @returns {Function} An unsubscribe function to remove the listener. */ once(event: string | string[], fn: Function): Function; /** * Reduces a target using an event. It's like emit, but the events listener return a * modified (or not) version of the `target`. * * @param {string | string[]} event An event name or a list of them. * @param {T} target The variable to reduce with the listeners. * @param {...*} args A list of parameters to send to the listeners. * @returns {T} A version of the `target` processed by the listeners. * @template T */ reduce(event: string | string[], target: T, ...args: any[]): T; /** * Reduces a target using an event. It's like emit, but the events listener return a * modified (or not) version of the `target`. This is the version async of `reduce`. * * @param {string | string[]} event An event name or a list of them. * @param {T} target The variable to reduce with the listeners. * @param {...*} args A list of parameters to send to the listeners. * @returns {Promise} A version of the `target` processed by the listeners. * @template T */ reduceAsync(event: string | string[], target: T_1, ...args: any[]): Promise; /** * Gets all the listeners for an event. * * @param {string} event The name of the event. * @returns {Function[]} */ subscribers(event: string): Function[]; } declare namespace EventsHub { export { EventsHubWrapperInfo, EventsHubOnceWrapper }; } /** * When there's a one time subscription, a wrapper function is created with a special * property to identify it and remove it once it gets triggered. The wrapper and the * original function are stored in case `off` is called before the wrapper gets triggered; * it will receive the original function, not the wrapper, so the class needs a way to map * them together. */ type EventsHubWrapperInfo = { /** * The wrapper function that was created for the * subscription. */ wrapper: Function; /** * The original listener that was sent. */ original: Function; }; type EventsHubOnceWrapper = (...args: any[]) => any;