Keywords · STATE

STATE

A STATE is a reactive cell — the one place a value actually changes.

Format

The grammar of a single STATE line:

STATE ::= "STATE" [ "LOCKED" ] type identifier "=" expression
type ::= name [ "(" type { " " type } ")" ]
expression ::= name { " " argument }
argument ::= name | constant
constant ::= string | integer | number
name ::= identifier { "." identifier }
identifier ::= letter { letter | digit }
A STATE keyword is followed by an optional LOCKED modifier, then the cell's type, its name, and an initial-value expression after the =.

Usage

A STATE keyword can only live inside a FUNCTION keyword.

Inside a FUNCTION

A state cell lives in a function body, the stable scope that owns it across re-renders.

FUNCTION UI.Element Counter
  STATE Maths.Integer count = 0
  STATE LOCKED Network.Web.Response responseState = null
A view function that owns a plain counter cell and a locked request cell.

Both cells live in the function's body, the stable scope that owns them across re-renders; reads see the current value, and a write arrives from a UI control or a REVERSE. The LOCKED cell marks a state that may be pending or carry an error, the form an in-flight request takes.

Can Contain

A STATE is a leaf: a type, a name, and an initial-value expression after the =. It opens no indented lines and no keyword lives inside it.

Modifiers

One inline modifier may sit before the type:

LOCKED

Marks the cell as one that may be pending or carry an error rather than always holding a settled value. It is a modifier, not a keyword of its own: it has no body, and it changes how the cell is read (its readers must handle the pending and error cases), not its structure. Use it for the result of an in-flight request such as a network call.

Targets

The same example, rendered to each target. The LOCKED cell becomes the same reactive state carrying a pending-or-error wrapper.

JavaScript

var count = Reactive.State(0);
var responseState = Reactive.StateLocked(null);   // LOCKED — pending or error

TypeScript

const count = Reactive.State<number>(0);
const responseState = Reactive.StateLocked<Network.Web.Response>(null);   // LOCKED

Dart

final count = Reactive.State<int>(0);
final responseState = Reactive.StateLocked<Network_Web_Response>(null);   // LOCKED

Swift

let count = Reactive.State<Int>(0)
let responseState = Reactive.StateLocked<Network.Web.Response>(nil)   // LOCKED

Go

count := Reactive.State[int](0)
responseState := Reactive.StateLocked[Network_Web_Response](nil)   // LOCKED

Rust

let count = Reactive::state::<i64>(0);
let response_state = Reactive::state_locked::<network::web::Response>(None);  // LOCKED

Zig

const count = Reactive.state(i64, 0);
const response_state = Reactive.state_locked(network.web.Response, null);  // LOCKED

JSON

["$", "count", "Maths.Integer", 0],
["$", "responseState", "Network.Web.Response", null, "LOCKED"]

Related

A derived value is a LET instead; writes flow back through a REVERSE, whose final SET pushes a value into a STATE. Stable identity for state is covered in the Reactive module. Back to the language.