/** * Event Bus Module * * Provides centralized event system for cross-module communication. * * Usage: * - Add data-module="event-bus" to enable global event bus * - Or import and use directly: import { EventBus } from './modules/event-bus/index.js' * * Features: * - Pub/sub pattern * - Namespaced events * - Event filtering * - Event history * - Integration with LiveComponents * - Integration with SSE */ import { Logger } from '../../core/logger.js'; import { EventBus, getGlobalEventBus } from './EventBus.js'; const EventBusModule = { name: 'event-bus', eventBus: null, init(config = {}, state = null) { Logger.info('[EventBusModule] Module initialized'); // Create global event bus this.eventBus = getGlobalEventBus(config); // Expose globally for easy access if (typeof window !== 'undefined') { window.EventBus = this.eventBus; } return this; }, /** * Get event bus instance */ getEventBus() { return this.eventBus || getGlobalEventBus(); }, /** * Emit an event */ emit(eventName, data = null, options = {}) { const bus = this.getEventBus(); bus.emit(eventName, data, options); }, /** * Subscribe to an event */ on(eventName, callback, options = {}) { const bus = this.getEventBus(); return bus.on(eventName, callback, options); }, /** * Unsubscribe from an event */ off(eventName, callback) { const bus = this.getEventBus(); bus.off(eventName, callback); }, destroy() { if (this.eventBus) { this.eventBus.destroy(); this.eventBus = null; } if (typeof window !== 'undefined' && window.EventBus) { delete window.EventBus; } Logger.info('[EventBusModule] Module destroyed'); } }; // Export for direct usage export { EventBus, getGlobalEventBus }; // Export as default for module system export default EventBusModule; // Export init function for module system export const init = EventBusModule.init.bind(EventBusModule);