From 2bca46dc397ed7202efd7f6f67d9e9a24f8d7e58 Mon Sep 17 00:00:00 2001 From: Joeylene <23741509+jorenrui@users.noreply.github.com> Date: Sat, 10 Feb 2024 22:17:57 +0800 Subject: [PATCH] fix: remove array type event listeners --- lib/entity.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/entity.js b/lib/entity.js index 8d4a714..b50be84 100644 --- a/lib/entity.js +++ b/lib/entity.js @@ -330,6 +330,8 @@ export default class Entity { } applyEventBindings() { + this.removeEventBindings() + const el = this.element // Change binding @@ -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) + } }) } @@ -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] }