added getVNodeById() for easier form handling
This commit is contained in:
parent
45951c96a4
commit
312eb5180a
1 changed files with 19 additions and 2 deletions
|
|
@ -38,6 +38,7 @@ type
|
||||||
runCount: int
|
runCount: int
|
||||||
components: seq[ComponentPair]
|
components: seq[ComponentPair]
|
||||||
surpressRedraws*: bool
|
surpressRedraws*: bool
|
||||||
|
byId: JDict[cstring, VNode]
|
||||||
when defined(stats):
|
when defined(stats):
|
||||||
recursion: int
|
recursion: int
|
||||||
|
|
||||||
|
|
@ -112,12 +113,19 @@ template detach(n: VNode) =
|
||||||
|
|
||||||
template attach(n: VNode) =
|
template attach(n: VNode) =
|
||||||
n.dom = result
|
n.dom = result
|
||||||
|
if n.id != nil: kxi.byId[n.id] = n
|
||||||
|
|
||||||
proc applyEvents(n: VNode; kxi: KaraxInstance) =
|
proc applyEvents(n: VNode; kxi: KaraxInstance) =
|
||||||
let dest = n.dom
|
let dest = n.dom
|
||||||
for i in 0..<len(n.events):
|
for i in 0..<len(n.events):
|
||||||
n.events[i][2] = wrapEvent(dest, n, n.events[i][0], n.events[i][1])
|
n.events[i][2] = wrapEvent(dest, n, n.events[i][0], n.events[i][1])
|
||||||
|
|
||||||
|
proc getVNodeById*(id: cstring; kxi: KaraxInstance = kxi): VNode =
|
||||||
|
## Get the VNode that was marked with ``id``. Returns ``nil``
|
||||||
|
## if no node exists.
|
||||||
|
if kxi.byId.contains(id):
|
||||||
|
result = kxi.byId[id]
|
||||||
|
|
||||||
proc vnodeToDom*(n: VNode; kxi: KaraxInstance): Node =
|
proc vnodeToDom*(n: VNode; kxi: KaraxInstance): Node =
|
||||||
if n.kind == VNodeKind.text:
|
if n.kind == VNodeKind.text:
|
||||||
result = document.createTextNode(n.text)
|
result = document.createTextNode(n.text)
|
||||||
|
|
@ -331,6 +339,7 @@ proc applyPatch(kxi: KaraxInstance) =
|
||||||
p.parent.insertBefore(nn, p.current)
|
p.parent.insertBefore(nn, p.current)
|
||||||
of pkDetach:
|
of pkDetach:
|
||||||
let n = p.n
|
let n = p.n
|
||||||
|
if n.id != nil: kxi.byId.del(n.id)
|
||||||
if n.kind == VNodeKind.component:
|
if n.kind == VNodeKind.component:
|
||||||
let x = VComponent(n)
|
let x = VComponent(n)
|
||||||
if x.onDetachImpl != nil: x.onDetachImpl(x)
|
if x.onDetachImpl != nil: x.onDetachImpl(x)
|
||||||
|
|
@ -615,7 +624,9 @@ proc setRenderer*(renderer: proc (): VNode, root: cstring = "ROOT",
|
||||||
postRenderCallback: clientPostRenderCallback,
|
postRenderCallback: clientPostRenderCallback,
|
||||||
patches: newSeq[Patch](60),
|
patches: newSeq[Patch](60),
|
||||||
patchesV: newSeq[PatchV](30),
|
patchesV: newSeq[PatchV](30),
|
||||||
components: @[])
|
components: @[],
|
||||||
|
surpressRedraws: false,
|
||||||
|
byId: newJDict[cstring, VNode]())
|
||||||
kxi = result
|
kxi = result
|
||||||
window.onload = init
|
window.onload = init
|
||||||
|
|
||||||
|
|
@ -627,7 +638,8 @@ proc setInitializer*(renderer: proc (): VNode, root: cstring = "ROOT",
|
||||||
patches: newSeq[Patch](60),
|
patches: newSeq[Patch](60),
|
||||||
patchesV: newSeq[PatchV](30),
|
patchesV: newSeq[PatchV](30),
|
||||||
components: @[],
|
components: @[],
|
||||||
surpressRedraws: true)
|
surpressRedraws: true,
|
||||||
|
byId: newJDict[cstring, VNode]())
|
||||||
kxi = result
|
kxi = result
|
||||||
window.onload = init
|
window.onload = init
|
||||||
|
|
||||||
|
|
@ -694,3 +706,8 @@ proc runLater*(action: proc(); later = 400): Timeout {.discardable.} =
|
||||||
action()
|
action()
|
||||||
redraw()
|
redraw()
|
||||||
result = setTimeout(wrapper, later)
|
result = setTimeout(wrapper, later)
|
||||||
|
|
||||||
|
proc setInputText*(n: VNode; s: cstring) =
|
||||||
|
## Sets the text of input elements.
|
||||||
|
n.text = s
|
||||||
|
if n.dom != nil: n.dom.value = s
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue