test nested components (still buggy)
This commit is contained in:
parent
fe7d72fa4e
commit
c987323dba
1 changed files with 18 additions and 2 deletions
|
|
@ -34,21 +34,37 @@ proc render(x: VComponent): VNode =
|
||||||
|
|
||||||
proc flip(ev: Event; n: VNode) =
|
proc flip(ev: Event; n: VNode) =
|
||||||
self.isActive = not self.isActive
|
self.isActive = not self.isActive
|
||||||
|
kout cstring"onflip", n.value
|
||||||
markDirty(self)
|
markDirty(self)
|
||||||
|
|
||||||
proc onchanged(ev: Event; n: VNode) =
|
proc onchanged(ev: Event; n: VNode) =
|
||||||
kout cstring"onchanged", n.value
|
kout cstring"onchanged", n.value
|
||||||
|
|
||||||
result = buildHtml(tdiv(style=style)):
|
result = buildHtml(tdiv(style=style)):
|
||||||
textarea(style=inputStyle, value=self.value, onblur=flip, onfocus=flip, onkeyup=onchanged)
|
input(style=inputStyle, value=self.value, onblur=flip, onfocus=flip, onkeyup=onchanged)
|
||||||
|
|
||||||
proc newTextInput*(style: VStyle = VStyle(); value: cstring = cstring""): TextInput =
|
proc newTextInput*(style: VStyle = VStyle(); value: cstring = cstring""): TextInput =
|
||||||
result = newComponent(TextInput, render)
|
result = newComponent(TextInput, render)
|
||||||
result.style = style
|
result.style = style
|
||||||
result.value = value
|
result.value = value
|
||||||
|
|
||||||
|
type
|
||||||
|
Combined = ref object of VComponent
|
||||||
|
a, b: TextInput
|
||||||
|
|
||||||
|
proc renderComb(self: VComponent): VNode =
|
||||||
|
let self = Combined(self)
|
||||||
|
result = buildHtml(tdiv(style=self.style)):
|
||||||
|
self.a
|
||||||
|
self.b
|
||||||
|
|
||||||
|
proc newCombined*(style: VStyle = VStyle()): Combined =
|
||||||
|
result = newComponent(Combined, renderComb)
|
||||||
|
result.a = newTextInput(style, "AAA")
|
||||||
|
result.b = newTextInput(style, "BBB")
|
||||||
|
|
||||||
proc createDom(): VNode =
|
proc createDom(): VNode =
|
||||||
result = buildHtml(tdiv):
|
result = buildHtml(tdiv):
|
||||||
newTextInput(value=cstring"test")
|
newCombined()
|
||||||
|
|
||||||
setRenderer createDom
|
setRenderer createDom
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue