Scala API¶
The Scala module is com.thinkmorestupidless:ankka-surface_3, in the package
com.thinkmorestupidless.ankka.surface. It depends on ankka's ankka-sdk, ankka-runtime and
ankka-http, and is built against ankka 0.16.3.
What a consumer extends¶
| Type | Extend it as | Registers |
|---|---|---|
SurfaceCompanion(componentId, vocabulary) |
object Surfaces extends SurfaceCompanion(ComponentId("surface"), vocabulary) |
the surface entity, event sourced |
SurfaceRowsCompanion(componentId, surfaces) |
object SurfaceRows extends SurfaceRowsCompanion(ComponentId("surface-rows"), Surfaces) |
the view of one row per surface |
SurfaceFocusCompanion(componentId, vocabulary) |
object Focuses extends SurfaceFocusCompanion(ComponentId("surface-focus"), vocabulary) |
the focus entity, key value |
SurfaceFocusRowsCompanion(componentId, focuses) |
object FocusRows extends SurfaceFocusRowsCompanion(ComponentId("surface-focus-rows"), Focuses) |
the view of one row per focus |
Interpreter |
object MyInterpreter extends Interpreter |
nothing; handed to the endpoint |
Each companion's descriptor is what Ankka.service.register takes.
Handlers and wire names¶
| Companion | Handler | Wire name | Takes | Answers |
|---|---|---|---|---|
SurfaceCompanion |
open |
open |
Open |
Surface |
move |
move |
Move |
Surface |
|
show |
show |
Show |
Surface |
|
hide |
hide |
Hide |
Surface |
|
close |
close |
Close |
Done |
|
get |
get, a query |
Surface |
||
SurfaceRowsCompanion |
byOwner |
by-owner, a view query |
owner |
the owner's rows |
SurfaceFocusCompanion |
set |
set |
SetFocus |
Focus |
get |
get, a query |
Focus |
A consumer's own components call them through ankka's component client, as the endpoint does:
client.forEventSourcedEntity(EntityId(id)).call(Surfaces.move).invoke(move). A consumer's route that
commits a pending act clears it this way.
SurfaceEndpoint¶
final class SurfaceEndpoint(
prefix: String,
val acl: Acl,
client: ComponentClient,
views: ViewClient,
surfaces: SurfaceCompanion,
rows: SurfaceRowsCompanion,
interpreter: Interpreter,
clock: Clock = Clock.systemUTC(),
focus: Option[FocusLane] = None
) extends HttpEndpoint(prefix)
FocusLane(focuses, rows) pairs the two focus companions. The routes are the
HTTP API.
Vocabulary¶
final case class Vocabulary(
shapes: Set[String],
homeShape: String,
anchorKinds: Set[String] = Set.empty,
modifierKeys: Set[String] = Set.empty,
pendingKinds: Set[String] = Set.empty,
deviceClasses: Set[String] = Set("phone", "laptop", "tv"),
railLength: Int = 3,
focusKeys: Set[String] = Set.empty
)
refuse(move) answers the first word of a move the vocabulary lacks, or None; refuseFocus(fields)
the first focus key. Declare a vocabulary explains every part.
Interpreter¶
trait Interpreter:
def interpret(surface: Surface, text: String): Interpretation
enum Interpretation:
case Understood(move: Move)
case NotUnderstood(reason: String)
Records¶
| Type | Fields |
|---|---|
Surface |
id, owner, opened, shape, anchor: Option[Anchor], modifiers: Map[String, String], pending: Option[Pending], rail: List[RailEntry], showing: List[Showing], version: Long |
Anchor |
kind, id |
Pending |
kind, fields: Map[String, String] |
RailEntry |
text, shape, anchor, modifiers, at: Instant, utterance: Option[String] |
Showing |
device, deviceClass, room: Boolean, since: Instant |
Focus |
id, device, fields: Map[String, String], at: Instant, version: Long |
Surface.empty(id) is a surface nobody opened. surface.applyMove(move, railLength) is the fold of
one move, leaving the version alone.
Commands¶
| Type | Fields |
|---|---|
Open |
owner, shape: Option[String], at |
Move |
shape, anchor, clearAnchor, modifiers, clearModifiers: List[String], pending, clearPending, request: Option[String], at, utterance: Option[String]; every field defaults to empty |
Show |
device, deviceClass, room, at |
Hide |
device, at |
Close |
at |
SetFocus |
device, fields, at |
Every command carries its time. The endpoint stamps it from its clock; a consumer calling the entity
directly stamps its own. Move has withRequest(text), at(instant) and fromUtterance(utterance)
to set those three.
Events¶
SurfaceEvent is a closed set, each case carrying its time: Opened(owner, shape, at),
Moved(move), ShowingStarted(showing), ShowingStopped(device, at) and Closed(at). A consumer's
own view or consumer reads them with ChangeSource.eventsOf(Surfaces).
Serializer manifests¶
The manifests the library registers are stored with every event and state, so they do not change:
surface, surface-event, surface-open, surface-move, surface-show, surface-hide,
surface-close, surface-row, surface-focus, surface-set-focus and surface-focus-row.