editor: resolve conflict between state preservation and potential "value" prop update by queuing the latters and check for changes when edition is performed (->flush)
This commit is contained in:
parent
3d3b7e1568
commit
27b1ede452
3 changed files with 38 additions and 12 deletions
|
|
@ -11,13 +11,19 @@ var updateWidget = function(widget, options = {}) {
|
|||
var sidepanel = DOM.get('#sidepanel')[0],
|
||||
scroll = sidepanel.scrollTop,
|
||||
oldWidgets = widget.childrenHashes.concat(widget.hash),
|
||||
oldValueProps = {},
|
||||
wScroll = {}
|
||||
|
||||
stateManager.incrementQueue()
|
||||
|
||||
for (let h of oldWidgets) {
|
||||
if (widgetManager.widgets[h] && widgetManager.widgets[h].getValue) {
|
||||
stateManager.push(widgetManager.widgets[h].getProp('id'), widgetManager.widgets[h].getValue())
|
||||
if (widgetManager.widgets[h]) {
|
||||
let id = widgetManager.widgets[h].getProp('id'),
|
||||
value = widgetManager.widgets[h].getValue(),
|
||||
valueProp = widgetManager.widgets[h].getProp('value')
|
||||
|
||||
stateManager.pushValueState(id, value)
|
||||
if (valueProp !== '' && valueProp !== undefined) stateManager.pushValueOldProp(id, valueProp)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,9 @@ var StateManager = class StateManager {
|
|||
|
||||
this.state = []
|
||||
|
||||
this.queue = {}
|
||||
this.valueStateQueue = {}
|
||||
this.valueOldPropQueue = {}
|
||||
this.valueNewPropQueue = {}
|
||||
this.queueCounter = 0
|
||||
|
||||
}
|
||||
|
|
@ -121,20 +123,39 @@ var StateManager = class StateManager {
|
|||
|
||||
}
|
||||
|
||||
push(id, value, options) {
|
||||
this.queue[id] = value
|
||||
pushValueState(id, value) {
|
||||
this.valueStateQueue[id] = value
|
||||
}
|
||||
|
||||
pushValueOldProp(id, value) {
|
||||
this.valueOldPropQueue[id] = value
|
||||
}
|
||||
|
||||
pushValueNewProp(id, value) {
|
||||
this.valueNewPropQueue[id] = value
|
||||
if (this.queueCounter == 0) this.flush()
|
||||
}
|
||||
|
||||
flush(){
|
||||
for (let id in this.queue) {
|
||||
if (this.queue[id] !== undefined) {
|
||||
for (let id in this.valueStateQueue) {
|
||||
if (this.valueStateQueue[id] !== undefined) {
|
||||
for (let w of widgetManager.getWidgetById(id)) {
|
||||
if (w.setValue) w.setValue(this.queue[id])
|
||||
if (w.setValue) w.setValue(this.valueStateQueue[id])
|
||||
}
|
||||
}
|
||||
}
|
||||
this.queue = {}
|
||||
|
||||
for (let id in this.valueNewPropQueue) {
|
||||
if (this.valueNewPropQueue[id] != this.valueOldPropQueue[id]) {
|
||||
for (let w of widgetManager.getWidgetById(id)) {
|
||||
if (w.setValue) w.setValue(this.valueNewPropQueue[id], {sync: true})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.valueStateQueue = {}
|
||||
this.valueOldPropQueue = {}
|
||||
this.valueNewPropQueue = {}
|
||||
}
|
||||
|
||||
incrementQueue() {
|
||||
|
|
|
|||
|
|
@ -146,9 +146,8 @@ var Parser = class Parser {
|
|||
if (widgetInner.getProp('color') && widgetInner.getProp('color')!='auto') widgetContainer.style.setProperty('--color-custom',widgetInner.getProp('color'))
|
||||
|
||||
// set widget's initial state
|
||||
if (widgetInner.getProp('value') !== '' && widgetInner.setValue) {
|
||||
widgetInner.setValue(widgetInner.getProp('value'), {sync:true})
|
||||
stateManager.push(widgetInner.getProp('id'), undefined)
|
||||
if (widgetInner.getProp('value') !== '') {
|
||||
stateManager.pushValueNewProp(widgetInner.getProp('id'), widgetInner.getProp('value'))
|
||||
}
|
||||
|
||||
// Append the widget to its parent
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue