Skip to content

Actions

Eight components fire an event, and each fires exactly one:

Component Event Fires when
Button press A person presses the button.
Input commit A person presses Enter in the field (always, even with the value unchanged), or leaves it when its value differs from what it was when they focused it or last committed it. A commit whose actions were rejected does not count, so leaving the field fires it again. A text area (lines above 1) takes Enter as a new line, so only leaving it commits.
NumberField, Choice, Toggle commit A person changes the value — confirms a typed number by leaving the field or pressing Enter, steps it, picks an option, ticks or clears a box, flips the switch, presses a toggle button — after the new value is written.
DateField, DateRange commit A typed date commits as an Input’s text does (Enter, or leaving the control changed); a date or range picked from the calendar commits at once.
Slider commit A drag ends, or an arrow key is pressed, on a new value — once, not while it moves.

Both come only from the person. A commit never fires per keystroke, and a store write — by an action or by the host — never raises either event, even when it changes an Input’s value, so no action can set off another event. A form control that is not editable (not bound, or writable is false) never commits.

An element’s on maps its event to one binding or a list of up to 8 bindings, run in order. press and commit take the same bindings, checked by the same rules:

"on": {
"press": [
{ "action": "setState", "params": { "statePath": "/guest/attending", "value": true } },
{ "action": "goToPage", "params": { "page": "page-thanks" } }
]
}
"on": {
"commit": { "action": "fetch", "params": { "object": "orders", "inputs": { "customerId": { "$state": "/customerId" } } } }
}

A binding is exactly { "action", "params" }. json-render’s binding-level confirm is refused — create, update and delete carry their own confirmation — and so are any other binding keys. If an action rejects, the actions after it do not run.

Import refuses an event the component does not fire — commit on a Button, press on a form control, either on anything else.

A Button or a form control inside the template of a repeated Stack or Grid runs its actions for its own row, and they may read that row’s fields with $item — nested in a value slot only: a leaf of a setState or addRow record, an object input’s whole value, or the key in an object action’s or a removeRow’s row. A param that is itself a row read ("value": { "$item": "id" }) is refused, because json-render resolves it to the row’s position path, not its value; $index and $bindItem are refused anywhere in params, and every row read is refused outside a template and in startup. See lists.

Write one value to document state.

Param Contents
statePath A writable state path.
value Text (up to 10,000 characters), a number, true/false, { "$state": path } to copy a value when the event fires, or a record of them. Not null.

A record is a plain object, {} included. Its keys follow the row-field rule — no /, ~, leading $, position (0, -), __proto__/prototype/ constructor, or surrounding spaces — and each value is text, a finite number, true/false, null, one { "$state": path }, inside a template one { "$item": field } of the element’s row, or another record. Records nest at most 4 levels, with at most 32 keys each and 64 values in all, and never hold a list literal (a read may still copy one). {} clears a draft.

A $state value that reads a declared object’s record copies it into ordinary state — the draft pattern. The target may never be a path a declared object owns, nor a path inside a list a repeat renders (change its rows with addRow, removeRow or $bindItem); at the list’s own path only a $state copy is accepted. Built into json-render; a host registers nothing for it.

Ask the host to show another page.

Param Contents
page The key of a child of the root PageStack (1–200 characters).

The host registers goToPageHandler(document, onNavigate) for it. Removing a page in the designer removes goToPage bindings that target it.

Check the form controls that carry rules and are visible on the active page, without asking the host. Local form validation: a control’s rules plus this action, with no new envelope keys (params stays {}; there is no params.controls). requiredWhen stays on business-object inputs. validate is a Mica verb; a host action of that name is refused at import.

Param Contents
(none) params is {}. Any other key is refused.

The control must bind its value with $bindState and its error with a {"$state": "/path"} read. rules may carry required: true, enum, and the field constraints its kind allows (pattern, minLength, maxLength on text; minimum, maximum on a number). Toggle has no rules. The host registers createValidateHandler({ document, store, activePageKey }). The getter is required and must return the same key the host gives PageProvider (JSONUIProvider copies handlers at mount). A host that never navigates passes () => undefined, which matches PageProvider and checks the first page. The handler writes each message (or "") to that control’s error path and rejects if any of those fail, so the rest of the event does not run. Controls on other pages, or hidden by visible, are not checked and keep their error slots. With none visible it succeeds. Import refuses an error path that setState could not write, or that equals, contains or sits inside a $bindState path or a list a repeat or $bindItem uses, and refuses validate when no control carries valid rules.

Add a row to, or remove a row from, a local list: a list in ordinary document state that a repeat in the document renders.

Param Contents
statePath The list: a literal state path with no position segment, writable, and the repeat.statePath of at least one Stack or Grid. Every repeat over it must use the same key, which is the list’s key. Never a declared object’s path.
value addRow only: a record of the new row’s fields, as for setState. It may not set the key.
row removeRow only: { <key>: value }, naming the row by its key. The value is non-empty text or a number, one { "$state": path }, or inside a template one { "$item": field } — the key itself in a template over this list.
  • addRow appends the row with a key Mica generates, row-1, row-2 and so on, skipping any key the list already holds.
  • removeRow removes every row whose key, compared as text, equals the one named. When none does, including when the key it reads is empty, nothing is written and the action succeeds.
  • A list that is not in state yet counts as empty.
  • Each rejects when the path holds something other than a list, or sits inside a value that is not a record. addRow also rejects when the list already holds 500 rows, when the new row takes more than 16,384 characters of JSON once its reads are resolved, and when it would nest state deeper than 12 levels. A rejection stops the rest of the event.
  • The values are stored as the event read them: nothing is resolved twice, and a typed $id stays $id.

The host registers the handlers createListHandlers({ document, store }) returns; see the runtime API. json-render’s own list actions, pushState and removeState, are refused on import: they run before any handler, so they remove by position and cannot be bounded.

Act on a declared business object. The object must declare the capability.

Param Contents
object The alias, as a literal string (1–64 characters). Never a $state read.
inputs Optional. Each key must be a declared input of that capability; each value is a literal the input’s rules accept, one { "$state": path }, or inside a template one { "$item": field } of the pressed row.
row A collection’s update and delete only, and required there: { <identity>: value }, naming the row by the collection’s identity. The value is a non-empty literal of the identity’s kind, one { "$state": path }, or inside a template one { "$item": field } — the identity itself in a template over this collection, a field of the identity’s kind over another declared collection (integer also serves a number identity), and any field over a local list, whose kinds are undeclared (a missing or unusable identity there fails at runtime with no-row).
confirmation create, update and delete; required on delete, optional on the other two. One line of plain text, 1–240 characters, never a $state read, shown before anything is sent. fetch refuses it.
  • Every required input must be supplied — as a $state read, or a literal other than "". Conditional (requiredWhen) inputs are checked when the event fires.
  • update and delete never take the identity as an input. For a record the runtime supplies the current record’s; a collection’s name their row with row, and with no usable identity there they fail with no-row before the host is asked. create, fetch and a record’s operations never take row.
  • Only fetch may appear in lifecycle.startup, which holds at most 8 entries.
  • One operation runs per object at a time; another is rejected as busy. The one exception: a fetch a person’s press or commit dispatches while another such fetch of that object is running replaces it (latest wins). A startup fetch is never replaced. The earlier fetch rejects as superseded, so its answer never lands and the rest of its event’s actions do not run. See the host contract.

What each verb does at runtime is described in Load, create, update and delete records, and the host side in the host contract.

A host lists named verbs (createLead) with param schemas. The designer and an agent pick a name into the document’s hostActions map; import then validates every binding against that declaration. An undeclared name is still Unknown action. Params use the same field-spec grammar as object inputs (literals, $state, a whole-param $item), except requiredWhen, which is operation-input only. Host actions cannot run at startup. They are never scripts, and they are never compiled into an object create. Names may not be a Mica verb or a json-render built-in (setState, goToPage, validate, pushState, removeState, validateForm, push, pop), or a JavaScript prototype name such as toString. validate is the ninth Mica verb; a host action of that name is refused at import.

The session catalogue (catalogVersion + actions + field-spec params) is authoring material only: the editor loads it for one session, and a future live host fetches the same JSON over the network. Picking an entry writes the declaration, so mica:check works without the catalogue.

"hostActions": {
"createLead": {
"params": {
"name": { "kind": "string", "required": true, "maxLength": 80 },
"email": { "kind": "string", "required": true }
}
}
}

A host implements the handler and calls preflightHostActions(document, handlers) so every declared name the document actually dispatches is a function. Designer preview runs them against sidecar fixtures (succeed, cancelled or failed) or succeeds when no sidecar is present. Prefer the business-object verbs when the thing is a record.