# `Macaw.Live.Page`
[🔗](https://github.com/dcoai/macaw_live/blob/v0.1.0/lib/macaw/live/page.ex#L1)

The runtime's value a page process holds (spec/01 §4.1), in the socket's private data
(`Phoenix.LiveView.put_private/3`), never an assign, so a change to it renders nothing by
itself. Its loop is visualize's `Visualize.Board.Server`'s, adapted; its state is
replaced by `Macaw.State` (spec/08).

| Field | Holds |
|---|---|
| `surfaces` | by name: the validated surface, its `Macaw.State`, its env, its readers, and per cell its last proved assigns, its pending inputs, its process and restarts |
| `sources` | by key, each source manager its readers subscribe to: its process, its monitor and the page's readers of it (spec/03 §2) |
| `readers` | each managed reader's name to its surface, cell and slot, its manager's key, and its window and budget (spec/03 §1) |
| `pending` | the readers subscribed or moved whose manager hasn't answered yet (spec/03 §3) |
| `refused` | the readers whose window their manager refused, each drawn `down` (spec/03 §8) |
| `sliding` | the readers of a sliding window, moved every `tick:` (spec/03 §2) |
| `digests` | each surface's sources' entries digested once, by surface and name, for their managers' keys |
| `reads` | each managed reader's last read of its window, its status and delivery (spec/03 §2.1) |
| `reading` | the read turns running, by manager key (Page.Reads, spec/03 §2.1) |
| `derived` | by surface, the process running its derived sources (`Macaw.Live.Derived`), its key and monitor, when it declares them (spec/03 §3.1) |
| `mirrors` | the values of other processes' nodes this page reads, each with its sequence (spec/04 §1) |
| `scopes` | the scopes past `:surface` and `:shared` (spec/04 §5): the visit joined for `:session`, the page's `:page` owner and its readers, and each surface's `:viewer` carrier |
| `place` | for a page `Macaw.Live.mount_page/3` mounted or a persistent region, its place in the page DAG across processes: its holder, the graph, its exports edge and its readers, and the exports edges it reads (spec/04 §2, §3, §6) |
| `pulse` | the marks waiting for the next pulse and its timer, a `Macaw.Live.Pulse` (spec/03 §3) |
| `waiting` | the cells whose slots were asked or changed, rendered once none of their readers waits for its manager (spec/03 §3) |
| `due` | the page's next slide of its sliding readers, its monotonic ms and timer (spec/03 §2) |
| `instances` | each mounted cell's instance id to its surface and cell |
| `processes` | each contained cell process's monitor to its instance (spec/02 §5) |
| `now` | the instant of the last pulse (spec/01 §7) |
| `config` | the page's live settings, from its first mount: `live:`, `clock:`, `tick:`, `timeout:`, `debounce:` |
| `turned` | the reductions its turns have spent, summed (spec/07 §0) |
| `shortcuts` | the shortcuts each mounted instance declares, the page's registry built from them and the viewer's `shortcuts` preference (spec/05 §6) |
| `stream` | a connected page's binary stream: its topic and token, and the joined channel's pid and monitor, or nil before it connects (spec/05 §9) |
| `navigation` | by surface, the faults of the last navigation step of one of its cells that its behavior or `Macaw.Page.steps/2` refused, gone once one succeeds (spec/01 §9) |
| `themes` | by surface, the faults of the last relink of its theme sheet after its `theme` changed, gone once one succeeds (spec/06 §2.4) |
| `budget` | its visit's event budget, a `Macaw.Live.Visit.Budget` built from its `event_budget:` at its first client event; `nil` before it or for `:unlimited` (spec/01 §5.1) |

**It holds no copy of a value another place holds:** a state's values are its
`Macaw.State`'s, a source's chunks its manager's, a delivery, once proved, its cell's
assigns'.

This module holds the value and the runtime's LiveView hooks, routing each message to
its concern: a surface's mount (Page.Mount), its cells built, proved and rendered
(Page.Render), the runtime's events (Page.Events), its contained cells (Page.Contained),
its `:shared` owners (Page.Mirrors), its scopes past `:surface`
(Page.Scopes) and its place in the page DAG across processes (Page.Edges).

# `cell`

```elixir
@type cell() :: %{
  name: String.t(),
  instance: String.t(),
  module: module(),
  kind: atom(),
  classes: String.t(),
  assigns: map(),
  placed: Macaw.Live.Proof.placed() | nil,
  held: Macaw.Live.Keyed.held() | nil,
  drawn: :ok | :loading | {:crashed, term()},
  seq: non_neg_integer(),
  pending: term(),
  pid: pid() | nil,
  restarts: non_neg_integer(),
  run: map() | nil
}
```

A cell as the page holds it: its name, instance, module, kind and classes, the assigns it
last rendered (proved, or tried and failed), what that proof rendered (`placed`, which its
component places; `nil` for a crash and for a connected contained cell, whose component
renders its process's proved value), the rows it keeps for its next proof (`held`,
`Macaw.Live.Keyed.kept/2`, `nil` for a render that isn't keyed), the outcome of that proof (`:loading` for a
contained cell whose process has not answered yet), the sequence its component last took,
and for a contained cell its pending inputs, its process, its restarts and its `run`, the
page's side of the process (spec/02 §3).

# `surface`

```elixir
@type surface() :: %{
  validated: Macaw.Surface.Validated.t(),
  state: Macaw.State.t(),
  env: keyword(),
  readers: %{required(String.t()) =&gt; [Macaw.Surface.reader_entry()]},
  order: [String.t()],
  cells: %{required(String.t()) =&gt; cell()},
  positions: %{required(String.t()) =&gt; non_neg_integer()},
  sizes: %{required(String.t()) =&gt; {number(), number()}},
  ratios: %{required(String.t()) =&gt; number()},
  font: number() | nil,
  plain: MapSet.t(String.t())
}
```

One mounted surface as the page holds it.

# `t`

```elixir
@type t() :: %Macaw.Live.Page{
  budget: Macaw.Live.Visit.Budget.t() | nil,
  config: keyword(),
  derived: map(),
  digests: %{required({String.t(), String.t()}) =&gt; String.t()},
  due: %{required(term()) =&gt; {integer(), reference(), reference()}},
  hooks: [atom()],
  instances: %{required(String.t()) =&gt; {String.t(), String.t()}},
  mirrors: map(),
  navigation: %{required(String.t()) =&gt; [Macaw.Base.Fault.t(), ...]},
  now: DateTime.t() | nil,
  params: map(),
  params_done: boolean(),
  pending: MapSet.t(),
  place: map() | nil,
  processes: %{required(reference()) =&gt; String.t()},
  pulse: term(),
  readers: %{required(String.t()) =&gt; map()},
  reading: %{required(Macaw.Data.Manager.key()) =&gt; map()},
  reads: %{
    required(String.t()) =&gt;
      {Macaw.Data.Manager.status(),
       Macaw.Live.Manager.Read.t() | Macaw.Data.Delivery.t() | nil}
  },
  refused: %{required(String.t()) =&gt; Macaw.Data.Manager.status()},
  scopes: map(),
  shortcuts: %{
    declared: %{required(String.t()) =&gt; [map()]},
    registry: Macaw.Live.Shortcuts.t() | nil,
    preference: Macaw.Live.Shortcuts.preference()
  },
  sliding: MapSet.t(),
  sources: %{required(Macaw.Data.Manager.key()) =&gt; map()},
  stream:
    %{
      topic: String.t(),
      token: String.t(),
      pid: pid() | nil,
      ref: reference() | nil
    }
    | nil,
  surfaces: %{required(String.t()) =&gt; surface()},
  themes: %{required(String.t()) =&gt; [Macaw.Base.Fault.t(), ...]},
  turned: non_neg_integer(),
  waiting: %{required({String.t(), String.t()}) =&gt; true}
}
```

---

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