@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
32 lines • 1.4 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.emitEvents = exports.removeListener = exports.addListener = void 0;
/**
* Adds an event listener for a given event. This function is not pure as it modifies the provided eventListeners map.
*/
const addListener = (eventListeners, event, listener) => {
const newListeners = eventListeners.get(event)?.add(listener) ?? new Set([listener]);
eventListeners.set(event, newListeners);
};
exports.addListener = addListener;
/**
* Removes an event listener for a given event. This function is not pure as it modifies the provided eventListeners map.
*/
const removeListener = (eventListeners, event, listener) => {
eventListeners.get(event)?.delete(listener);
};
exports.removeListener = removeListener;
/**
* 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).
*/
const emitEvents = (eventListeners, event, ...args) => {
const actualEventListeners = eventListeners.get(event);
if (actualEventListeners && actualEventListeners.size > 0) {
actualEventListeners.forEach((callback) => {
callback(...args);
});
}
};
exports.emitEvents = emitEvents;
//# sourceMappingURL=events.js.map