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.
The page's template renders it, once per persistent region, with live_render/2:
{Macaw.Live.Region.live_render(@socket, "sidebar")}which is live_render(socket, Macaw.Live.Region, id: "mw-region-<name>", sticky: true, session: %{"mw_region" => name, "mw_live" => live}). The session holds only the region's
name and the supervisor's; the page's document and env reach the region from the page,
never through the session, which is signed into the HTML.
- It holds its own
%Macaw.Live.Page{}of its surfaces, mounted asMacaw.Live.mount/3mounts them, with its own monitors, cells and pulses. - It registers by its transport,
{:region, transport_pid, name}in the supervisor'sRegistry, as the page registers by its ({:page, transport_pid}). Each finds the other there and nowhere else, and tells the other it is there; the region then asks the page for its content (its surfaces as the page validated them, the env they mount with, the page's DAG and its path) and joins the page's edges: its:pagestate (Macaw.Live.Scopes.join/5) and the exports its mirrors read. The page joins the exports the region's surfaces publish to its own mirrors. Each watches the other. - Its
:regionstate lives here, each surface's instance the region's name: two of its surfaces declaring one:regionname hold one value. It applies an event to:surface,:regionand:viewerstate itself (Macaw.Live.Scopes.held(:region)) and sends a:pagewrite to the page, a:sessionwrite to the visit and a:sharedwrite to its owner, taking each back from its owner's publication. - On live navigation the old page ends and the next registers. The region reads
the old page's
:DOWNand keeps its mirrors' values, and takes the next page's content when it is told: each surface it keeps followsMacaw.Region.kept(region, :navigate)withMacaw.State.follow/3, its:pagevalues back at their initial values under the next page's path, then joins the next page's edges and takes their values whole. Its:surfaceand:regionstate, its contained cells' processes and their values are untouched. - When the next page fills the region differently, the surfaces no longer in it are
unmounted and the new ones mounted. A surface that returns starts from its old state
as
Macaw.State.follow(old, Macaw.Region.kept(region, :refill), instances)keeps it: its:surfaceand:regionstate gone with the content, and the values the scopes' owners hold (:page,:session,:viewer,:shared) taken again when it joins them. - A crashed region is LiveView's to rejoin: it mounts again, finds its page and
joins its edges, its
:regionstate starting at its initial values.
Before the socket connects there is no transport to find the page by, so the region renders empty and fills once it connects.
Summary
Functions
The page template's render of the persistent region name: a sticky
live_render/3 of this LiveView, its session the region's name and the page's
supervisor. socket is the page's, mounted by Macaw.Live.mount_page/3.
Functions
@spec live_render(Phoenix.LiveView.Socket.t(), String.t()) :: Phoenix.LiveView.Rendered.t()
The page template's render of the persistent region name: a sticky
live_render/3 of this LiveView, its session the region's name and the page's
supervisor. socket is the page's, mounted by Macaw.Live.mount_page/3.