@adorsys-gis/event-bus
Version:
An event-driven library for managing custom events in JavaScript applications. Built on eventemitter3, it supports both synchronous and asynchronous event handling and ensures deep cloning of emitted data to prevent unintended mutations.
17 lines (16 loc) • 757 B
TypeScript
import { EventEmitter } from 'eventemitter3';
/**
* This specialized event emitter deep clones all emitted objects.
*/
export declare class CloningEventEmitter<EventTypes extends EventEmitter.ValidEventTypes = string | symbol, Context = unknown> extends EventEmitter<EventTypes, Context> {
/**
* Calls each of the listeners registered for a given event.
*
* This overriding logic deep clones all emitted objects using
* the `structuredClone` global function. Uncloneable objects
* lead to a `DataCloneError`.
*
* See https://developer.mozilla.org/en-US/docs/Web/API/structuredClone
*/
emit<T extends EventEmitter.EventNames<EventTypes>>(event: T, ...args: EventEmitter.EventArgs<EventTypes, T>): boolean;
}