How ankka-surface works¶
ankka-surface is four components and one endpoint inside the consumer's own ankka service, and a model on every device that talks to that endpoint. The surface entity is the only place a surface changes; a view keeps one row per surface, and every device streams that row.
The components¶
| Component | Kind | What it holds |
|---|---|---|
| surface entity | event sourced entity | one surface by id: every change, journaled, one event per change |
| surface rows | view | one row per surface, the whole surface, keyed by its id; what a device streams and what lists an owner's surfaces |
| focus entity | key value entity, optional | where the attention is beside one surface, the latest value only |
| focus rows | view, optional | one row per focus; what a device streams to follow it |
The consumer registers each one by extending the library's companion with a component id of its own, so two kinds of surface in one service stay apart. The endpoint serves them under a prefix and an ACL the consumer chooses. Serve surfaces wires them.
The path of a move¶
A move goes from a device to the journal and back to every device in five steps:
- The device applies the move to the surface it holds, at once, by the same fold the server applies, so the person sees the change before the server answers.
- It posts the move to
/{id}/moves. The endpoint stamps it with the time from its clock. - The surface entity refuses the move if the surface is not opened, if the move names nothing, or if
it uses a word the vocabulary lacks. Otherwise it journals one
Movedevent and answers the surface at its new version. - The device replaces what it applied locally with that answer.
- The rows view folds the event into the surface's row, and every device streaming that row is given it. A device takes a row only when its version is higher than the one it holds, so the device that made the move ignores the echo.
The path of a say¶
A say is the same path with the interpreter in front of it. The endpoint reads the surface, hands it and the words to the consumer's interpreter, and either applies the interpreter's move with the words as its request, or answers that nothing was understood and why. The device does not apply a say locally, because it cannot know what the interpreter will make of the words. The surface never acts explains what an interpreter may and may not do.
What each half owns¶
| The server half owns | The device half owns |
|---|---|
| the surface and its version | one copy of one surface, and the version it holds |
| refusing words the vocabulary lacks | applying its own moves locally before the answer |
| the interpreter's answer to a say or a hear | which say is the newest, so an older answer is not held |
| the time every change carries | reconnecting, and fetching the surface before every stream |
| which devices are showing the surface | showing itself on connect and hiding itself on disconnect |
Neither half renders anything. A renderer is the consumer's: it reads the surface the device model holds and draws it however that device draws. Devices says what a renderer honours.
Why a library and not a platform feature¶
ankka owns entities, views and streams and nothing above them, so what is shown to a person and how it is steered is a layer a service adds. The layer is generic: the consumer's words are data in a vocabulary rather than types in the library, so every consumer shares one JSON, one device package and one HTTP API.