Skip to main content

Track

The track module gives you a compact reactive state primitive inspired by signal-style APIs. A state returns a getter and setter. Effects subscribe to one or more getters and run when a subscribed state changes.

State and effect

Effects are dependency based. Updating a different state will not trigger an effect unless that state’s getter is included in the dependency list.

Tables and functional updates

When the initial value, returned value, or next value is a table, sure_lib deep-clones it at the state boundary. This prevents accidental mutation of stored state through an old table reference.
Setters also accept a function. The function receives a copied current value and returns the next value.

API

function
required
Creates a reactive state. stateName is used internally to connect dependencies to effects.
function
Call the getter with no arguments to read the current value: amount().
function
Call the setter with a new value or a function (currentValue) -> nextValue to update state and notify dependent effects.
function
required
Registers a callback that runs when any getter in dependencies changes.
Use track for local derived behavior inside one resource. It is not a network replication layer.