UNPKG

@kontent-ai/smart-link

Version:

Kontent.ai Smart Link SDK allowing to automatically inject [smart links](https://docs.kontent.ai/tutorials/develop-apps/build-strong-foundation/set-up-editing-from-preview#a-using-smart-links) to Kontent.ai according to manually specified [HTML data attri

26 lines 1.16 kB
/** * Adds an event listener for a given event. This function is not pure as it modifies the provided eventListeners map. */ export const addListener = (eventListeners, event, listener) => { const newListeners = eventListeners.get(event)?.add(listener) ?? new Set([listener]); eventListeners.set(event, newListeners); }; /** * Removes an event listener for a given event. This function is not pure as it modifies the provided eventListeners map. */ export const removeListener = (eventListeners, event, listener) => { eventListeners.get(event)?.delete(listener); }; /** * Emits an event, calling all registered listeners for that event with the provided arguments. * This function is not pure, though it only reads from the eventListeners map, its core purpose is to trigger side effects (the listeners). */ export const emitEvents = (eventListeners, event, ...args) => { const actualEventListeners = eventListeners.get(event); if (actualEventListeners && actualEventListeners.size > 0) { actualEventListeners.forEach((callback) => { callback(...args); }); } }; //# sourceMappingURL=events.js.map