widget: better event listener cleanup

This commit is contained in:
jean-emmanuel 2022-01-28 16:46:10 +01:00
parent 317216bfdc
commit 03c46d421f
2 changed files with 5 additions and 1 deletions

View file

@ -158,7 +158,6 @@ class WidgetManager extends EventEmitter {
if (this.widgets[hash]) {
if (this.widgets[hash].onRemove) {
this.widgets[hash].onRemove()
this.widgets[hash].off()
}
delete this.widgets[hash]
@ -168,6 +167,7 @@ class WidgetManager extends EventEmitter {
})
widget.trigger('widget-removed', {widget: widget})
widget.off('widget-removed')
}
if (id && this.idRoute[id].indexOf(hash) != -1) this.idRoute[id].splice(this.idRoute[id].indexOf(hash), 1)

View file

@ -1268,6 +1268,10 @@ class Widget extends EventEmitter {
}
this.removed = true
for (var name in this._listeners) {
if (name !== 'widget-removed') this.off(name)
}
widgetManager.off(undefined, undefined, this)
sessionManager.off(undefined, undefined, this)
this.removeOscReceivers()