DOM diff problem: hashing

This commit is contained in:
Roman Vishnevskii 2017-04-08 18:58:08 +07:00
commit c065b8f709
3 changed files with 79 additions and 13 deletions

View file

@ -38,6 +38,8 @@ type
# even index: key, odd index: value; done this way for memory efficiency:
attrs: seq[cstring]
events*: seq[(EventKind, EventHandler)]
hash*: uint64
validHash*: bool
proc value*(n: VNode): cstring = n.text
proc `value=`*(n: VNode; v: cstring) = n.text = v
@ -129,6 +131,24 @@ proc toString*(n: VNode; result: var string; indent: int) =
for i in 1..indent: result.add ' '
result.add "\L</" & $n.kind & ">"
proc getVNodeData*(n: VNode): string =
result.add "<" & $n.kind
toStringAttr(id)
toStringAttr(class)
#for k, v in attrs(n):
# result.add " " & $k & " = " & $v
result.add ">"
if n.kind == VNodeKind.text:
result.add n.text
else:
if n.text != nil:
result.add " value = "
result.add n.text
result.add "</" & $n.kind & ">"
proc `$`*(n: VNode): cstring =
var res = ""
toString(n, res, 0)