From 870693e7dfe7fe31e6ee88b422cc72986a98f3d2 Mon Sep 17 00:00:00 2001 From: Cagatay Civici Date: Wed, 3 Mar 2021 12:56:04 +0300 Subject: [PATCH] Fixed #1046 - CDN builds are broken --- src/components/utils/EventBus.js | 13 ++++++++----- src/components/utils/OverlayEventBus.js | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/components/utils/EventBus.js b/src/components/utils/EventBus.js index 2e18a56d14..1c083541ac 100644 --- a/src/components/utils/EventBus.js +++ b/src/components/utils/EventBus.js @@ -1,25 +1,28 @@ -export default function handler() { - let eventTarget = document.body.appendChild(document.createComment('')); - let eventListener, eventKey; +export default function() { + let eventTarget, eventListener, eventKey; return { on(type, listener, key) { + eventTarget = eventTarget || document.body.appendChild(document.createComment('')); eventKey = key; eventListener = function(e) { listener(e.detail); }; eventTarget.addEventListener(type, eventListener); }, once(type, listener, key) { + eventTarget = eventTarget || document.body.appendChild(document.createComment('')); eventKey = key; eventListener = function(e) { listener(e.detail); }; eventTarget.addEventListener(type, eventListener, { once: true }); }, off(type, key) { - if (eventListener && eventKey === key) { + if (eventTarget && eventListener && eventKey === key) { eventTarget.removeEventListener(type, eventListener); } }, emit(type, detail) { - eventTarget.dispatchEvent(new CustomEvent(type, { detail })); + if (eventTarget) { + eventTarget.dispatchEvent(new CustomEvent(type, { detail })); + } } } } \ No newline at end of file diff --git a/src/components/utils/OverlayEventBus.js b/src/components/utils/OverlayEventBus.js index 844a1b111d..5b55760f8c 100644 --- a/src/components/utils/OverlayEventBus.js +++ b/src/components/utils/OverlayEventBus.js @@ -1,3 +1,3 @@ -import {EventBus} from 'primevue/utils'; +import EventBus from './EventBus.js'; export default EventBus(); \ No newline at end of file