David Herman
07/18/2023, 12:11 AMSimpleGrid(numColumns(10)) {
repeat(30) {
Box(Modifier.size(50.px).backgroundColor(Color.Companion.rgb(Random.nextInt())))
}
}
(See attached image)
0.13.9
The latest release introduces persistent client-server connections (think WebSockets) via a feature called API streams (a new companion to API routes, the way you declare REST endpoints in Kobweb)
Declaring and using streams will likely be a little more involved in practice, but for the simple case of just sending text back and forth, you're looking at some nice one-liners. Here, the following code sends text to the server which then immediately gets echoed back to the client (and logged to the console):
// Backend
val echo = ApiStream { ctx -> ctx.stream.send(ctx.text) }
// Frontend
val echoStream = rememberApiStream("echo") { ctx -> console.log("Echoed: ${ctx.text}") }
// later:
echoStream.send("Hello!")
A Kobweb power-user put together a chess playground is less than two days (see attached video).
Tons of potential in this feature! Hope the community has fun with it.