Skip to content

Commit

Permalink
fix(state-layer): ensure all listeners are always remove from the pre…
Browse files Browse the repository at this point in the history
…vious target element regardless of attached state
  • Loading branch information
DRiFTy17 committed Dec 7, 2023
1 parent 953d578 commit 80a62bf
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/lib/state-layer/state-layer-foundation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,10 @@ export class StateLayerFoundation implements IStateLayerFoundation {
}
public set targetElement(el: HTMLElement | null) {
// Always remove the listeners from the previous target element
if (this._attached) {
this._removeListeners();
} else {
// If unattached destroy the defer listener to recreate on the new target element
this._removeListeners();

// If unattached destroy the defer listener to recreate on the new target element
if (!this._attached) {
this._adapter.destroy();
this._deferred = false;
}
Expand All @@ -273,9 +273,10 @@ export class StateLayerFoundation implements IStateLayerFoundation {
this._target = value;

if (this._adapter.isConnected) {
if (this._attached) {
this._removeListeners();
} else {
// Always remove the listeners from the previous target element
this._removeListeners();

if (!this._attached) {
this._adapter.destroy();
this._deferred = false;
}
Expand Down

0 comments on commit 80a62bf

Please sign in to comment.