Skip to content
Brew

Example — Counter

A minimal interactive widget: one integer property, two actions, one template.

package app.brew
import org.konaframework.brew.Component
class Counter : Component() {
var count = 0
fun mount(start: Int = 0) {
count = start
}
fun increment() { count++ }
fun decrement() { count-- }
fun reset() { count = 0 }
override fun template() = """
<div class="counter">
<button type="button" wire:click="decrement" wire:loading.attr="disabled">−</button>
<span wire:text="count"></span>
<button type="button" wire:click="increment" wire:loading.attr="disabled">+</button>
<button type="button" wire:click="reset">Reset</button>
<span wire:loading wire:target="increment,decrement">…</span>
</div>
""".trimIndent()
}
<brew:counter :start="3" />
Brew.test(Counter::class.java, mapOf("start" to 3))
.assertSet("count", 3)
.call("increment")
.assertSet("count", 4)
.call("reset")
.assertSet("count", 0)

The repo samples (samples/brew-kotlin, samples/brew-java) ship a similar counter on the welcome page.