added track field

This commit is contained in:
Andreas Rumpf 2017-05-04 09:41:11 +02:00
commit 8195ecf61b
4 changed files with 13 additions and 7 deletions

View file

@ -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:

View file

@ -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

View file

@ -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..<a.attrs.len:
if a.attrs[i] != b.attrs[i]: return false
if a.track != 0 and b.track != 0:
if a.track != b.track: return false
result = true
proc setAttr*(n: VNode; key: cstring; val: cstring = "") =