widgets: call an optionnal onRemove() callback method before deleting widgets from manager

=> and unbind event handlers attached to the documents root
This commit is contained in:
jean-emmanuel 2017-01-03 12:17:16 +01:00
parent 193c9e421e
commit 4efb32f0e7
3 changed files with 23 additions and 7 deletions

View file

@ -92,7 +92,10 @@ WidgetManager.prototype.removeWidget = function(hash) {
linkId = widget.widgetData.linkId,
id = widget.widgetData.id
if (this.widgets[hash]) delete this.widgets[hash]
if (this.widgets[hash]) {
if (this.widgets[hash].onRemove) this.widgets[hash].onRemove()
delete this.widgets[hash]
}
if (id && this.idRoute[id].indexOf(hash) != -1) this.idRoute[id].splice(this.idRoute[id].indexOf(hash), 1)
if (linkId && this.linkIdRoute[linkId].indexOf(hash) != -1) this.linkIdRoute[linkId].splice(this.linkIdRoute[linkId].indexOf(hash), 1)
if (address && this.addressRoute[address].indexOf(hash) != -1) this.addressRoute[address].splice(this.addressRoute[address].indexOf(hash), 1)

View file

@ -30,13 +30,19 @@ module.exports = class _plots_base extends _canvas_base {
}
$('body').on('sync',this.syncHandleProxy.bind(this))
this.syncHandleProxy = ()=>{
this.syncHandle(...arguments)
}
$('body').on('sync',this.syncHandleProxy)
}
syncHandleProxy() {
onRemove() {
this.syncHandle(...arguments)
$('body').off('sync',this.syncHandleProxy)
}

View file

@ -18,8 +18,7 @@ module.exports = class _switchers_base extends _widgets_base {
}
$('body').on('sync',(e)=>{
this.syncHandler = (e)=>{
var {id, widget, linkId, fromExternal, options} = e
@ -29,8 +28,16 @@ module.exports = class _switchers_base extends _widgets_base {
}
})
}
$('body').on('sync',this.syncHandler)
}
onRemove() {
$('body').off('sync',this.syncHandler)
}