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
|
const
|
||||||
StmtContext = ["kout", "inc", "echo", "dec", "!"]
|
StmtContext = ["kout", "inc", "echo", "dec", "!"]
|
||||||
|
SpecialAttrs = ["id", "class", "value", "key"]
|
||||||
|
|
||||||
proc getName(n: NimNode): string =
|
proc getName(n: NimNode): string =
|
||||||
case n.kind
|
case n.kind
|
||||||
|
|
@ -72,7 +73,7 @@ proc tcall2(n, tmpContext: NimNode): NimNode =
|
||||||
let key = getName x[0]
|
let key = getName x[0]
|
||||||
if key.startsWith("on"):
|
if key.startsWith("on"):
|
||||||
result.add newCall(!("set" & key), tmp, x[1])
|
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])
|
result.add newDotAsgn(tmp, key, x[1])
|
||||||
else:
|
else:
|
||||||
result.add newCall(bindSym"setAttr", tmp, newLit(key), x[1])
|
result.add newCall(bindSym"setAttr", tmp, newLit(key), x[1])
|
||||||
|
|
|
||||||
2
vdom.nim
2
vdom.nim
|
|
@ -31,8 +31,10 @@ const
|
||||||
|
|
||||||
type
|
type
|
||||||
EventHandler* = proc (ev: Event; target: VNode) {.closure.}
|
EventHandler* = proc (ev: Event; target: VNode) {.closure.}
|
||||||
|
VKey* = int
|
||||||
VNode* = ref object
|
VNode* = ref object
|
||||||
kind*: VNodeKind
|
kind*: VNodeKind
|
||||||
|
key*: VKey
|
||||||
id*, class*, text*: cstring
|
id*, class*, text*: cstring
|
||||||
kids: seq[VNode]
|
kids: seq[VNode]
|
||||||
# even index: key, odd index: value; done this way for memory efficiency:
|
# even index: key, odd index: value; done this way for memory efficiency:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue