UNPKG

@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.

27 lines 1.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.eventBus = void 0; const CloningEventEmitter_1 = require("../emitter/CloningEventEmitter"); /** * EventBus class represents a singleton event bus instance using EventEmitter3. * It provides a central communication channel for emitting and listening to events. */ class EventBus { /** * Initializes the event bus instance. * If the instance doesn't exist, creates a new one; otherwise, returns the existing instance. * @returns The initialized EventEmitter instance representing the event bus. */ static init() { // Check if the instance already exists if (!EventBus.instance) { // If the instance doesn't exist, create a new EventEmitter instance EventBus.instance = new CloningEventEmitter_1.CloningEventEmitter(); } // Return the initialized instance return EventBus.instance; } } // Initialize and export the singleton instance of the event bus exports.eventBus = EventBus.init(); //# sourceMappingURL=EventBus.js.map