I have solved the issue the karax way, to produce a new element and get it
render, I created each element using `VNodeKind`, to make the button "create"
the new element, I simply save the previously selected option `VNodeKind` and
createt with `newVNode`, wrapped in `buildHtml()`:
var
prev: VNodeKind
selected: VNodeKind
proc renderElementList*: VNode =
result = buildHtml(tdiv):
select(id="selector"):
proc onchange(e: Event, n: VNode) =
prev = parseEnum[VNodeKind]($n.value)
for element in low(VNodeKind) .. high(VNodeKind):
option(value = $element):
text $element
proc renderElement*(kind: VNodeKind): VNode =
result = buildHtml(newVNode(kind))
proc renderCreator*: VNode =
result = buildHtml(tdiv):
renderElementList()
button:
text "Create"
proc onclick(e: Event, n: VNode) =
selected = prev
echo $selected, " created"
button:
text "Edit"
proc onclick(e: Event, n: VNode) =
echo "Editing ", $selected
tdiv:
renderElement(selected)
Run
This solution is not genius but it does the job.