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.
- It is registered by its transport's pid in the supervisor's
Registry, as{:visit, transport_pid}, and started under<live>.Ownersby the first page of the transport that mounts a surface declaring:sessionstate (ensure/3); racing pages take the one started first. It ends with the transport, which it monitors. - Its instance (
Macaw.State.new/2'sinstances: %{session: …}) is a token it makes at its start, so no two visits' values meet under one identity. - Pages join its edge with their surfaces' states (
join/4), each registered (Macaw.Live.Scopes.register/3) and put the visit's values before its first render. A live navigation ends the old page and joins the new one to the same visit, so a:sessionvalue written on one page is read on the next. - A page's event is applied by the page to the scopes it holds and sent here
(
apply/3, a cast); the visit applies it withscopes: [:session]in arrival order, puts the change into every other surface's state it holds, and publishes it to every joined page directly,{:macaw_live, :edge, {:session, transport_pid}, seq, values}. No page applies a:sessionwrite itself. - Restored at its start and written after each change through the host's
persistence (
persistence:,[module: module, carrier: carrier]): a surface's:sessionvalues are restored from the carrier when the surface first joins (Macaw.Live.Scopes.restore/4), and every change writes that surface's:sessionvalues into it (Macaw.Live.Scopes.persist/4). The carrierstore/3answers is the one the next write takes, andinfo/1gives it. - A visitor's changes to a source's rows are held here (macaw spec/13 §3, #94):
each surface's overlay of each source its
addandremoveactions change, at:sessionscope under{:overlay, source}(Macaw.Live.Scopes.held/2). Anadd, aremoveand areset: :allare applied here as a:sessionwrite is, and the overlay published to every joined page, which applies it to its reads; so a visit's changes survive its live navigations and end with it. An overlay its host's policy holdsheld: :sessionis written and restored through the host's persistence too; one held:visit, the default, only lives here. - Faults of an event (a value its declaration refuses, a row its policy refuses)
change nothing and are reported in
info/1. - A crashed visit is restarted by
Ownersand restores from the carrier it was started with; its pages' mirrors rejoin and take its values whole.
Summary
Functions
A page's event sent to the visit, which applies it with scopes: [:session] to the
surface's state in arrival order: :ok, never waiting. legal is the legal values the
page read for it, as Macaw.Live.Scopes.forward/5 takes them.
Returns a specification to start this module under a supervisor.
The visit of transport under the supervisor live, started when none runs: {:ok, pid}, the one started first when two pages race, or {:error, reason}. opts:
persistence:, nil or [module: module, carrier: carrier].
The visit's present state: its key, instance, sequence, :session values by name (each
overlay it holds among them, under {:overlay, source}), the
pages joined, the surfaces registered, the faults of the events it refused in arrival
order and its persistence's carrier. {:ok, info}, or {:error, reason}.
A page pid joins the visit for its surface's state: {:ok, %{id: id, seq: seq, values: values}}, the visit's instance and every current :session value by name, or {:error, reason} ({:down, reason}, :timeout, as Macaw.Live.Edge.join/3 answers). The visit
registers the state, restoring its :session values from the carrier the first time
the surface joins, and monitors the page.
The edge key of a transport's visit.
A page leaves the visit: :ok, never waiting.
The visit of transport under the supervisor live, or nil when none runs.
Types
@type key() :: {:session, pid()}
A visit's edge key: {:session, transport_pid}.
Functions
@spec apply(pid(), String.t(), Macaw.Data.Event.t(), map()) :: :ok
A page's event sent to the visit, which applies it with scopes: [:session] to the
surface's state in arrival order: :ok, never waiting. legal is the legal values the
page read for it, as Macaw.Live.Scopes.forward/5 takes them.
Returns a specification to start this module under a supervisor.
See Supervisor.
The visit of transport under the supervisor live, started when none runs: {:ok, pid}, the one started first when two pages race, or {:error, reason}. opts:
persistence:, nil or [module: module, carrier: carrier].
The visit's present state: its key, instance, sequence, :session values by name (each
overlay it holds among them, under {:overlay, source}), the
pages joined, the surfaces registered, the faults of the events it refused in arrival
order and its persistence's carrier. {:ok, info}, or {:error, reason}.
A page pid joins the visit for its surface's state: {:ok, %{id: id, seq: seq, values: values}}, the visit's instance and every current :session value by name, or {:error, reason} ({:down, reason}, :timeout, as Macaw.Live.Edge.join/3 answers). The visit
registers the state, restoring its :session values from the carrier the first time
the surface joins, and monitors the page.
The edge key of a transport's visit.
A page leaves the visit: :ok, never waiting.
The visit of transport under the supervisor live, or nil when none runs.