Contract is Exact's declarative interface language. A .contract file describes what the app shows and how its state changes. It cannot fetch, read files or run arbitrary code: that is the job of the data module. This page is a lookup table for the constructs the app actually uses. The full language is in Exact's grammar and guide for agents.
Syntax in one paragraph
Indentation with spaces makes blocks. Top-level declarations start in column 1. Tags are HTML element names and attributes are CSS properties or element attributes (padding=16, flex=1, color="-exact-label"). A bare number is pixels, units are quoted ("50%"). Names may contain hyphens, so subtraction needs spaces (a - b). Comments are //. Strings use double quotes, templates use backticks.
Declarations
Construct | Real example | Source |
|---|---|---|
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
| The root provides |
State and data, inside a component
Construct | Real example | Source |
|---|---|---|
|
| |
typed |
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
reset a mutation slot |
| |
|
|
A resource is asked again whenever one of its arguments changes. The app refetches on purpose by changing an argument, see State, refresh and stale-reply patterns. with appends arguments that should not count against a kept answer at boot. A mutation reads as option<T> and starts at none.
Views and built-in calls
Elements, attributes, navigation attributes and built-in calls such as share, haptic and openURL are on their own page: Contract views and built-in calls.
Purity rules
From Exact's start-here guide and README:
No truthiness. Conditions are bool: write draft.trim() != "".
Absence is an option, none or some(x), read with match. There is no null.
Values never change. Build a new one: xs.concat([x]), or a record copy Shape(old, field=value).
== compares lists and records by value.
State changes only in actions. "Nothing runs because a value changed: an event runs an action." Writes land when the action ends, so a later line reads the old value. Bind with let when the new value is needed.
No loops in actions and no await. Lists are a view's keyed for. Computation is a derive or fn. Anything slower lives in a source.
Root-only rules
resource, mutation and task may be declared only in the root component, and routes only in the root file (language inventory). That is why app.contract holds every one of them and passes data and actions down as props. Child components may hold their own state, derive and actions. persist is for root state only.
Compiler commands
Command | What it does |
|---|---|
| Compile, rewrite |
| Source-preserving formatter ( |
| No name prints the card ( |
| Generate the |
More verbs are in Commands and verbs.
Do you like what you are reading? Subscribe to receive updates.
Unsubscribe anytime