diff --git a/package-lock.json b/package-lock.json index 9e88765..7bc61d8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "domodel", - "version": "1.1.9", + "version": "1.1.10", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "domodel", - "version": "1.1.9", + "version": "1.1.10", "license": "MIT", "devDependencies": { "ava": "^5.3.1", diff --git a/package.json b/package.json index 35e5378..51acd26 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "domodel", - "version": "1.1.9", + "version": "1.1.10", "main": "index.js", "type": "module", "description": "Front-end library", diff --git a/src/binding.js b/src/binding.js index 07ea905..a003f71 100644 --- a/src/binding.js +++ b/src/binding.js @@ -134,6 +134,10 @@ class Binding { * Remove the model and all its children from the DOM and clean up any listener associated with them. */ remove() { + for(const { target, type, listener, options } of this._remoteEventListeners) { + target.removeEventListener(type, listener, options) + } + this._remoteEventListeners = [] const listeners = this._listeners.slice() for(const listener of listeners) { listener.remove() @@ -142,10 +146,6 @@ class Binding { for(const child of children) { child.remove() } - for(const { target, type, listener } of this._remoteEventListeners) { - target.removeEventListener(type, listener) - } - this._remoteEventListeners = [] if(this._parent !== null) { this._parent._children = this._parent._children.filter(child => child !== this) } @@ -168,7 +168,7 @@ class Binding { * @param {object} options */ addEventListener(target, type, listener, options) { - this._remoteEventListeners.push({ target, type, listener }) + this._remoteEventListeners.push({ target, type, listener, options }) target.addEventListener(type, listener, options) }