Skip to content

The surface and its moves

A surface is a record of what a person last asked for, and a move is one change to it with as many parts as it names. The surface is never edited field by field: every change is a move, an open, a show or a hide, each journaled as one event, each raising the version by one.

The parts of a surface

Part What it is Named by
shape what the surface is showing: a shelf, an item, a result; not a screen, because each device class renders the same shape its own way the vocabulary's shapes
anchor the thing the shape is about, by kind and id: theme:newcastle, market:m1; or none the vocabulary's anchorKinds
modifiers named qualifiers on the shape, by key and value: time=this weekend the vocabulary's modifierKeys
pending an act the person has begun and not committed, by kind and fields; or none the vocabulary's pendingKinds
rail the last few requests, newest first, each with the surface it left the vocabulary's railLength
showing the devices showing the surface now, each with its class and whether it is in a room the vocabulary's deviceClasses
owner the name the surface was opened for the consumer
version a counter, up by one on every change recorded the surface

A surface nobody has opened has opened false and every other part empty, and refuses every move.

One move, several parts

A move names any of the parts it changes, and they change together or not at all. Moving to a shelf about Newcastle this weekend is one move, one event and one version, not three:

{"shape":"shelf","anchor":{"kind":"theme","id":"newcastle"},"modifiers":{"time":"this weekend"},"request":"anything about Newcastle this weekend"}

Because a move is one event, a renderer never sees half of one: no device draws a shelf about the old anchor between two writes.

The fold, in order

The entity, the rows view and the device all apply a move the same way, in this order:

  1. The shape, when the move names one.
  2. The anchor: clearAnchor removes it and wins over anchor; otherwise anchor replaces it.
  3. The modifiers: each key in clearModifiers is removed, then each entry in modifiers is set. A key in both ends up set.
  4. The pending: clearPending removes it and wins over pending; otherwise pending replaces it.
  5. The request: when the move carries one, it goes on the head of the rail with the shape, anchor and modifiers as they now stand, and the rail is cut to its length.

A move that names none of these is refused. The order is the contract: the device applies its own moves locally by the same fold, so a change to the order would show one thing on the device and another on the server.

The rail is the way back

The rail holds the last requests, newest first, three unless the vocabulary says otherwise. Each entry keeps the text and the shape, anchor and modifiers the request left the surface in, so a renderer can offer the way back to any of them as a move. A move with no request changes the surface without touching the rail, which is how a tap on a card differs from a request a person made.

The moves made from one utterance share one entry. A request that names the same utterance as the head of the rail replaces that entry rather than pushing a new one, so a device that says partial words while a person is still speaking leaves one entry for what they said, not one per word. Hear before you say uses it.

What the version promises

The version rises by one on every change the surface records and never falls. A renderer holding a surface replaces it with one of a higher version and ignores one of a lower or equal version. That one rule makes the order in which answers and streamed rows arrive not matter: whichever is newest wins, wherever it came from.

A hide for a device that is not showing records nothing, and the version does not move.

Opening and closing

open gives a surface its owner and its first shape, the vocabulary's home shape unless the open names another, at version 1. A surface is opened once; opening it again is refused.

close records the close and then deletes the surface, so the same id starts again unopened, and a device streaming it is told it was removed. The journal keeps the close for whatever reads it.

Every version is rebuilt from the journal

The surface is event sourced: what is stored is its events, and the surface is their fold. A service that restarts reads every surface as it was. The current state is a few hundred bytes; the history is what a consumer's own projections want, such as what was asked and what was looked at.