sumi

Basics · Signals

Your first signal

A signal is a value that the UI watches. When it changes, sumi re-renders the parts of the template that read it — no manual redraw.

sumi.New(0) creates a signal holding 0. The template reads it with {count}. Right now the number never moves: nothing changes the signal.

Your turn

Make it react to the keyboard. Give the outer box an onkey handler and have that handler update the signal:

func handleKey(evt sumi.Event) {
    if evt.Kind == sumi.EventKey {
        count.Update(func(n int) int { return n + 1 })
    }
}

and on the template:

<div class="box" onkey="handleKey">

Press Run, then click into the terminal and press any key — the count climbs. Solve shows the finished version; Reset restores the start.

⌘↵ to run