From 0924ff63d83647e827fdfa54afbcd1fc2fc9adbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9ry=20Debongnie?= Date: Thu, 13 Jan 2022 15:22:11 +0100 Subject: [PATCH] wip --- src/app/template_helpers.ts | 6 +----- src/portal.ts | 4 +++- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/app/template_helpers.ts b/src/app/template_helpers.ts index 10de502d..86dc3af9 100644 --- a/src/app/template_helpers.ts +++ b/src/app/template_helpers.ts @@ -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; } diff --git a/src/portal.ts b/src/portal.ts index 23fa759b..833038a4 100644 --- a/src/portal.ts +++ b/src/portal.ts @@ -7,13 +7,15 @@ export class VPortal extends VText implements Partial> { 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;