Kotlin plugin for Svelte-like reactivity


I’ve reached a working proof-of-concept for a Kotlin compiler plugin that brings Svelte-like reactivity to Kotlin.

A short example (this one is for JavaScript, JVM works as well):

fun main() {
  rui(RuiDOMAdapter()) {
    var counter = 0
    Button("Counter: $counter") { counter++ }
    Text("You've clicked $counter times.")

This works as you would expect: shows a button, when you click on it, the UI updates automatically.

You can check out the current status here: GitHub - spxbhuhb/rui: Kotlin Reactive UI inspired by Svelte.

There are two major points not implemented yet: for loops and higher order functions. The first is a kinda simple, I’ve already written half of it. The second is pretty hard but I already have plans about how to implement.

Other major pain point is the IDE feedback (errors) which does not exists at the moment (the compiler complains). I’ll work on that once the loop and higher-order is ready.

I be happy to get any feedback from the community. Opinions, comments, ideas.


Looks like a nice and interesting project, great work!!!

Curious if it could also be made to work with Kotlin/WASM, then it would be a very high performing solution for complex web apps.

Assuming WASM uses the IR compiler backend (I think it does, but I’m not 100% sure) the plugin itself should work out-of-the-box.

That said, to use it with WASM we would need an adapter and a bridge class. These are quite simple to write and provide a few methods to call the underlying UI. For example: create a node, delete a node, etc.

I’m also curious, I might try it on the weekend. :wink:

1 Like