Playground
SoonWhat the Lithe compiler wrote for Counter.lithe when this site was built. Compiling your own edits is coming soon.
@file:Suppress("USELESS_CAST", "UNCHECKED_CAST", "UNCHECKED_CAST_TO_EXTERNAL_INTERFACE", "UNUSED_VARIABLE", "NAME_SHADOWING", "REDUNDANT_ELSE_IN_WHEN")
import io.github.ayfri.lithe.Choose
import io.github.ayfri.lithe.Element
import io.github.ayfri.lithe.StaticHtml
import io.github.ayfri.lithe.Text
import io.github.ayfri.lithe.Ui
import io.github.ayfri.lithe.derived
import io.github.ayfri.lithe.dom.*
import io.github.ayfri.lithe.getValue
import io.github.ayfri.lithe.prop
import io.github.ayfri.lithe.state
import io.github.ayfri.lithe.textOf
context(_: Ui)
fun App(
step: (() -> Int)? = null,
) {
val step: Int by prop(step) { 1 }
var count by state(0)
val doubled by derived { count * 2 }
Element("div", {
attr("class", "demo")
}) {
Element("button", {
attr("class", "counter l-17pz0t5")
attr("type", "button")
on("click") {
count += step
}
}) {
Text { "${textOf(count)} × 2 = ${textOf(doubled)}" }
}
Text(" ")
Choose({
if (count > 10) 0 else -1
}) {
StaticHtml("<p>That's a lot of clicks.</p>")
}
}
}
- No errors and no warnings.
The file compiles on this site's server as you type. Run also builds it with Kotlin/JS and runs it in a sandboxed frame.
It stands alone: the runtime and the browser are there, other components and this site's API aren't. The HTML tab is what the browser builds, since a server render would run anyone's code there.