oldValue support

This commit is contained in:
dntzhang 2018-11-07 08:04:59 +08:00
parent 6784e18198
commit 656bb21ca2
2 changed files with 4 additions and 9 deletions

View File

@ -4,20 +4,14 @@ export function observe(target) {
target.observe = true
}
let preValue = null
let prePath = null
let preEle = null
export function proxyUpdate(ele) {
let timeout = null
ele.data = new JSONProxy(ele.data).observe(false, info => {
if (preValue === info.value && prePath === info.path && preEle === ele) {
if (info.oldValue === info.value) {
return
}
preValue = info.value
prePath = info.path
preEle = ele
clearTimeout(timeout)
timeout = setTimeout(() => {

View File

@ -57,7 +57,7 @@ const JSONPatcherProxy = (function() {
function setTrap(instance, target, key, newValue) {
const parentPath = findObjectPath(instance, target)
const destinationPropKey = parentPath + '/' + escapePathComponent(key)
const destinationPropKey = parentPath + '/' + escapePathComponent(key)
if (instance.proxifiedObjectsMap.has(newValue)) {
const newValueOriginalObject = instance.proxifiedObjectsMap.get(newValue)
@ -145,7 +145,8 @@ const JSONPatcherProxy = (function() {
}
}
operation.value = newValue
}
}
operation.oldValue = target[key]
const reflectionResult = Reflect.set(target, key, newValue)
instance.defaultCallback(operation)
return reflectionResult