From f61b77ceef209b1914e446bfdcd43995cd8cff30 Mon Sep 17 00:00:00 2001 From: mertsincan Date: Tue, 6 Apr 2021 12:49:34 +0300 Subject: [PATCH] Add reset method to EventBus in core --- src/components/utils/EventBus.js | 13 ++++++++++++- src/views/liveeditor/LiveEditor.vue | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/components/utils/EventBus.js b/src/components/utils/EventBus.js index 1c083541a..73b3a0697 100644 --- a/src/components/utils/EventBus.js +++ b/src/components/utils/EventBus.js @@ -7,22 +7,33 @@ export default function() { eventKey = key; eventListener = function(e) { listener(e.detail); }; eventTarget.addEventListener(type, eventListener); + return this; }, 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 }); + return this; }, off(type, key) { if (eventTarget && eventListener && eventKey === key) { eventTarget.removeEventListener(type, eventListener); } + return this; }, emit(type, detail) { if (eventTarget) { eventTarget.dispatchEvent(new CustomEvent(type, { detail })); } + return this; + }, + reset() { + if (eventTarget) { + document.body.removeChild(eventTarget); + eventTarget = eventListener = eventKey = undefined; + } + return this; } } -} \ No newline at end of file +} diff --git a/src/views/liveeditor/LiveEditor.vue b/src/views/liveeditor/LiveEditor.vue index 4c349ad8e..aeb05bb61 100644 --- a/src/views/liveeditor/LiveEditor.vue +++ b/src/views/liveeditor/LiveEditor.vue @@ -59,7 +59,7 @@ export default { }); }, beforeUnmount() { - EventBus.off('run-demo'); + EventBus.off('run-demo').reset(); }, methods: { postSandboxParameters(sourceType) {