Chatwoot/app/javascript/shared/helpers/CustomEventHelper.js
2022-02-21 09:40:11 +05:30

15 lines
470 B
JavaScript

export const createEvent = ({ eventName, data = null }) => {
let event;
if (typeof window.CustomEvent === 'function') {
event = new CustomEvent(eventName, { detail: data });
} else {
event = document.createEvent('CustomEvent');
event.initCustomEvent(eventName, false, false, data);
}
return event;
};
export const dispatchWindowEvent = ({ eventName, data }) => {
const event = createEvent({ eventName, data });
window.dispatchEvent(event);
};