diff: clean diff parsing
This commit is contained in:
parent
9e7f089828
commit
4adb92974a
3 changed files with 12 additions and 10 deletions
|
|
@ -4,8 +4,7 @@ module.exports = {
|
|||
|
||||
diffToWidget: function(widget, diff) {
|
||||
|
||||
var props = Object.keys(diff),
|
||||
children = diff.tabs ||diff.widgets
|
||||
var children = diff.tabs ||diff.widgets
|
||||
|
||||
if (children) {
|
||||
var childrenKeys = Object.keys(children),
|
||||
|
|
@ -20,7 +19,7 @@ module.exports = {
|
|||
changedChildren.length !== 1
|
||||
|
||||
) {
|
||||
return [widget, props]
|
||||
return [widget, diff]
|
||||
}
|
||||
|
||||
return module.exports.diffToWidget(widget.children[changedChildren[0]], children[changedChildren[0]])
|
||||
|
|
|
|||
|
|
@ -812,13 +812,13 @@ var Editor = class Editor {
|
|||
|
||||
updateWidgetFromPatch(patch, indexes) {
|
||||
|
||||
var [widget, props] = diffToWidget(widgetManager.getWidgetById('root')[0], patch[0]),
|
||||
var [widget, patch] = diffToWidget(widgetManager.getWidgetById('root')[0], patch[0]),
|
||||
options = {}
|
||||
|
||||
if (indexes) {
|
||||
options = {...indexes}
|
||||
} else {
|
||||
options.changedProps = props
|
||||
options.changedProps = Object.keys(patch)
|
||||
options.reuseChildren = false
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ var Container = require('../common/container'),
|
|||
resize = require('../../events/resize'),
|
||||
parser = require('../../parser'),
|
||||
{deepCopy, deepEqual} = require('../../utils'),
|
||||
diff = require('jsondiffpatch')
|
||||
{diff, diffToWidget} = require('../../editor/diff')
|
||||
|
||||
var excludedCloneClasses = ['widget', 'absolute-position', 'ui-resizable', 'ui-draggable', 'not-editable']
|
||||
|
||||
|
|
@ -41,7 +41,7 @@ class Clone extends Container {
|
|||
this.bindTarget(this.getCloneTarget())
|
||||
if (this.cloneTarget) this.createClone(true)
|
||||
|
||||
// global listenner to catch cloneTarget's creation if no target is locked
|
||||
// global listener to catch cloneTarget's creation if no target is locked
|
||||
widgetManager.on('widget-created', (e)=>{
|
||||
|
||||
if (this.cloneTarget) return
|
||||
|
|
@ -203,23 +203,26 @@ class Clone extends Container {
|
|||
childrenChanged = false
|
||||
|
||||
var delta = diff.diff(clone.props, data) || {},
|
||||
[widget, props] = diffToWidget(clone, delta),
|
||||
changedProps = Object.keys(delta)
|
||||
|
||||
clone.props = data
|
||||
|
||||
if (changedProps.some(x => !clone.constructor.dynamicProps.includes(x))) {
|
||||
clone.props = data
|
||||
console.log(widget, props)
|
||||
if (props.some(x => !widget.constructor.dynamicProps.includes(x))) {
|
||||
|
||||
clone.reCreateWidget({reuseChildren: false})
|
||||
this.updateContainer(false)
|
||||
|
||||
} else {
|
||||
|
||||
clone.updateProps(changedProps, this)
|
||||
widget.updateProps(props, this)
|
||||
this.updateContainer(true)
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
this.cloneLock = false
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue