This commit is contained in:
Géry Debongnie
2022-01-13 15:22:11 +01:00
parent fb64355f59
commit 0924ff63d8
2 changed files with 4 additions and 6 deletions
+1 -5
View File
@@ -20,11 +20,7 @@ function callPortal(
target: string,
content: (ctx: any, node: any, key: string) => BDom
): BDom {
const portal = new VPortal(target, content(ctx, parent, key)) as any;
// make sure we cleanup only once
if (!ctx.__owl)
ctx.__owl__.willDestroy.push(() => portal.cleanup());
ctx.__owl__.hasPortal = true;
const portal = new VPortal(target, content(ctx, parent, key), ctx.__owl__) as any;
return portal;
}
+3 -1
View File
@@ -7,13 +7,15 @@ export class VPortal extends VText implements Partial<VNode<VPortal>> {
realBDom: BDom | null;
target: HTMLElement | null = null;
constructor(selector: string, realBDom: BDom) {
constructor(selector: string, realBDom: BDom, ownerComponent: ComponentNode) {
super("");
this.ownerComponent = ownerComponent;
this.selector = selector;
this.realBDom = realBDom;
}
mount(parent: HTMLElement, anchor: ChildNode) {
super.mount(parent, anchor);
this.ownerComponent.willDestroy.push(() => this.cleanup());
this.target = document.querySelector(this.selector) as any;
if (!this.target) {
let el: any = this.el;