more robust stores purging after editing (slower to...)
This commit is contained in:
parent
cdc96ca704
commit
8d66d243b1
3 changed files with 64 additions and 24 deletions
|
|
@ -4,6 +4,7 @@ WIDGETS = {}
|
|||
WIDGETS_LINKED = {}
|
||||
WIDGETS_ID_BY_PATH = {}
|
||||
SESSION = []
|
||||
STATE = []
|
||||
|
||||
CLIPBOARD = null
|
||||
EDITING = false
|
||||
|
|
|
|||
|
|
@ -8,7 +8,8 @@ var widgets = require('../widgets'),
|
|||
actions = require('../actions'),
|
||||
sidepanelCreateToggle = require('../sidepanel').createToggle,
|
||||
editObject = function(a,b){require('./edit-objects').editObject(a,b,true)},
|
||||
editSession = function(a,b){require('./edit-objects').editSession(a,b,true)}
|
||||
editSession = function(a,b){require('./edit-objects').editSession(a,b,true)},
|
||||
purgeStores = require('./purge')
|
||||
|
||||
|
||||
var getObjectData = function(obj){
|
||||
|
|
@ -50,7 +51,8 @@ var updateDom = function(container,data) {
|
|||
|
||||
// save state
|
||||
var scroll = $('#sidepanel').scrollTop(),
|
||||
state = actions.stateGet()
|
||||
state = actions.stateGet(),
|
||||
hadChildren = data.widgets||data.tabs
|
||||
|
||||
|
||||
|
||||
|
|
@ -88,28 +90,7 @@ var updateDom = function(container,data) {
|
|||
newContainer.find('[data-tab]:first-child').click()
|
||||
|
||||
|
||||
// prune widget stores
|
||||
for (i in WIDGETS) {
|
||||
for (var j=WIDGETS[i].length-1;j>=0;j--) {
|
||||
if (!document.contains(WIDGETS[i][j][0])) {
|
||||
WIDGETS[i].splice(j,1)
|
||||
}
|
||||
}
|
||||
if (!WIDGETS[i].length) {
|
||||
delete WIDGETS[i]
|
||||
}
|
||||
}
|
||||
for (i in WIDGETS_LINKED) {
|
||||
for (var j=WIDGETS_LINKED[i].length-1;j>=0;j--) {
|
||||
if (!document.contains(WIDGETS_LINKED[i][j][0])) {
|
||||
WIDGETS_LINKED[i].splice(j,1)
|
||||
}
|
||||
}
|
||||
if (!WIDGETS_LINKED[i].length) {
|
||||
delete WIDGETS_LINKED[i]
|
||||
}
|
||||
}
|
||||
|
||||
if (container.attr('id')=='container' || container.hasClass('tab') || hadChildren) purgeStores()
|
||||
|
||||
// restore state
|
||||
actions.stateSet(state,false)
|
||||
|
|
|
|||
58
browser/js/app/editor/purge.js
Normal file
58
browser/js/app/editor/purge.js
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
module.exports = function() {
|
||||
|
||||
// prune tabs store
|
||||
var count, newcount, formerBuffuredTabs, bufferedTabs
|
||||
|
||||
while (true) {
|
||||
// we need to do that several times since tabs are referenced in each of their parents
|
||||
|
||||
// get all buffered tabs
|
||||
formerBuffuredTabs = []
|
||||
for (i in TABS) {
|
||||
formerBuffuredTabs.push(TABS[i].tab[0])
|
||||
}
|
||||
|
||||
// remove deleted tabs that are not referenced (have no navigation link pointing to them)
|
||||
var $f = $(formerBuffuredTabs)
|
||||
for (i in TABS) {
|
||||
if (!($f.find(`[data-tab="${i}"]`).length || i== '#container')) {
|
||||
delete TABS[i]
|
||||
}
|
||||
}
|
||||
|
||||
newcount = Object.keys(TABS).length
|
||||
if (count == newcount) break
|
||||
count = newcount
|
||||
|
||||
}
|
||||
|
||||
|
||||
bufferedTabs = []
|
||||
for (i in TABS) {
|
||||
bufferedTabs.push(TABS[i].tab[0])
|
||||
}
|
||||
|
||||
// prune widget stores
|
||||
// if widgets cannot be found in buffered tabs, it must be unreferenced
|
||||
var $b = $(bufferedTabs)
|
||||
for (i in WIDGETS) {
|
||||
for (var j=WIDGETS[i].length-1;j>=0;j--) {
|
||||
if (!$b.find(WIDGETS[i][j]).length) {
|
||||
WIDGETS[i].splice(j,1)
|
||||
}
|
||||
}
|
||||
if (!WIDGETS[i].length) {
|
||||
delete WIDGETS[i]
|
||||
}
|
||||
}
|
||||
for (i in WIDGETS_LINKED) {
|
||||
for (var j=WIDGETS_LINKED[i].length-1;j>=0;j--) {
|
||||
if (!$b.find(WIDGETS_LINKED[i][j]).length) {
|
||||
WIDGETS_LINKED[i].splice(j,1)
|
||||
}
|
||||
}
|
||||
if (!WIDGETS_LINKED[i].length) {
|
||||
delete WIDGETS_LINKED[i]
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue