app.contract is the root of the app: 942 lines holding the routes, the single App component, and every resource, mutation and task of every package. Its first line states why: "Routes, tabs, and every resource/mutation (Exact allows them only here)".
Why everything lives in the root
In Contract a child component declares no resource, mutation or task. The Exact compiler refuses it with type-child-resource (contract-for-agents.md). So package contracts such as read.contract hold only shapes, pure functions and view components, and the root declares the data and passes it down as props, with actions passed as action props. The cost is one large shared file. Ownership blocks keep it editable by several authors.
Section map
Lines | Section | What it holds |
|---|---|---|
Header | The ownership rule | |
Imports |
| |
| Rewrites a | |
|
| |
| Four tab routes and 21 routes beneath them. See Navigation | |
| The reply of the hidden crypto parity resource | |
|
| |
Package declarations | One | |
Shared actions |
| |
Package actions | One | |
| Values injected into read's components | |
View: route switch | One screen call per route | |
View: tab bar | Four |
Shared state
Three declarations are used by every package (lines 76-78):
Name | Kind | Meaning |
|---|---|---|
| state, | The Seed site the app reads and publishes to. Default |
| state, | Account id of the selected identity, |
| resource | Host clock facts. Wall time is always |
Declarations per package
Each block is described in a child page, with one line per state, derive, resource, mutation and task:
Block | Lines | Page |
|---|---|---|
| ||
| ||
|
Actions
Three shared actions come first: pick(name) selects a tab, follow(url) goes to a location scoped to the reader's server, back pops. Then each package has an actions block: read 281-327, discuss 328-365, activity 366-415, agents 416-550, me 551-669, profile 670-686, vault 688-733. Actions are the only place that writes state, sends a mutation (send m = source(...)), refreshes a resource, or reads the clock. Each package's actions are listed on its screens page, for example Agents screens.
Provide
The provide block is owned by discuss. It exposes discussions, discussNow, discussUtc, readNow and readUtc so that read's DocDiscussionSlot and row components can inject them without the root threading them through DocScreen props. The two now values are time.epochAtZero + readTick, the minute clock.
The view
The root node is main navigationKey=... navigationBack="back" navigate=follow testId="app" accent-color="brand". Inside it, a for t in nav.tabs loop draws one role="tabpanel" per tab, and a for e in t.stack loop draws every entry of that tab's stack. A chain of if e.name == "..." picks the screen component and binds its props to root state and actions. Screens of covered entries stay mounted, which is why screens take eid and often active. The tab bar follows.
User stories
The code described here exists to deliver these stories. Each story lists this page in its Trace (traceability).
US-READ-01 Open the app to my site's home: The server state (default https://hyper.media, persisted) and the route switch
US-READ-03 Follow links between documents: main navigate=follow and navigationBack
US-READ-05 Open an hm:// link from outside the app: main navigate=follow
US-ID-03 Switch between my identities: currentAccount is persisted root state every package reads
US-ID-08 Choose which Seed server I read from: server is persisted root state passed to every package
US-APP-01 The app feels like an iPhone app: The root view: every tab's stack and the tab list
US-APP-02 Move around the app without losing my place: Shared state that persists and the route switch in the view
US-APP-05 Always know what is happening: pending and failure are passed from root resources into every screen
US-TEAM-04 Understand how the app is built: The anatomy of app.contract section by section
In this section
Do you like what you are reading? Subscribe to receive updates.
Unsubscribe anytime