Skip to content

Store and show state

Document state is the data a micro-app starts with and changes as people use it: a flag that a step is done, the text someone typed, which option they picked.

Open the inspector’s State tab and stay on Values. The panel is a tree of ui.state: each pointer is a row you can select, nested plain objects show a record badge, and leaves are editable in place.

To add a top-level key, type a key and a value and press Add (or Enter):

  • The value box accepts JSON — false, 12, "text", {"a": 1} — and falls back to plain text when it is not valid JSON. Leave it empty for an empty text value.
  • A / in the key nests it: steps/laptop with false creates { "steps": { "laptop": false } }.
  • Edit a leaf in place and leave the field to apply it; the trash icon removes the key.
  • On a record, nested key plus Add field (or Enter) adds a child seeded as empty text.

Select a path (Select {pointer}) to see Used by: the Text, Input, condition and event sites that read or write that pointer (and anything under it). With none: Nothing in this document reads or writes {pointer}. The data map is the same walk, drawn as nodes and edges.

In the document it is plain JSON under ui.state:

"state": { "steps": { "laptop": false, "accounts": false } }

State keys become JSON Pointer segments, so they are held to the same rules as paths: no / or ~ inside a key, no - on its own, no leading or trailing spaces, and none of __proto__, prototype, constructor or $state. State may nest at most 12 levels, and /mica is reserved for hosts.

Text and Heading content can read state. Select the component and, under Content, switch from Static to State and enter the path:

"props": { "content": { "$state": "/guest/name" }, "size": "lg", "tone": "default", "align": "left", "italic": false }

The text follows the value live. A value that is missing or null renders as empty text, and a number or boolean renders as written. A Heading’s content must be non-empty text when it is static.

A bound Text, Heading or Value can show its value formatted: under the path, set Format as to Number, Currency, Percent, Date or Count. Currency asks for an ISO currency code (EUR, USD, GBP) and Count for the wording of one and of any other number (claim, claims). The read stays the same, wrapped in $format:

"content": { "$format": "currency", "value": { "$state": "/claim/amount" }, "currency": "EUR" }

1250 then shows as €1,250.00 in an English locale and 1.250,00 € in a German one: the host picks the locale, and the designer uses your browser’s. Percent reads a fraction (0.25 is 25%), Date a YYYY-MM-DD text, and Count a number or a list, whose rows it counts, and shows the wording for one only at exactly 1, whatever the locale; for a language with more plural forms, have the host supply the text. A value of the wrong kind shows nothing. Only a read can be formatted: fixed text is written as it should show. Format as works the same for a business object field or a row field; set it back to None to show the raw value. The Business object picker offers only fields the chosen format reads; to count a collection’s list, type its path (/objects/orders/data) in State mode. See $format for the details.

A Text, Heading or Value can show a number calculated from the document’s state while the person types: an order total (price × quantity), a basket’s total, or the nights between two dates. Choose Calculate beside Static and State; the read shown so far becomes the first operand. Pick the calculation — Sum, Product, Difference, Quotient, Round, Smallest, Largest or Days between two dates — and for each operand whether it is a Number, a State path, a Row field (inside a list template) or a nested Calculation, up to three deep. Sum, Smallest and Largest can instead take Every row of a list: pick the list and the field to total. Below, the control shows what the calculation gives over the document’s sample state, and Format as shows it as money or a count:

"content": {
"$format": "currency",
"value": { "$calc": "product", "args": [{ "$state": "/order/price" }, { "$state": "/order/quantity" }] },
"currency": "EUR"
}

An input that is empty or not a number, or a division by zero, shows nothing rather than an error. A calculation is for display only: it is never sent to the host and no condition can read it, so the host recomputes the total it charges, and decides anything that depends on it. See $calc.

A number or text $expr may sit in the same display props (arithmetic, or if choosing between values; comparisons only inside if’s condition). A boolean $expr is refused here. When the prop already holds one, the Inspector is in formula mode — a Formula · … summary, Remove, and the formula editor — rather than Calculate. Calculate still creates $calc. Boolean formulas belong on Show when and $cond; see formulas for true and false.

A Button’s Set a value action (setState) writes to one path:

{ "action": "setState", "params": { "statePath": "/steps/laptop", "value": true } }

The value may be text, a number, true/false, or { "$state": "/other/path" } to copy another value at the moment of the press. null is not accepted: the runtime would drop the key rather than store null. The state path suggestions only offer paths a document may write.

In the Inspector, Set a value edits that value as Value, State path, inside a list template Row field, or Record. Record is a field-by-field builder: type a field name and press Add field (or Enter), then pick a kind for each field the same way. A record may have at most 32 fields; a 33rd is refused (has 33 fields; the limit is 32). Inside a template, Copy this row fills the record from the row’s top-level fields — see lists. $expr is refused in setState params.

The onboarding checklist is built entirely from this: each step’s buttons set a boolean, and conditions show which steps are done.

When the person sets the value themselves — switches something on, picks one of a fixed set of options — bind a form control to the path instead: a Toggle writes true/false, a Choice the chosen option, a NumberField or Slider a number and a DateField an ISO date, with no Button per value. See forms. A form that writes these paths can check itself with Local rules and a Check local rules (validate) action, which looks only at visible controls on the active page — see Check a form without a business object. validate is a reserved Mica name: a host action may not use it.

The document only holds the starting state. In the preview, writes go to a disposable session that Reset preview recreates and Exit preview discards. In a host, writes go to the store the host created; the document is never modified, and nothing a person does is exported.

A host may also put its own values in the store for a document to read — the reference host seeds /host/greeting and /host/account/plan, which its document shows with $state without ever declaring them.