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

The render memo (spec/01 §3.4): what a pure cell's proof rendered, by a key the runtime
builds from everything the render reads, shared by every page under one supervisor, so
a cell many viewers see is proved once per change and placed by each.

**A behavior over an argument**, so a host of several nodes plugs a shared one. A host
chooses it with the supervisor's `renders:` option, `{module, arg}`;
`Macaw.Live.Renders.Memory`, the default, is an ETS table its process owns, bounded by
entries and bytes, the oldest dropped. A memo module exporting `child_spec/1` is
started under the supervisor with its argument and `name: <live>.Renders`, and that
argument is the one its callbacks are given.

**The key** (`key/4`) is built by the runtime from the cell, never by hand: the
component's module and kind, the viewer for a cell reading a source that isn't
viewer-independent, and its assigns, each delivery's table (and each slot's read, by
the signature it was read with, spec/03 §2.2) replaced by its chunk identity: each
chunk's `{id, version}` and the run of its rows the table reads, a
chunk's version being its content's digest (macaw_data spec/01 §1.1.3). A render is a
pure function of its assigns (macaw_component spec/02 §7), so equal keys render equal
markup, and any input that moves moves the key. A table with a chunk of no version
leaves the cell unkeyed: proved each time, never held. The key is a term the memo
compares exactly, so no two inputs share one.

**A safe render is held**, as the one binary the proof wrote
(`Macaw.Live.Proof.render/4`), and so is a keyed render (`Macaw.Live.Keyed`), each
part the binary the proof wrote, so a hit copies references. A HEEx render carries its
change tracking and is proved each time.

**A keyed render's rows are held too** (`written/3`), each by its row key (`row_key/4`):
the row's key, its content version (its chunk's version, its place in the chunk and its
mark, macaw#439) and the render's scope (what every row reads besides: for macaw's
table its instance, whether events work, its columns and its identity field), with the
viewer for a cell reading a source that isn't viewer-independent. Rows of equal scope
and version have equal markup, so a proof writing a keyed render takes each row the
memo holds as the binary held, writes only the others and holds them: a row many pages
draw is written once and its one binary shared. A version is its chunk's, so a changed
row moves the version of every row its chunk holds. A row with no version, or a render
with no scope, holds nothing.

**The rows a memo holds are handed to a render undrawn** (macaw#465): a memo exporting
`rows/3` answers the rows it holds under a scope and a viewer (`held/3`), which a proof
merges into the rows its page kept and hands the render as macaw_component's `held`
assign, so a row any page drew is taken as held, not drawn again.

# `held`

```elixir
@type held() :: {:safe, binary()} | Macaw.Live.Keyed.t()
```

What a memo holds: a safe render's binary, or a keyed render, each part a binary.

# `key`

```elixir
@type key() ::
  {module(), atom(), term(), map()} | {:row, term(), term(), term(), term()}
```

A memo key: a cell's (`key/4`) or a keyed render's row's (`row_key/4`).

# `get`

```elixir
@callback get(arg :: term(), key()) :: {:ok, held()} | :miss
```

The markup held under `key`: `{:ok, held}`, or `:miss`.

# `put`

```elixir
@callback put(arg :: term(), key(), placed :: held()) :: :ok
```

Holds `placed` under `key`: `:ok`.

# `rows`
*optional* 

```elixir
@callback rows(arg :: term(), scope :: term(), viewer :: term()) :: [{term(), binary()}]
```

The rows held by row key (`row_key/4`) under `scope` and `viewer`, whatever their row's
key: `[{version, binary}]`, in any order. Optional: a memo without it shares no rows
with a proof before it draws (`held/3`).

# `held`

```elixir
@spec held(atom(), term(), term()) :: Macaw.Live.Keyed.held()
```

The rows the supervisor `live`'s memo holds under a keyed render's `scope` and `viewer`,
as macaw_component's `held` assign takes them (`t:Macaw.Live.Keyed.held/0`): `%{}` for a
memo without `rows/3`, or a render of no scope.

# `key`

```elixir
@spec key(module(), atom(), map(), term()) :: {:ok, key()} | :none
```

A cell's key from its module, kind and assigns, and `viewer`, what names the viewer for
a cell reading a source that isn't viewer-independent (`nil` otherwise): `{:ok, key}`,
or `:none` for a cell delivered a table with a chunk of no version.

# `row_key`

```elixir
@spec row_key(term(), term(), term(), term()) :: {:ok, key()} | :none
```

A keyed render's row's key from the render's `scope`, the row's `key` and `version`, and
`viewer` as `key/4` takes it: `{:ok, key}`, or `:none` for a row of no version or a
render of no scope, whose markup is never held.

# `written`

```elixir
@spec written(atom(), term(), Macaw.Live.Keyed.t()) :: Macaw.Live.Keyed.t()
```

A keyed render written out as `Macaw.Live.Keyed.written/1` writes it, each row the
supervisor `live`'s memo holds by its row key (`row_key/4`, with `viewer`) taken as the
binary held, and each other row written and held.

---

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