fix(stage): render destroy后移除load事件

This commit is contained in:
roymondchen 2022-03-29 12:44:48 +08:00 committed by jia000
parent 504adcb017
commit f03281ac6c

View File

@ -52,15 +52,7 @@ export default class StageRender extends EventEmitter {
height: 100%; height: 100%;
`; `;
this.iframe.onload = async () => { this.iframe.addEventListener('load', this.loadHandler);
this.emit('onload');
if (this.render) {
const el = await this.render(this.core);
if (el) {
this.iframe?.contentDocument?.body?.appendChild(el);
}
}
};
} }
public getMagicApi = () => ({ public getMagicApi = () => ({
@ -113,9 +105,20 @@ export default class StageRender extends EventEmitter {
* *
*/ */
public destroy(): void { public destroy(): void {
this.iframe?.removeEventListener('load', this.loadHandler);
this.contentWindow = null; this.contentWindow = null;
this.iframe?.remove(); this.iframe?.remove();
this.iframe = undefined; this.iframe = undefined;
this.removeAllListeners(); this.removeAllListeners();
} }
private loadHandler = async () => {
this.emit('onload');
if (this.render) {
const el = await this.render(this.core);
if (el) {
this.iframe?.contentDocument?.body?.appendChild(el);
}
}
};
} }