Read: root contract wiring
The pkg:read blocks of app.contract: routes, state, derives, the three resources, actions, the reader's server context and the view switch.

Exact allows resources and mutations only in the root component, so the read package's data wiring lives in app.contract inside // >>> pkg:read blocks. The convention is described in Package conventions and ownership blocks; this page lists what the read blocks contain and why.

Routes

app.contract L27-L33: the read tab at /, doc "/d/:ref", and inside the read block open-site "/open-site", directory "/dir/:uid", author "/a/:uid". app.json maps the hm protocol to /d/%s, so a deep link arrives as the doc route's parameter (Deep links and URL handling).

Declarations

Name

Kind

Meaning

readSiteDraft, readSiteError, readSiteRevision, readSiteSubmittedRevision, readSiteReplyCurrent, readSiteOpened

state, derive, mutation

The open-site form, see Open a site by URL.

readEpoch

state

Bumped by pull to refresh; an argument of every read resource (the epoch).

readTick, task readClock

state, task

readClock runs on mount and calls readClockStep every 60000 ms, which stores performanceNow(). Views use time.epochAtZero + readTick for relative dates in Read and Discuss.

dirQuery

state

The directory search text.

readStack

derive

The stack entries of the read tab.

readRefs

derive

One ref per read or doc entry on the stack ("" for the home).

readContextRef, readContextServer

derive

The ref of the top-most read, doc or Activity-opened thread entry, and the server of the loaded page with that ref (the configured server when the ref is empty or not loaded).

readVisible

derive

Only the top entry: "Do not request covered detail routes on the visible entry's server."

dirUid, authorUids

derive

The uid of a visible directory or author entry.

readCurrent

derive

The ref of the context document, for the directory's check mark.

docs

resource

readDocs(server, readRefs, readEpoch) as shape DocPage[] else empty()

directory

resource

readDirectory(readContextServer, dirUid, readEpoch) as shape DirPage else empty()

authors

resource

readAuthors(readContextServer, authorUids, readEpoch) as shape AuthorPage[] else empty()

docs is asked for the whole stack at once, which is why every covered document stays loaded and Back shows it instantly. directory and authors get a real uid only while their screen is on top; otherwise the uid is empty and the loaders answer without a request.

The reader's server context

Documents may be read from a server other than the configured one (a typed site, a gateway link). Three pieces keep navigation consistent without changing settings:

    docs is called with the configured server; a URL ref makes buildPage switch servers and report the real one in DocPage.server.

    readContextServer is that reported server for the visible reader. The directory, authors and the discuss resources are asked on it.

    readScopedHref(url, server) rewrites a plain /d/{ref} href to /d/{server}/hm/{ref} (encoded) unless the ref is already a URL. The root's follow action and readDirOpen apply it with readContextServer, so a link tapped inside a typed-site document opens on that site.

A thread entry opened from Activity carries ?from=activity. It counts as a context entry, and a thread entry has no ref parameter (inferred: the context ref is then empty), so the context becomes the configured server; Back restores the covered reader's context. open-site-activity.test.contract asserts readContextServer at each step.

Actions

Action

Effect

readShowOpenSite, readEditSite(v), readSubmitSite, readSiteAfterOpen

The open-site form.

readClockStep

readTick = performanceNow()

readRetry, readDirRetry, readAuthorRetry

refresh docs, refresh directory, refresh authors

readRefresh

readEpoch = readEpoch + 1

readOpenDir(uid)

Push the directory route.

readDirSearch(v), readDirClose

Set or clear dirQuery; close also goes back.

readDirOpen(href)

Go back, then go to the scoped href, and clear the search.

Provide and view

The root provides discussions, discussNow, discussUtc, readNow and readUtc; read's rows and DocDiscussionSlot inject them instead of threading props through every component.

The view switch renders one screen per stack entry of every tab: DocScreen for read (with ref="", home=true) and doc, then OpenSiteScreen, DirectoryScreen and AuthorScreen in the read block. Each gets active=(e.id == top(nav).id) and loading=pending(...) of its resource. The two DocScreen lines sit just outside the pkg:read view markers, in the lead-owned part of the switch.

Other packages that touch these

    Profile: profileSaved refreshes authors and docs.

    Discuss: discussTargets derives from docs; both discuss resources add readEpoch to their epoch.

    Agents: agentsNavigate opens hm:// URLs with path("doc", url).

Do you like what you are reading? Subscribe to receive updates.

Unsubscribe anytime

Comments