make todoapp work again

This commit is contained in:
Andreas Rumpf 2017-07-07 17:37:29 +02:00
commit dc88eeaae3

View file

@ -311,7 +311,6 @@ proc diff(newNode, oldNode: VNode; parent, current: Node; kxi: KaraxInstance): E
#doAssert false, "overflow!" #doAssert false, "overflow!"
inc kxi.recursion inc kxi.recursion
result = eq(newNode, oldNode) result = eq(newNode, oldNode)
assert(same(oldNode, current))
case result case result
of identical, similar: of identical, similar:
newNode.dom = oldNode.dom newNode.dom = oldNode.dom
@ -350,6 +349,8 @@ proc diff(newNode, oldNode: VNode; parent, current: Node; kxi: KaraxInstance): E
of usenewNode: of usenewNode:
kxi.addPatchV(b, j, a[i]) kxi.addPatchV(b, j, a[i])
action action
# unfortunately, we need to propagate the changes upwards:
result = useNewNode
of different: of different:
# undo what 'diff' would have done: # undo what 'diff' would have done:
kxi.patchLen = oldLen kxi.patchLen = oldLen
@ -372,8 +373,7 @@ proc diff(newNode, oldNode: VNode; parent, current: Node; kxi: KaraxInstance): E
let pos = min(oldPos, newPos) + 1 let pos = min(oldPos, newPos) + 1
# now the different children are in commonPrefix .. pos - 1: # now the different children are in commonPrefix .. pos - 1:
for i in commonPrefix..pos-1: for i in commonPrefix..pos-1:
let r = diff(newNode[i], oldNode[i], current, current.childNodes[i], let r = diff(newNode[i], oldNode[i], current, current.childNodes[i], kxi)
kxi)
if r == usenewNode: if r == usenewNode:
#oldNode[i] = newNode[i] #oldNode[i] = newNode[i]
kxi.addPatchV(oldNode, i, newNode[i]) kxi.addPatchV(oldNode, i, newNode[i])