Nim + Karax allow creating single-page applications without "magic":
https://nim-lang.org/araq/karax.html
Working example: https://forum.nim-lang.org/
https://nim-lang.org/araq/karax.html
Working example: https://forum.nim-lang.org/
Here is kerax:
var lines: seq[kstring] = @[]
proc createDom(): VNode =
result = buildHtml(tdiv):
button:
text "Say hello!"
proc onclick(ev: Event; n: VNode) =
lines.add "Hello simulated universe"
for x in lines:
tdiv:
text x
setRenderer createDom
Here is the equivalent in Kweb: fun main() {
Kweb(port = 2734) {
doc.body.new {
button().text("Say hello!").on.click {
println("Hello simulated universe")
}
}
}
}
This compiles and works. for x in lines:
tdiv:
text x
Whenever the DOM gets rerendered, it iterates over the the lines (or the "model" in general), and creates DOM elements from it. At least it looks very similar to React and Angular code, and they do exactly this.