editor: use a shared tmp state to prevent a fresh "value" property value to be applied
This commit is contained in:
parent
66d48a38fc
commit
cb86370cb4
3 changed files with 35 additions and 9 deletions
|
|
@ -2,6 +2,7 @@ var editObject = function(){editObject = require('./edit-objects').editObject; e
|
|||
purgeStores = require('./purge'),
|
||||
{iconify} = require('../utils'),
|
||||
widgetManager = require('../managers/widgets'),
|
||||
stateManager = require('../managers/state'),
|
||||
parser = require('../parser')
|
||||
|
||||
var getObjectData = function(obj){
|
||||
|
|
@ -15,17 +16,18 @@ var getObjectData = function(obj){
|
|||
|
||||
}
|
||||
|
||||
var updateDom = function(container,data, remote, applyValue) {
|
||||
var updateDom = function(container,data, remote) {
|
||||
|
||||
// save state
|
||||
var scroll = $('#sidepanel').scrollTop(),
|
||||
oldWidgets = container[0].abstract.hashes || [container[0].abstract.hash],
|
||||
wState = {},
|
||||
wScroll = {}
|
||||
|
||||
stateManager.incrementQueue()
|
||||
|
||||
for (let h of oldWidgets) {
|
||||
if (widgetManager.widgets[h] && widgetManager.widgets[h].getValue) {
|
||||
wState[widgetManager.widgets[h].getProp('id')] = widgetManager.widgets[h].getValue()
|
||||
stateManager.push(widgetManager.widgets[h].getProp('id'), widgetManager.widgets[h].getValue())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -54,13 +56,8 @@ var updateDom = function(container,data, remote, applyValue) {
|
|||
|
||||
|
||||
// restore state
|
||||
if (applyValue) delete wState[newContainer[0].abstract.getProp('id')]
|
||||
stateManager.decrementQueue()
|
||||
|
||||
for (let id in wState) {
|
||||
for (let w of widgetManager.getWidgetById(id)) {
|
||||
if (w.setValue) w.setValue(wState[id])
|
||||
}
|
||||
}
|
||||
|
||||
// restore scroll states
|
||||
for (let id in wScroll) {
|
||||
|
|
|
|||
|
|
@ -8,6 +8,9 @@ var StateManager = class StateManager {
|
|||
|
||||
this.state = []
|
||||
|
||||
this.queue = {}
|
||||
this.queueCounter = 0
|
||||
|
||||
}
|
||||
|
||||
get() {
|
||||
|
|
@ -119,6 +122,30 @@ var StateManager = class StateManager {
|
|||
|
||||
}
|
||||
|
||||
push(id, value, options) {
|
||||
this.queue[id] = value
|
||||
if (this.queueCounter == 0) this.flush()
|
||||
}
|
||||
|
||||
flush(){
|
||||
for (let id in this.queue) {
|
||||
if (this.queue[id] !== undefined) {
|
||||
for (let w of widgetManager.getWidgetById(id)) {
|
||||
if (w.setValue) w.setValue(this.queue[id])
|
||||
}
|
||||
}
|
||||
}
|
||||
this.queue = {}
|
||||
}
|
||||
|
||||
incrementQueue() {
|
||||
this.queueCounter++
|
||||
}
|
||||
|
||||
decrementQueue() {
|
||||
this.queueCounter--
|
||||
if (this.queueCounter == 0) this.flush()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
var widgetManager = require('./managers/widgets'),
|
||||
stateManager = require('./managers/state'),
|
||||
{iconify} = require('./utils')
|
||||
|
||||
var Parser = class Parser {
|
||||
|
|
@ -151,6 +152,7 @@ var Parser = class Parser {
|
|||
// set widget's initial state
|
||||
if (widgetInner.getProp('value') !== '' && widgetInner.setValue) {
|
||||
widgetInner.setValue(widgetInner.getProp('value'), {sync:true})
|
||||
stateManager.push(widgetInner.getProp('id'), undefined)
|
||||
}
|
||||
|
||||
// Append the widget to its parent
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue