Macaw.State.Persistence behaviour (macaw v0.6.0)

Copy Markdown View Source

Where a surface's state survives a reload, a new page or a later visit (spec/03 §3): a host behavior, chosen by the host, since it is a privacy and deployment decision.

A persistence moves text: store/3 writes a surface's values, each the text Macaw.State.persist/3 wrote, into its carrier under the surface's name, and load/2 reads them back for Macaw.State.restore/3, which judges every value as untrusted input. Three ship:

Persistence is for interaction state only, never for domain data.

Summary

Types

What a persistence stores: each state's text, or a map of names to text.

Callbacks

The values stored for the surface key, or %{}; any term, read as untrusted.

The carrier with the surface key's values written, replacing what it held.

Types

values()

@type values() :: %{
  required(String.t()) => String.t() | %{required(String.t()) => String.t()}
}

What a persistence stores: each state's text, or a map of names to text.

Callbacks

load(carrier, key)

@callback load(carrier :: term(), key :: String.t()) :: term()

The values stored for the surface key, or %{}; any term, read as untrusted.

store(carrier, key, values)

@callback store(carrier :: term(), key :: String.t(), values()) :: term()

The carrier with the surface key's values written, replacing what it held.