sumi

Basics · Signals

Derived values

A derived value is one signal computed from others. sumi.From builds one: you give it a function, it runs the function once to discover which signals the function read, and re-runs whenever any of those change. The result is read-only — there is no Set on a derived.

This counter climbs toward a goal of ten. We want to show how many are left without storing a second number by hand — goal - count should always be right, so it belongs in a derived.

Your turn

Add the derived. In <script>, after count, declare:

remaining := sumi.From(func() int { return goal - count.Get() })

Then display it in the template with {remaining}. Note the .Get() inside From — the function body is ordinary Go, so you read the signal explicitly there.

Press Run and count up; remaining falls as count rises. Solve shows the finished version; Reset restores the start.

⌘↵ to run