manager: rename store reset method, create a route purging method to call after removing widgets

This commit is contained in:
jean-emmanuel 2016-12-08 10:45:05 +01:00
parent 433307ebad
commit 17d8560c3b
3 changed files with 20 additions and 4 deletions

View file

@ -44,4 +44,6 @@ module.exports = function(purgetabs) {
widgetManager.removeWidget(hash)
}
}
widgetManager.purge()
}

View file

@ -92,13 +92,27 @@ WidgetManager.prototype.removeWidget = function(hash) {
id = widget.widgetData.id
if (this.widgets[hash]) 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)
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)
}
WidgetManager.prototype.purge = function() {
for (route of [this.addressRoute, this.idRoute, this.linkIdRoute]) {
for (key in route) {
for (hash in route[key]) {
if (!this.widgets[hash]) {
route[key].splice(route[key].indexOf(hash, 1))
}
}
}
}
}
WidgetManager.prototype.reset = function() {
this.widgets = {}
this.addressRoute = {}

View file

@ -41,7 +41,7 @@ module.exports.tabs = function(data,parent,main,parentLabel){
iterators.tab = {}
iterators.widget = {}
widgetManager.purge()
widgetManager.reset()
}
var main = main?'main ':'',