optimized diff algorithm further; fixed a stupid bug; cleaned up the tests

This commit is contained in:
Andreas Rumpf 2017-06-26 21:03:39 +02:00
commit 8a1424669f
5 changed files with 117 additions and 168 deletions

View file

@ -2,10 +2,19 @@
include "../src/karax"
import "../src/karaxdsl"
proc hasDom(n: Vnode) =
if n.kind in {VNodeKind.component, VNodeKind.vthunk, VNodeKind.dthunk}:
discard
else:
doAssert n.dom != nil
for i in 0..<n.len: hasDom(n[i])
proc doDiff(a, b: VNode) =
var patches: seq[Patch] = @[]
echo diff(nil, vnodeToDom(a, kxi), b, a, patches, kxi)
echo patches
var patches = newJSeq[Patch]()
echo diff(b, a, nil, vnodeToDom(a, kxi), patches)
for i in 0..<patches.len:
echo patches[i]
#hasDom(kxi.currentTree)
proc testAppend() =
let a = buildHtml(tdiv):
@ -31,7 +40,19 @@ proc testInsert() =
li: text "C"
doDiff(a, b)
proc testDelete() =
let a = buildHtml(tdiv):
ul:
li: text "A"
li: text "B"
li: text "C"
let b = buildHtml(tdiv):
ul:
discard
doDiff(a, b)
kxi = KaraxInstance(rootId: cstring"ROOT", renderer: proc (): VNode = discard)
#testAppend()
testAppend()
testInsert()
testDelete()