Skip to content

Commit

Permalink
fix: remove array type event listeners
Browse files Browse the repository at this point in the history
  • Loading branch information
jorenrui committed Feb 10, 2024
1 parent 78a3925 commit 2bca46d
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions lib/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,8 @@ export default class Entity {
}

applyEventBindings() {
this.removeEventBindings()

const el = this.element

// Change binding
Expand Down Expand Up @@ -445,8 +447,16 @@ export default class Entity {

removeEventBindings() {
Object.keys(this.listener).forEach((key) => {
const { el, eventName, event } = this.listener[key]
el.removeEventListener(eventName, event)
const listener = this.listener[key]

if (Array.isArray(listener)) {
listener.forEach(({ el, eventName, event }) => {
el.removeEventListener(eventName, event)
})
} else {
const { el, eventName, event } = listener
el.removeEventListener(eventName, event)
}
})
}

Expand Down Expand Up @@ -489,7 +499,7 @@ export default class Entity {
unusedVariables.forEach((variable) => {
if (variable.startsWith('el.')) {
const varName = variable.replace('el.', '')
delete window[this.uuid][varName]
if (window[this.uuid]?.[varName]) delete window[this.uuid]
} else {
delete window[variable]
}
Expand Down

0 comments on commit 2bca46d

Please sign in to comment.