Datumo.StateView behaviour (datumo v0.1.0)

Copy Markdown View Source

Behaviour for read slices (read models), and the read that serves them.

Pick from history, fold into current state, project what the screen gets. There is no table and no materialised projection: the view is computed on every call, by read/3.

  • query/1 — what to read, from the call's arguments.
  • next_query/1 (optional) — what else to read, given what's folded so far: the plots of the receptions of a lot can't be named before the lot is read. It returns every follow-up query the state implies; read/3 reads only the ones it hasn't read yet and stops when none are new.
  • initial_state/0, apply_event/2 — the fold.
  • project/2 (optional) — the read model, from the folded state and the call's arguments. Without it, the state is the read model.

Summary

Functions

The read with the store passed in: read_model.query(args), then next_query/1 until nothing new, the fold, and project/2. Returns {view, every_query_item_read}. Production reads FACT; Datumo.Scenario reads the scenario's given, so a test runs this same code.

Callbacks

apply_event(state, event)

@callback apply_event(state :: term(), event :: map()) :: term()

initial_state()

@callback initial_state() :: term()

next_query(state)

(optional)
@callback next_query(state :: term()) :: term() | nil

project(state, args)

(optional)
@callback project(state :: term(), args :: term()) :: term()

query(args)

@callback query(args :: term()) :: term()

Functions

read(db, read_model, args)

view(read_model, args, read)

The read with the store passed in: read_model.query(args), then next_query/1 until nothing new, the fold, and project/2. Returns {view, every_query_item_read}. Production reads FACT; Datumo.Scenario reads the scenario's given, so a test runs this same code.