wip
This commit is contained in:
parent
43ee890356
commit
5f7f33bb02
3 changed files with 33 additions and 8 deletions
|
|
@ -282,7 +282,7 @@ proc diff(newNode, oldNode: VNode; parent, current: Node; kxi: KaraxInstance): E
|
||||||
echo "newNode ", newNode.kind, " oldNode ", oldNode.kind, " eq ", eq(newNode, oldNode)
|
echo "newNode ", newNode.kind, " oldNode ", oldNode.kind, " eq ", eq(newNode, oldNode)
|
||||||
if oldNode.kind == VNodeKind.text:
|
if oldNode.kind == VNodeKind.text:
|
||||||
echo oldNode.text
|
echo oldNode.text
|
||||||
return
|
#return
|
||||||
#doAssert false, "overflow!"
|
#doAssert false, "overflow!"
|
||||||
inc kxi.recursion
|
inc kxi.recursion
|
||||||
result = eq(newNode, oldNode)
|
result = eq(newNode, oldNode)
|
||||||
|
|
@ -315,7 +315,7 @@ 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 j < current.len;
|
(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:
|
||||||
|
|
@ -327,7 +327,7 @@ proc diff(newNode, oldNode: VNode; parent, current: Node; kxi: KaraxInstance): E
|
||||||
of different:
|
of different:
|
||||||
# undo what 'diff' would have done:
|
# undo what 'diff' would have done:
|
||||||
kxi.patchLen = oldLen
|
kxi.patchLen = oldLen
|
||||||
#if result != different: result = r
|
if result != different: result = r
|
||||||
break
|
break
|
||||||
# compute common prefix:
|
# compute common prefix:
|
||||||
while commonPrefix < minLength:
|
while commonPrefix < minLength:
|
||||||
|
|
@ -341,7 +341,6 @@ proc diff(newNode, oldNode: VNode; parent, current: Node; kxi: KaraxInstance): E
|
||||||
eqAndUpdate(newNode, newPos, oldNode, oldPos, cstring"suffix"):
|
eqAndUpdate(newNode, newPos, oldNode, oldPos, cstring"suffix"):
|
||||||
dec oldPos
|
dec oldPos
|
||||||
dec newPos
|
dec newPos
|
||||||
echo "came here"
|
|
||||||
|
|
||||||
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:
|
||||||
|
|
|
||||||
|
|
@ -19,15 +19,18 @@ proc shortRepr(n: VNode): string =
|
||||||
for i in 0..<n.len:
|
for i in 0..<n.len:
|
||||||
result &= " " & shortRepr(n[i])
|
result &= " " & shortRepr(n[i])
|
||||||
|
|
||||||
|
var err = 0
|
||||||
|
|
||||||
proc doDiff(a, b: VNode; expected: varargs[string]) =
|
proc doDiff(a, b: VNode; expected: varargs[string]) =
|
||||||
discard diff(b, a, nil, vnodeToDom(a, kxi), kxi)
|
discard diff(b, a, nil, vnodeToDom(a, kxi), kxi)
|
||||||
for i in 0..<kxi.patchLen:
|
for i in 0..<kxi.patchLen:
|
||||||
let p = $kxi.patches[i].k & " " & shortRepr(kxi.patches[i].n)
|
let p = $kxi.patches[i].k & " " & shortRepr(kxi.patches[i].n)
|
||||||
echo "got ", p
|
|
||||||
if i >= expected.len:
|
if i >= expected.len:
|
||||||
echo "patches differ; expected nothing but got: ", p
|
echo "patches differ; expected nothing but got: ", p
|
||||||
|
inc err
|
||||||
elif p != expected[i]:
|
elif p != expected[i]:
|
||||||
echo "patches differ; expected ", expected[i], " but got: ", p
|
echo "patches differ; expected ", expected[i], " but got: ", p
|
||||||
|
inc err
|
||||||
#hasDom(kxi.currentTree)
|
#hasDom(kxi.currentTree)
|
||||||
kxi.patchLen = 0
|
kxi.patchLen = 0
|
||||||
|
|
||||||
|
|
@ -53,7 +56,24 @@ proc testInsert() =
|
||||||
li: text "A"
|
li: text "A"
|
||||||
li: text "B"
|
li: text "B"
|
||||||
li: text "C"
|
li: text "C"
|
||||||
doDiff(a, b, "pkInsert li B")
|
doDiff(a, b, "pkInsertBefore li B")
|
||||||
|
|
||||||
|
proc testInsert2() =
|
||||||
|
let a = buildHtml(tdiv):
|
||||||
|
tdiv:
|
||||||
|
tdiv:
|
||||||
|
ul:
|
||||||
|
li: text "A"
|
||||||
|
li: text "D"
|
||||||
|
let b = buildHtml(tdiv):
|
||||||
|
tdiv:
|
||||||
|
tdiv:
|
||||||
|
ul:
|
||||||
|
li: text "A"
|
||||||
|
li: text "B"
|
||||||
|
li: text "C"
|
||||||
|
li: text "D"
|
||||||
|
doDiff(a, b, "pkInsertBefore li B", "pkInsertBefore li C")
|
||||||
|
|
||||||
proc testDelete() =
|
proc testDelete() =
|
||||||
let a = buildHtml(tdiv):
|
let a = buildHtml(tdiv):
|
||||||
|
|
@ -70,6 +90,11 @@ proc testDelete() =
|
||||||
|
|
||||||
kxi = KaraxInstance(rootId: cstring"ROOT", renderer: proc (): VNode = discard)
|
kxi = KaraxInstance(rootId: cstring"ROOT", renderer: proc (): VNode = discard)
|
||||||
|
|
||||||
#testAppend()
|
testAppend()
|
||||||
testInsert()
|
testInsert()
|
||||||
#testDelete()
|
testInsert2()
|
||||||
|
testDelete()
|
||||||
|
if err == 0:
|
||||||
|
echo "Success"
|
||||||
|
else:
|
||||||
|
quit 1
|
||||||
|
|
|
||||||
|
|
@ -13,5 +13,6 @@ proc main =
|
||||||
exec("nim js examples/scrollapp/scrollapp.nim")
|
exec("nim js examples/scrollapp/scrollapp.nim")
|
||||||
exec("nim js examples/mediaplayer/playerapp.nim")
|
exec("nim js examples/mediaplayer/playerapp.nim")
|
||||||
exec("nim js examples/carousel/carousel.nim")
|
exec("nim js examples/carousel/carousel.nim")
|
||||||
|
exec("nim js -d:nodejs -r tests/difftest.nim")
|
||||||
|
|
||||||
main()
|
main()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue