1/* eslint-disable */ 2(function() { 3 if (!window.eventBus) { 4 const subscribers = {}; 5 6 window.eventBus = { 7 /** 8 * Subscribe to an event 9 * @param {string} event - Event name to subscribe to 10 * @param {Function} callback - Function to call when event is published 11 * @returns {Function} - Unsubscribe function 12 */ 13 subscribe: function(event, callback) { 14 if (!subscribers[event]) { 15 subscribers[event] = []; 16 } 17 18 const index = subscribers[event].push(callback) - 1; 19 20 return function unsubscribe() { 21 subscribers[event].splice(index, 1); 22 }; 23 }, 24 25 /** 26 * Publish an event with data 27 * @param {string} event - Event name to publish 28 * @param {any} data - Data to pass to subscribers 29 */ 30 publish: function(event, data) { 31 if (!subscribers[event]) { 32 return; 33 } 34 35 subscribers[event].forEach(callback => { 36 try { 37 callback(data); 38 } catch (err) { 39 console.error(`Error in event handler for ${event}:`, err); 40 } 41 }); 42 }, 43 44 /** 45 * Clear all subscribers for an event or all events 46 * @param {string} [event] - Event to clear subscribers for (optional, clears all if not provided) 47 */ 48 clear: function(event) { 49 if (event) { 50 subscribers[event] = []; 51 } else { 52 Object.keys(subscribers).forEach(key => { 53 subscribers[key] = []; 54 }); 55 } 56 }, 57 58 /** 59 * Get the number of subscribers for an event 60 * @param {string} event - Event name 61 * @returns {number} - Number of subscribers 62 */ 63 getSubscriberCount: function(event) { 64 return subscribers[event] ? subscribers[event].length : 0; 65 }, 66 67 /** 68 * Get all event names that have subscribers 69 * @returns {string[]} - Array of event names 70 */ 71 getEvents: function() { 72 return Object.keys(subscribers).filter(event => subscribers[event].length > 0); 73 }, 74 }; 75 76 // Trigger the initialized event 77 window.dispatchEvent(new CustomEvent(`EventBus:initialized`)); 78 } 79})();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.