vdom: addd support for special 'key' field
This commit is contained in:
parent
11e4f355e7
commit
b6d3d7821b
2 changed files with 4 additions and 1 deletions
|
|
@ -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])
|
||||
|
|
|
|||
2
vdom.nim
2
vdom.nim
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue