-
-
Notifications
You must be signed in to change notification settings - Fork 70
Description
JSX is the part of react that everybody likes. It's too bad that Kotlin can't handle angle braces in identifiers, but that's not something that can change soon. Nevertheless, it'd be great if KVision could provide a way to get closer to the JSX flow of "build a component and include it as a tag".
Right now, the dsl that KVision provides is nice and fluent:
root("kvapp") {
div("Hello world")
h2("my heading") {
color = Color.name(BLUE)
}
}
However, while I can make my own component with minimal boilerplate using Kotlin's init:
class MyComponent: Div() {
init {
h2("goodbye world")
}
}
...this does not work in KVision's dsl:
root("kvapp") {
div("Hello world")
h2("my heading") {
color = Color.name(BLUE)
}
MyComponent()
}
Instead, I have to call add(MyComponent()), which spoils the illusion of the dsl. I think it would be fine for components to have to implement a function in order to support this (rather than init, although init is nicer), but either way, would it be possible to think about a way to more seamlessly include components within the dsl in this manner? Maybe it could be done with receivers on a different entrypoint to root, so as to avoid breaking existing apps, e.g.:
kv("kvapp") {
div("hello world") {
MyComponent()
}
}