diff --git a/src/karax.nim b/src/karax.nim index 85a126a..78395b3 100644 --- a/src/karax.nim +++ b/src/karax.nim @@ -135,6 +135,8 @@ proc equalsShallow(a, b: VNode): bool = if not equalsShallow(a[i], b[i]): return false if not sameAttrs(a, b): return false if a.class != b.class: return false + if a.track != 0 and b.track != 0: + if a.track != b.track: return false # XXX test event listeners here? return true @@ -191,10 +193,10 @@ proc updateElement(parent, current: Node, newNode, oldNode: VNode) = var left = 0 var rightNew = newLength - 1 var rightOld = oldLength - 1 - + while left <= min(rightNew, rightOld): var minRight = min(rightOld, rightNew) - + while left <= minRight and equalsTree(newNode[left], oldNode[left]): newNode[left] = oldNode[left] @@ -205,7 +207,7 @@ proc updateElement(parent, current: Node, newNode, oldNode: VNode) = newNode[rightNew] = oldNode[rightOld] dec rightOld dec rightNew - + minRight = min(rightOld, rightNew) if left <= minRight: updateElement(current, oldNode[left].dom, newNode[left], oldNode[left]) @@ -215,7 +217,7 @@ proc updateElement(parent, current: Node, newNode, oldNode: VNode) = updateElement(current, oldNode[rightOld].dom, newNode[rightNew], oldNode[rightOld]) dec rightNew dec rightOld - + var posNextElem = rightOld + 1 var isPushBack = posNextElem == oldLength while left <= rightNew: diff --git a/src/karaxdsl.nim b/src/karaxdsl.nim index 5ba525a..5553d8f 100644 --- a/src/karaxdsl.nim +++ b/src/karaxdsl.nim @@ -4,7 +4,7 @@ from strutils import startsWith, toLowerAscii const StmtContext = ["kout", "inc", "echo", "dec", "!"] - SpecialAttrs = ["id", "class", "value", "key"] + SpecialAttrs = ["id", "class", "value", "key", "track"] proc getName(n: NimNode): string = case n.kind diff --git a/src/vdom.nim b/src/vdom.nim index 48574de..77b3c89 100644 --- a/src/vdom.nim +++ b/src/vdom.nim @@ -109,6 +109,7 @@ type when false: hash*: Hash validHash*: bool + track*: int dom*: Node ## the attached real DOM node. Can be 'nil' if the virtual node ## is not part of the virtual DOM anymore. @@ -143,6 +144,8 @@ proc eq*(a, b: VNode): bool = if a.attrs.len != b.attrs.len: return false for i in 0..