From 17d8560c3bd2cfc10ae7d24b85d3bb293d0d3628 Mon Sep 17 00:00:00 2001 From: jean-emmanuel Date: Thu, 8 Dec 2016 10:45:05 +0100 Subject: [PATCH] manager: rename store reset method, create a route purging method to call after removing widgets --- src/browser/js/app/editor/purge.js | 2 ++ src/browser/js/app/managers.js | 20 +++++++++++++++++--- src/browser/js/app/parser.js | 2 +- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/browser/js/app/editor/purge.js b/src/browser/js/app/editor/purge.js index 0499e77a..54149526 100644 --- a/src/browser/js/app/editor/purge.js +++ b/src/browser/js/app/editor/purge.js @@ -44,4 +44,6 @@ module.exports = function(purgetabs) { widgetManager.removeWidget(hash) } } + widgetManager.purge() + } diff --git a/src/browser/js/app/managers.js b/src/browser/js/app/managers.js index 059a7ce7..fc878d4c 100644 --- a/src/browser/js/app/managers.js +++ b/src/browser/js/app/managers.js @@ -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 = {} diff --git a/src/browser/js/app/parser.js b/src/browser/js/app/parser.js index 25d0843d..945db0ca 100644 --- a/src/browser/js/app/parser.js +++ b/src/browser/js/app/parser.js @@ -41,7 +41,7 @@ module.exports.tabs = function(data,parent,main,parentLabel){ iterators.tab = {} iterators.widget = {} - widgetManager.purge() + widgetManager.reset() } var main = main?'main ':'',