Declare a vocabulary¶
A vocabulary is the list of words a consumer's surfaces may hold. The surface entity checks every
move, open, show and focus against it before anything is kept, so a journal never holds a shape no
renderer knows, and a typo in a device is a 400 naming the word, not a blank screen.
Declare it¶
Vocabulary is a case class; every part but the shapes and the home shape has a default. This one
names three shapes, opens on home, and names the anchor kinds, modifier key, pending kind and focus
keys the rest of this documentation uses:
val vocabulary: Vocabulary = Vocabulary(
shapes = Set("home", "shelf", "item"),
homeShape = "home",
anchorKinds = Set("theme", "market"),
modifierKeys = Set("time"),
pendingKinds = Set("forecast"),
focusKeys = Set("card", "outcome")
)
The vocabulary is handed to the surface's companion and, for the focus lane, to the focus companion, so both check against the same words. Serve surfaces registers them.
Every part¶
| Part | Default | Checks |
|---|---|---|
shapes |
required | the shape of an open and of every move |
homeShape |
required | the shape a surface opens on when the open names none; must be one of shapes |
anchorKinds |
none | the kind of every move's anchor; an anchor's id is free |
modifierKeys |
none | every key a move sets or clears; a modifier's value is free |
pendingKinds |
none | the kind of every move's pending act; its fields are free |
deviceClasses |
phone, laptop, tv |
the class of every show |
railLength |
3 |
how many requests the rail keeps; 0 keeps none |
focusKeys |
none | every key a focus sets |
A part left at its default of none refuses every word of that part: a vocabulary with no anchor kinds
is a surface whose moves never carry an anchor. In particular, a consumer that registers the focus
lane names its focusKeys, or every focus but an empty one is refused.
Constructing a vocabulary whose home shape is not one of its shapes, or whose rail length is
negative, throws IllegalArgumentException, so the mistake stops the service at startup.
What a refusal says¶
A word outside the vocabulary is refused with 400, and the error names the first word refused and
what it was meant as:
{"status":400,"error":"the vocabulary has no shape 'basket'"}
{"status":400,"error":"the vocabulary has no anchor kind 'stake'"}
{"status":400,"error":"the vocabulary has no modifier key 'colour'"}
{"status":400,"error":"the vocabulary has no pending kind 'stake'"}
{"status":400,"error":"the vocabulary has no device class 'fridge'"}
{"status":400,"error":"the vocabulary has no focus key 'colour'"}
The parts are checked in the fold's order: the shape, the anchor kind, the modifier keys, then the pending kind. Nothing of a refused move is kept.
Choose the words¶
The vocabulary is the consumer's whole agreement with its renderers, so a word belongs in it when a renderer draws something different for it:
- A shape is a kind of thing to show, not a screen. If two screens differ only by what they are about, they are one shape with two anchors.
- An anchor kind is a kind of thing a shape can be about. The id is whatever names one in the consumer's domain.
- A modifier key qualifies a shape without changing what it is about: a time window, an order, a filter.
- A pending kind is an act a person can begin from the surface and commit somewhere else.
- A focus key is a kind of thing a finger can rest on.
Change it¶
A vocabulary is code, so it changes with a deployment. Adding a word is safe. Removing a word stops new moves using it, and a surface already holding it keeps it until a move replaces it, because the journal is replayed without the vocabulary's checks: they run on commands, not on events. A renderer should draw a word it does not know as nothing rather than fail.