Skip to content

Commit

Permalink
fix(stage): render destroy后移除load事件
Browse files Browse the repository at this point in the history
  • Loading branch information
roymondchen authored and jia000 committed Mar 29, 2022
1 parent 504adcb commit f03281a
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions packages/stage/src/StageRender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,7 @@ export default class StageRender extends EventEmitter {
height: 100%;
`;

this.iframe.onload = async () => {
this.emit('onload');
if (this.render) {
const el = await this.render(this.core);
if (el) {
this.iframe?.contentDocument?.body?.appendChild(el);
}
}
};
this.iframe.addEventListener('load', this.loadHandler);
}

public getMagicApi = () => ({
Expand Down Expand Up @@ -113,9 +105,20 @@ export default class StageRender extends EventEmitter {
* 销毁实例
*/
public destroy(): void {
this.iframe?.removeEventListener('load', this.loadHandler);
this.contentWindow = null;
this.iframe?.remove();
this.iframe = undefined;
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);
}
}
};
}

0 comments on commit f03281a

Please sign in to comment.