vdom: addd support for special 'key' field

This commit is contained in:
Andreas Rumpf 2017-04-08 10:07:45 +02:00
commit b6d3d7821b
2 changed files with 4 additions and 1 deletions

View file

@ -4,6 +4,7 @@ from strutils import startsWith, toLowerAscii
const
StmtContext = ["kout", "inc", "echo", "dec", "!"]
SpecialAttrs = ["id", "class", "value", "key"]
proc getName(n: NimNode): string =
case n.kind
@ -72,7 +73,7 @@ proc tcall2(n, tmpContext: NimNode): NimNode =
let key = getName x[0]
if key.startsWith("on"):
result.add newCall(!("set" & key), tmp, x[1])
elif key == "id" or key == "class" or key == "value":
elif key in SpecialAttrs:
result.add newDotAsgn(tmp, key, x[1])
else:
result.add newCall(bindSym"setAttr", tmp, newLit(key), x[1])

View file

@ -31,8 +31,10 @@ const
type
EventHandler* = proc (ev: Event; target: VNode) {.closure.}
VKey* = int
VNode* = ref object
kind*: VNodeKind
key*: VKey
id*, class*, text*: cstring
kids: seq[VNode]
# even index: key, odd index: value; done this way for memory efficiency: