Add reset method to EventBus in core

pull/1147/head
mertsincan 2021-04-06 12:49:34 +03:00
parent d6b6744f9f
commit f61b77ceef
2 changed files with 13 additions and 2 deletions

View File

@ -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;
}
}
}
}

View File

@ -59,7 +59,7 @@ export default {
});
},
beforeUnmount() {
EventBus.off('run-demo');
EventBus.off('run-demo').reset();
},
methods: {
postSandboxParameters(sourceType) {