# `Macaw.State.Persistence`
[🔗](https://github.com/dcoai/macaw/blob/v0.6.0/lib/macaw/state/persistence.ex#L1)

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:

  * `Macaw.State.Persistence.None`, the default: nothing is stored, nothing loads;
  * `Macaw.State.Persistence.Url`: the carrier is a params map as Phoenix decodes a
    query string and encodes one (`handle_params/3`'s params, a verified route's query),
    the values nested under the surface's name;
  * `Macaw.State.Persistence.Session`: the carrier is a session map, the values under
    the surface's name, for state that must not go in a URL.

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

# `values`

```elixir
@type values() :: %{
  required(String.t()) =&gt; String.t() | %{required(String.t()) =&gt; String.t()}
}
```

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

# `load`

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

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

# `store`

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

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

---

*Consult [api-reference.md](api-reference.md) for complete listing*
