From 0b111697c11edfef7f93e2a6805a0b1411929fd7 Mon Sep 17 00:00:00 2001 From: Philipp Legner Date: Tue, 23 Sep 2025 15:15:19 +0100 Subject: [PATCH 1/2] Allow accessing deleted elements temporarily --- src/elements.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/elements.ts b/src/elements.ts index 7ee92fb..c268c47 100644 --- a/src/elements.ts +++ b/src/elements.ts @@ -47,10 +47,16 @@ export abstract class BaseView { private readonly _mutationObserverCallbacks: Obj = {}; readonly type: string = 'default'; model?: Observable; + isDeleted?: boolean; - constructor(readonly _el: T) { + constructor(readonly __el: T) { // Store a reference to this element within the native browser DOM. - _el._view = this; + __el._view = this; + } + + get _el() { + if (this.isDeleted) console.error('Trying to access a deleted element.'); + return this.__el; } get id() { @@ -602,6 +608,7 @@ export abstract class BaseView { /** Removes listeners and model data from el */ private unsubscribe() { + this.isDeleted = true; this.model?.clear(); this._mutationObserver?.disconnect(); this.offAll(); @@ -610,6 +617,7 @@ export abstract class BaseView { child.unsubscribe(); } + /* Disabled temporarily // hack to avoid TS notification // about setting undefined value to readonly properties delete (this as any)._el; @@ -618,7 +626,7 @@ export abstract class BaseView { // remove mutation observer instances delete (this as any)._mutationObserver; - delete (this as any)._mutationObserverCallbacks; + delete (this as any)._mutationObserverCallbacks; */ } /** Removes this element. */ From cca60c7d59d1056ced06a9b40f35cbcbcbbaf842 Mon Sep 17 00:00:00 2001 From: Philipp Legner Date: Wed, 24 Sep 2025 13:00:32 +0100 Subject: [PATCH 2/2] Log which element is deleted --- src/elements.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/elements.ts b/src/elements.ts index c268c47..6421240 100644 --- a/src/elements.ts +++ b/src/elements.ts @@ -55,7 +55,7 @@ export abstract class BaseView { } get _el() { - if (this.isDeleted) console.error('Trying to access a deleted element.'); + if (this.isDeleted) console.error('Trying to access a deleted element:', this); return this.__el; }