Macaw.Live.Region (macaw_live v0.1.0)

Copy Markdown View Source

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 as Macaw.Live.mount/3 mounts them, with its own monitors, cells and pulses.
  • It registers by its transport, {:region, transport_pid, name} in the supervisor's Registry, 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 :page state (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 :region state lives here, each surface's instance the region's name: two of its surfaces declaring one :region name hold one value. It applies an event to :surface, :region and :viewer state itself (Macaw.Live.Scopes.held(:region)) and sends a :page write to the page, a :session write to the visit and a :shared write 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 :DOWN and keeps its mirrors' values, and takes the next page's content when it is told: each surface it keeps follows Macaw.Region.kept(region, :navigate) with Macaw.State.follow/3, its :page values back at their initial values under the next page's path, then joins the next page's edges and takes their values whole. Its :surface and :region state, 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 :surface and :region state 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 :region state 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

live_render(socket, name)

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.