# macaw_live v0.1.0 - API Reference

## Modules

- [Macaw.Live](Macaw.Live.md): Macaw's LiveView runtime (spec/00): a runtime around Macaw's pure values, never a second
state model. `Macaw.State` stays the state, `Macaw.Surface.fetch/2` and `render/3` stay
the fetch and the render, and a contained component stays a pure value with transitions;
`macaw_live` decides only where these run and how changes travel (spec/00 §1).
- [Macaw.Live.Assets](Macaw.Live.Assets.md): What a page loads from its own origin (spec/06 §2, §3): the generated stylesheets the
runtime registers at mount and the links to them. Copied from visualize's
`Visualize.Sheets` and adapted: the store is a behavior over an argument
(`Macaw.Live.Assets.Store`), its default table the supervisor's
(`Macaw.Live.Assets.Store.Memory`), and a sheet's path is
`Macaw.Component.Stylesheet.path/1`'s, `/assets/<hex>.css`, `hex` the SHA-256 of its bytes.
- [Macaw.Live.Assets.Plug](Macaw.Live.Assets.Plug.md): The plug that serves every file the runtime and its components load from the page's own
origin (spec/06 §2.2, §3), mounted once
- [Macaw.Live.Assets.Store](Macaw.Live.Assets.Store.md): Where the runtime keeps what it registers at mount (spec/06 §2.1): generated stylesheets
and proxy routes, a behavior over an argument, so a host of several nodes plugs a shared
store. Copied from visualize's `Visualize.Sheets` table and made a behavior.
- [Macaw.Live.Assets.Store.Memory](Macaw.Live.Assets.Store.Memory.md): The default asset store (spec/06 §2.1): an ETS table its process owns, started under the
host's `Macaw.Live.Supervisor` as `<live>.Assets`, so the table is the supervisor's and
never an application's. Copied from visualize's `Visualize.Sheets` (D-297), its table
now named by the supervisor and its bound an argument.
- [Macaw.Live.Bench](Macaw.Live.Bench.md): The benchmark harness behind the performance requirements (spec/07 §8), in the shape of
visualize's `Visualize.Benchmark`: `run/2` measures, `format/1` reports.
- [Macaw.Live.Cell](Macaw.Live.Cell.md): The contained cell (spec/02): the process that holds one `:contained` component's value,
drives its transitions as inputs arrive, proves its render, and hands the page what to
draw. Copied from visualize's `Visualize.Board.Cell` (the host part of
`Visualize.Visual`) and adapted: generic, it knows a component only through
`Macaw.Component`'s dispatch functions and its `render/2`, and its coalescing has moved to
the sender (spec/02 §3). visualize's board, subscribers, views, tokens and click
resolution are not carried over (spec/08).
- [Macaw.Live.Cell.Backoff](Macaw.Live.Cell.Backoff.md): The restart schedule of a contained cell, a pure value (spec/02 §5). Copied from
visualize's cell restart in `Visualize.Board.Server` (100 ms doubling to 10 s, reset after
30 s alive) and adapted: the schedule is a value the page holds, and the delay a timer on
the page's clock (spec/01 §7), so a test steps it with the manual clock.
- [Macaw.Live.CellComponent](Macaw.Live.CellComponent.md): One `Phoenix.LiveComponent` per cell, so the diff a change costs is that cell's alone
(spec/01 §3.2, visualize spec/15 §9.1). Its id is the cell's instance id
(`"<surface>-<cell>"`).
- [Macaw.Live.Client](Macaw.Live.Client.md): The server's side of the client (spec/05 §4, §5, §7): the announcements and focus moves
the runtime pushes to the live module, and the runtime's own client events it reads.
Adapted from visualize's `Visualize.Hooks.Announcer` (`attrs/1`): the announcer's queue
is macaw_component's client module's, and a request is built here as the client builds
it, by `Macaw.Component.Announcement.new/2`.
- [Macaw.Live.Data](Macaw.Live.Data.md): How a mounted surface's slots get their data on a connected page (spec/03 §1, §2, §5,
§6, §8, §10): its readers, from `Macaw.Surface.readers/2`, subscribed to the source
managers that hold their sources (macaw_data's `Macaw.Data.Manager`), and each reader's window read
from what its manager published, handed back to the cells that read it. Adapted from
visualize's `Visualize.Board.Server.Budgets`: the readers are the core's, the budgets
clamped by the ceiling there.
- [Macaw.Live.Derived](Macaw.Live.Derived.md): A surface's derived sources run once per host (spec/03 §3.1, dco-tek/macaw/macaw#108 "A
derived source is a managed source"): a process holding one `Macaw.Data.Derived.Engine`
for every page that mounts a surface with the same derived sources over the same inputs.
- [Macaw.Live.Derived.Source](Macaw.Live.Derived.Source.md): A derived source's output read as any source (spec/03 §3.1): the entry a page puts in
its surface's `sources:` for each output its derived process runs, read by that
output's source manager as any source's.
- [Macaw.Live.Edge](Macaw.Live.Edge.md): The owner–mirror protocol (spec/04 §1): how a node of a page's DAG held in another
process reaches the processes that read it. One protocol serves every crossing edge: a
`:shared` owner (spec/04 §4), the visit's and the page's scopes (spec/04 §5), and the page and its
persistent regions once macaw has them (spec/04 §3). They differ only in where the owner
lives and how it is found.
- [Macaw.Live.Edge.Mirror](Macaw.Live.Edge.Mirror.md): A mirror of an edge (spec/04 §1): the last values a reading process holds of a node
another process owns, and the sequence they are as of. `Macaw.Live.Edge` is the owner's
side.
- [Macaw.Live.Hooks](Macaw.Live.Hooks.md): The generated hooks module (spec/05 §2): one ES module that imports every enabled
package's static hooks and the live module's, so a host registers them with its
`LiveSocket` in one import and changes nothing else. Adapted from visualize's
`Visualize.Hooks` (`js_code/0`, `install!/0`): the text is generated from the registry,
never a bundle of hook sources, and each hook file is imported by its static URL as its
default export (macaw_component spec/01 §1.8).
- [Macaw.Live.Keyed](Macaw.Live.Keyed.md): A keyed render (spec/01 §3.3): a component's render answered as keyed parts, which the
runtime places by key, so a change sends only the rows whose markup changed. The
runtime knows it by its shape alone, never by its module (spec/00 §1, it is generic):
a struct implementing `Phoenix.HTML.Safe` with
- [Macaw.Live.Manager.Read](Macaw.Live.Manager.Read.md): A reader's read of its window, as the page holds it (spec/03 §2.2, dco-tek/macaw/macaw#108
"Readers hold no chunks"): what it read and how it drew, never the rows. A page holds
this in a cell's entry where it held the delivery; the process that draws the cell (a
proof, a contained cell) reads the window again from the manager's table with
`resolve/1`, and drops it when its work is done.
- [Macaw.Live.Manager.Reader](Macaw.Live.Manager.Reader.md): A source manager's window read through a visitor's overlay (spec/03 §2, macaw spec/13
§3.4). The managers and their table reads are macaw_data's (`Macaw.Data.Manager`,
`Macaw.Data.Manager.Reader`, macaw_data spec/01 §6.4, #137); this read stays here, since
it overlays with macaw (`Macaw.Overlay.read/4`), which macaw_data never calls.

- [Macaw.Live.Mounted](Macaw.Live.Mounted.md): The render-stable part of a mounted surface, in the socket's assigns as `@macaw`
(spec/01 §3): what a template reads.
- [Macaw.Live.Navigation](Macaw.Live.Navigation.md): The host's navigation behavior (spec/01 §9). **The library never navigates:** a
`navigate` action's step (`Macaw.Page.steps/2`, macaw spec/06 §5) goes to the behavior
named by the mount's `navigation:`, `{module, arg}`, after the event's state changes are
applied and their renders sent, so a pick that selects and then navigates shows the
selection on the page it leaves.
- [Macaw.Live.Navigation.Message](Macaw.Live.Navigation.Message.md): The default navigation behavior (spec/01 §9): each step sent to the page process as
`{:macaw_live, :navigate, target, params}`, which the runtime's `:handle_info` hook passes
on to the host's own `handle_info/2`. Sent after the event's renders, it reaches the host
after them. Its argument is unused.

- [Macaw.Live.Notify](Macaw.Live.Notify.md): The notification transport (spec/03 §7), a behavior over an argument
([macaw 00 goal 3](https://github.com/dcoai/macaw/blob/main/spec/00-overview.md#overview-goals)):
how a page hears "this source's data changed; re-read it", and how the runtime's own
broadcasts travel.
- [Macaw.Live.Notify.Local](Macaw.Live.Notify.Local.md): The default notification transport (spec/03 §7): this node only, through a `Registry`
of duplicate keys, the supervisor's `<live>.Topics`, its argument. A process subscribed
twice to one topic hears it once.

- [Macaw.Live.Notify.PubSub](Macaw.Live.Notify.PubSub.md): A notification transport over the host's `Phoenix.PubSub` (spec/03 §7), its argument
the PubSub's name: it reaches every node the host's PubSub does.
- [Macaw.Live.Page](Macaw.Live.Page.md): 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).
- [Macaw.Live.Proof](Macaw.Live.Proof.md): A cell's render, proved in a process of its own before the page renders it (spec/01
§3.3). Adapted from visualize's drawing process (`Visualize.Components.Chart`, D-206,
D-216): generic, its outcome a value, with no message text.
- [Macaw.Live.Proxy](Macaw.Live.Proxy.md): The one same-origin asset proxy (spec/06 §1): media a component needs from another
origin, map tiles first, fetched by the host's server so a page under `img-src 'self'`
holds same-origin paths only. Copied from visualize's `Visualize.TileProxy` (D-298) and
made generic: routes are components' declared `proxy_routes` by component, name and
digest, the enabled origins are the host's configuration value, never application
config, and every step is a value.
- [Macaw.Live.Proxy.Cache](Macaw.Live.Proxy.Cache.md): The proxy's cache by filled upstream URL (spec/06 §1.5), a behavior over an argument, so
a host of several nodes plugs a shared one. A host chooses it with the supervisor's
`proxy_cache:` option, `{module, arg}`; `Macaw.Live.Proxy.Cache.Memory`, the default, is
bounded by entries and bytes and drops the least recently used. A cache module
exporting `child_spec/1` is started under the supervisor with its argument and
`name: <live>.ProxyCache`, and that argument is the one its callbacks are given.
- [Macaw.Live.Proxy.Cache.Memory](Macaw.Live.Proxy.Cache.Memory.md): The proxy's default cache (spec/06 §1.5): an ETS table its process owns, started under
the host's `Macaw.Live.Supervisor` as `<live>.ProxyCache`, so the table is the
supervisor's. It holds at most `entries:` answers (10,000) and `bytes:` bytes of bodies
(256 MiB), dropping the least recently used past either; a body larger than `bytes:` is
never held. Reads go to the table directly and tell the process what was used; writes
go through the process. A stale entry is a miss, and dropped.

- [Macaw.Live.Proxy.Fetcher](Macaw.Live.Proxy.Fetcher.md): How the proxy fetches upstream (spec/06 §1.6), a behavior over an argument, so a test
passes a fetcher of its own and the proxy's suite reaches no network. Copied from
visualize's `Visualize.TileProxy.Fetcher`, now given the request's headers and bounds.
- [Macaw.Live.Proxy.Fetcher.Httpc](Macaw.Live.Proxy.Fetcher.Httpc.md): The default `Macaw.Live.Proxy.Fetcher` (spec/06 §1.6): OTP's `:httpc`, copied from
visualize's `Visualize.TileProxy.Fetcher.Httpc` and bounded.
- [Macaw.Live.Proxy.Fetcher.Httpc.Transport](Macaw.Live.Proxy.Fetcher.Httpc.Transport.md): What `Macaw.Live.Proxy.Fetcher.Httpc` performs its I/O through (spec/06 §1.6), a behavior
over an argument: `:httpc`'s asynchronous request and its cancel. The fetcher builds
everything else (the peer verification its `ssl` options give, no redirect, the headers,
the byte cap and the timeout), so a test hands it a transport of its own that records
what it was given and answers as `:httpc` would, and no socket opens.
`Macaw.Live.Proxy.Fetcher.Httpc.Transport.Inets`, OTP's `:httpc`, is the default.
- [Macaw.Live.Proxy.Fetcher.Httpc.Transport.Inets](Macaw.Live.Proxy.Fetcher.Httpc.Transport.Inets.md): The default `Macaw.Live.Proxy.Fetcher.Httpc.Transport`: OTP's `:httpc` on its default
profile, whose cookies are disabled unless a host enables them. Its argument is unused.

- [Macaw.Live.Proxy.Plug](Macaw.Live.Proxy.Plug.md): The asset proxy's plug (spec/06 §1.1), which a host mounts once with its configuration
built at boot
- [Macaw.Live.Pulse](Macaw.Live.Pulse.md): The page's pulse (spec/03 §3): a change reaches the cells in ranked pulses, as the core's
page DAG carries it ([macaw spec/03 §6](https://github.com/dcoai/macaw/blob/main/spec/03-state.md#state-dag)).
Adapted from visualize's `Visualize.Board.Server` pulse timer: the marks waiting, when the
pulse is due, and its stages in rank order, over the core's values.
- [Macaw.Live.Reader](Macaw.Live.Reader.md): macaw's `Macaw.Surface.Reader` over the host's source managers (spec/03 §9, macaw#443):
how a socketless render (`Macaw.Surface.fetch/2`), `Macaw.Surface.legal/2` and
`Macaw.Page.check/3` read a source from the manager that holds it, so a request reads a
source once and the connected mount after it finds the manager warm.
- [Macaw.Live.Region](Macaw.Live.Region.md): A persistent region's sticky LiveView (spec/04 §3, macaw spec/06 §4): a process of its
own that survives live navigation between pages sharing the region, its components
keeping their processes and state, and focus inside it kept.
- [Macaw.Live.Renders](Macaw.Live.Renders.md): 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.
- [Macaw.Live.Renders.Memory](Macaw.Live.Renders.Memory.md): The render memo's default (spec/01 §3.4): an ETS table its process owns, started under
the host's `Macaw.Live.Supervisor` as `<live>.Renders`, so the table is the
supervisor's. It holds at most `entries:` renders (10,000) and `bytes:` bytes of markup
(256 MiB), dropping the oldest past either; a render larger than `bytes:` is never
held. Reads go to the table directly and send nothing; writes go through the process.
The markup is held as the binaries the proof wrote, so a read copies their references.
- [Macaw.Live.Scopes](Macaw.Live.Scopes.md): Where each scope's values live (spec/04 §5), and the owner's side of a scope held for
several surfaces' states. macaw gives the pure functions (macaw spec/03 §2.1); this
module decides which process holds what, calling them and never reimplementing them.
- [Macaw.Live.Shared](Macaw.Live.Shared.md): The owner of one surface instance's `:shared` state (spec/04 §4), across every viewer's
process: a wall display's selection, set by anyone watching it, seen by everyone. New:
visualize's shared board state lived in `Visualize.Board.Server`, not carried over.
- [Macaw.Live.Shortcuts](Macaw.Live.Shortcuts.md): The page-shortcut registry and its dialog (spec/05 §6). Page-wide shortcuts go only
through it: each mounted cell's declared shortcuts (`%{key, action, description}`,
macaw_component spec/01 §1.6), each entry identified as `"<instance>.<action>"`, and the
runtime's own help entry, `"mw-live.help"` on `?`.
- [Macaw.Live.Specs.Batch](Macaw.Live.Specs.Batch.md): The contained cell's batch protocol (spec/02 §3), modeled so every ordering it reaches is
checked (spec/00 §3). The page holds the latest input (`arrived`, newer inputs numbered
in order) and sends it to the cell as a batch only when none is in flight; the cell
takes its mailbox in order and answers each batch with its sequence; the page takes an
answer only for the sequence in flight. The cell may crash at any point: its mailbox is
lost, its `:DOWN` follows its answers on the one channel to the page (the BEAM's order
between a pair of processes), and the page restarts it with the latest input as its
first batch, sequence 1 again (spec/02 §5).
- [Macaw.Live.Specs.Edge](Macaw.Live.Specs.Edge.md): The edge protocol (spec/04 §1), modeled so every ordering it reaches is checked (spec/00
§3). An owner publishes each change under the next sequence; a mirror applies the next
one it expects, ignores a repeat, and on a gap joins again and takes the owner's answer
whole. The owner may end and be restarted once: its `:DOWN` follows its publications on
the one channel to the mirror (the BEAM's order between a pair of processes), and the
mirror joins the restarted owner at it. The restarted owner's publications travel on a
channel of their own (`second`), in no order against the first owner's (`first`).
- [Macaw.Live.Specs.Turn](Macaw.Live.Specs.Turn.md): The turn's replay (spec/03 §2.1), modeled so every ordering it reaches is checked
(spec/00 §3). The page holds a monitor and changes it with edits (a push, an ask, a
budget); a tick runs in a turn on a copy of the monitor. While the turn runs, each edit
is made in the page's copy and kept, and when the turn answers, the kept edits are
replayed onto the monitor it answers. A tick asked while a turn runs runs once after it.
A turn past its liveness bound is killed: the page keeps its own copy, edits included,
and takes the killed turn's answer from its mailbox if it came before the `:DOWN`.
- [Macaw.Live.Stream](Macaw.Live.Stream.md): The binary stream (spec/05 §9): one Phoenix channel per page, beside its LiveView,
joined by the page's `MacawSurface` hook, carrying a contained value's changed drawing
segments as binary frames (`Macaw.Live.Stream.Frame`), so a live update sends its bytes
raw and its markup only each segment's key and token. The first render, and every render
while no channel is joined, carries the segments as base64 in markup, so a page without
a socket, or whose channel is refused, is complete and never fails (spec/00 §2). A
neutral or print render carries no stream and no drawing token: it is static (spec/05
§9.1).
- [Macaw.Live.Stream.Frame](Macaw.Live.Stream.Frame.md): One binary frame of the stream (spec/05 §9.2): a header naming the cell instance, the
drawing token, the segment key, the frame's sequence and the length of the bytes, then
the segment's raw bytes, never base64.
- [Macaw.Live.Supervisor](Macaw.Live.Supervisor.md): The supervisor a host adds to its tree; everything the runtime starts lives under it
(spec/01 §1). Copied from visualize's `Visualize.Board.Supervisor` and adapted: host-named,
its children fixed, and no application process.
- [Macaw.Live.Surface](Macaw.Live.Surface.md): The function component a template renders a mounted surface with (spec/01 §3.1), as
`Macaw.Live.surface/1`
- [Macaw.Live.Visit](Macaw.Live.Visit.md): The holder of a visit's `:session` state across live navigation (spec/04 §5): one per
transport, the LiveView socket every page of a browser tab's visit shares. New.
- [Macaw.Live.Visit.Budget](Macaw.Live.Visit.Budget.md): A visit's event budget (spec/01 §5.1): a token bucket that bounds how fast one visitor's
events are acted on, so a host taking events from anonymous visitors needs no wrapper
around any of them.

## Mix Tasks

- [mix macaw_live.bench](Mix.Tasks.MacawLive.Bench.md): Runs `Macaw.Live.Bench` over spec/07's scenarios (spec/07 §8) and prints, per scenario,
the median and range of its reductions per process, the diff's bytes, the crossings'
flat sizes, and the milliseconds of work, reported and never asserted.

