Add reset method to EventBus in core
parent
d6b6744f9f
commit
f61b77ceef
|
@ -7,22 +7,33 @@ export default function() {
|
||||||
eventKey = key;
|
eventKey = key;
|
||||||
eventListener = function(e) { listener(e.detail); };
|
eventListener = function(e) { listener(e.detail); };
|
||||||
eventTarget.addEventListener(type, eventListener);
|
eventTarget.addEventListener(type, eventListener);
|
||||||
|
return this;
|
||||||
},
|
},
|
||||||
once(type, listener, key) {
|
once(type, listener, key) {
|
||||||
eventTarget = eventTarget || document.body.appendChild(document.createComment(''));
|
eventTarget = eventTarget || document.body.appendChild(document.createComment(''));
|
||||||
eventKey = key;
|
eventKey = key;
|
||||||
eventListener = function(e) { listener(e.detail); };
|
eventListener = function(e) { listener(e.detail); };
|
||||||
eventTarget.addEventListener(type, eventListener, { once: true });
|
eventTarget.addEventListener(type, eventListener, { once: true });
|
||||||
|
return this;
|
||||||
},
|
},
|
||||||
off(type, key) {
|
off(type, key) {
|
||||||
if (eventTarget && eventListener && eventKey === key) {
|
if (eventTarget && eventListener && eventKey === key) {
|
||||||
eventTarget.removeEventListener(type, eventListener);
|
eventTarget.removeEventListener(type, eventListener);
|
||||||
}
|
}
|
||||||
|
return this;
|
||||||
},
|
},
|
||||||
emit(type, detail) {
|
emit(type, detail) {
|
||||||
if (eventTarget) {
|
if (eventTarget) {
|
||||||
eventTarget.dispatchEvent(new CustomEvent(type, { detail }));
|
eventTarget.dispatchEvent(new CustomEvent(type, { detail }));
|
||||||
}
|
}
|
||||||
|
return this;
|
||||||
|
},
|
||||||
|
reset() {
|
||||||
|
if (eventTarget) {
|
||||||
|
document.body.removeChild(eventTarget);
|
||||||
|
eventTarget = eventListener = eventKey = undefined;
|
||||||
|
}
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -59,7 +59,7 @@ export default {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
beforeUnmount() {
|
beforeUnmount() {
|
||||||
EventBus.off('run-demo');
|
EventBus.off('run-demo').reset();
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
postSandboxParameters(sourceType) {
|
postSandboxParameters(sourceType) {
|
||||||
|
|
Loading…
Reference in New Issue