diff --git a/src/elements.ts b/src/elements.ts index 7ee92fb..6421240 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:', this); + 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. */