kweb-core icon indicating copy to clipboard operation
kweb-core copied to clipboard

DSL revamp

Open sanity opened this issue 3 years ago • 2 comments

I think we need to rethink the DSL to support this kind of usage:

 doc.body {
    section {
        classes("section")
        h1 {
            classes("title")
            text("What would you like to know?")
        }
        val textArea = textArea {
            classes("textarea")
            attr(
                "placeholder" to "Ask a question",
                "rows" to 10
            )
        }
        button {
            classes("button", "is-primary")
            text("Submit")
            parent.on(retrieveJs = textArea.valueJsExpression).click {
                val value = it.retrieved.jsonPrimitive.content
            }
        }
    }
}

The most notable architectural change will be merging the functionality of ElementCreator into Element.

sanity avatar Jun 18 '22 13:06 sanity

Wouldn't it make sense to leverage https://github.com/Kotlin/kotlinx.html here?

TreyBastian avatar Jun 22 '22 12:06 TreyBastian

It's a good question, but I don't think so because kotlinx isn't solving quite the same problem as kweb, which is doing more than just HTML generation.

Specifically, Kweb's render {} and KVar mechanisms are fairly fundamental and I don't think they would play nice with Kotlinx, also stuff like JavaScript event listeners.

That being said, I think kotlinx can provide useful inspiration for the DSL design.

sanity avatar Jun 22 '22 18:06 sanity

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar Oct 09 '22 15:10 github-actions[bot]

This is on the to-do list.

sanity avatar Oct 09 '22 15:10 sanity