code cleanups
This commit is contained in:
parent
7779560b6b
commit
907c372c27
1 changed files with 13 additions and 27 deletions
|
|
@ -339,14 +339,12 @@ proc diff(newNode, oldNode: VNode; parent, current: Node; kxi: KaraxInstance): E
|
||||||
let r = if isSpecial:
|
let r = if isSpecial:
|
||||||
diff(a[i], b[j], parent, current, kxi)
|
diff(a[i], b[j], parent, current, kxi)
|
||||||
else:
|
else:
|
||||||
(assert same(b, current); #(j < current.len, "j: " & $j & " len " & $current.len);
|
diff(a[i], b[j], current, current.childNodes[j], kxi)
|
||||||
diff(a[i], b[j], current, current.childNodes[j], kxi))
|
|
||||||
case r
|
case r
|
||||||
of identical, changed, similar:
|
of identical, changed, similar:
|
||||||
a[i] = b[j]
|
a[i] = b[j]
|
||||||
action
|
action
|
||||||
of usenewNode:
|
of usenewNode:
|
||||||
#b[j] = a[i]
|
|
||||||
kxi.addPatchV(b, j, a[i])
|
kxi.addPatchV(b, j, a[i])
|
||||||
action
|
action
|
||||||
of different:
|
of different:
|
||||||
|
|
@ -370,16 +368,12 @@ 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:
|
||||||
when false:
|
|
||||||
for i in commonPrefix..pos-1:
|
|
||||||
detach(oldNode[i])
|
|
||||||
kxi.addPatch(pkReplace, current, current.childNodes[i], newNode[i])
|
|
||||||
when true:
|
|
||||||
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])
|
||||||
elif r != different:
|
elif r != different:
|
||||||
newNode[i] = oldNode[i]
|
newNode[i] = oldNode[i]
|
||||||
#else:
|
#else:
|
||||||
|
|
@ -389,25 +383,17 @@ proc diff(newNode, oldNode: VNode; parent, current: Node; kxi: KaraxInstance): E
|
||||||
for i in pos..newPos:
|
for i in pos..newPos:
|
||||||
kxi.addPatch(pkAppend, current, nil, newNode[i])
|
kxi.addPatch(pkAppend, current, nil, newNode[i])
|
||||||
result = usenewNode
|
result = usenewNode
|
||||||
#result = different
|
|
||||||
else:
|
else:
|
||||||
let before = current.childNodes[oldPos + 1]
|
let before = current.childNodes[oldPos + 1]
|
||||||
for i in pos..newPos:
|
for i in pos..newPos:
|
||||||
kxi.addPatch(pkInsertBefore, current, before, newNode[i])
|
kxi.addPatch(pkInsertBefore, current, before, newNode[i])
|
||||||
result = usenewNode
|
result = usenewNode
|
||||||
#result = different
|
|
||||||
# XXX call 'attach' here?
|
# XXX call 'attach' here?
|
||||||
for i in pos..oldPos:
|
for i in pos..oldPos:
|
||||||
detach(oldNode[i])
|
detach(oldNode[i])
|
||||||
#doAssert i < current.childNodes.len
|
#doAssert i < current.childNodes.len
|
||||||
kxi.addPatch(pkRemove, current, current.childNodes[i], nil)
|
kxi.addPatch(pkRemove, current, current.childNodes[i], nil)
|
||||||
result = usenewNode #different
|
result = usenewNode
|
||||||
# after the applied patch, conceptually the nodes are identical, so
|
|
||||||
# no further search is required. 'changed' needs to be propagated
|
|
||||||
# for the component system to work. 'similar' was transformed into
|
|
||||||
# identical too:
|
|
||||||
#if result == different or result == similar:
|
|
||||||
# result = identical
|
|
||||||
|
|
||||||
of changed:
|
of changed:
|
||||||
assert oldNode.kind == VNodeKind.component
|
assert oldNode.kind == VNodeKind.component
|
||||||
|
|
@ -456,7 +442,7 @@ proc dodraw(kxi: KaraxInstance) =
|
||||||
#kout cstring"patch len ", patches.len
|
#kout cstring"patch len ", patches.len
|
||||||
apply(kxi)
|
apply(kxi)
|
||||||
kxi.currentTree = newtree
|
kxi.currentTree = newtree
|
||||||
#doAssert same(kxi.currentTree, document.getElementById(kxi.rootId))
|
doAssert same(kxi.currentTree, document.getElementById(kxi.rootId))
|
||||||
|
|
||||||
if not kxi.postRenderCallback.isNil:
|
if not kxi.postRenderCallback.isNil:
|
||||||
kxi.postRenderCallback()
|
kxi.postRenderCallback()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue