Macaw.Live.Page (macaw_live v0.1.0)

Copy Markdown View Source

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).

FieldHolds
surfacesby name: the validated surface, its Macaw.State, its env, its readers, and per cell its last proved assigns, its pending inputs, its process and restarts
sourcesby key, each source manager its readers subscribe to: its process, its monitor and the page's readers of it (spec/03 §2)
readerseach managed reader's name to its surface, cell and slot, its manager's key, and its window and budget (spec/03 §1)
pendingthe readers subscribed or moved whose manager hasn't answered yet (spec/03 §3)
refusedthe readers whose window their manager refused, each drawn down (spec/03 §8)
slidingthe readers of a sliding window, moved every tick: (spec/03 §2)
digestseach surface's sources' entries digested once, by surface and name, for their managers' keys
readseach managed reader's last read of its window, its status and delivery (spec/03 §2.1)
readingthe read turns running, by manager key (Page.Reads, spec/03 §2.1)
derivedby surface, the process running its derived sources (Macaw.Live.Derived), its key and monitor, when it declares them (spec/03 §3.1)
mirrorsthe values of other processes' nodes this page reads, each with its sequence (spec/04 §1)
scopesthe scopes past :surface and :shared (spec/04 §5): the visit joined for :session, the page's :page owner and its readers, and each surface's :viewer carrier
placefor a page Macaw.Live.mount_page/3 mounted or a persistent region, its place in the page DAG across processes: its holder, the graph, its exports edge and its readers, and the exports edges it reads (spec/04 §2, §3, §6)
pulsethe marks waiting for the next pulse and its timer, a Macaw.Live.Pulse (spec/03 §3)
waitingthe cells whose slots were asked or changed, rendered once none of their readers waits for its manager (spec/03 §3)
duethe page's next slide of its sliding readers, its monotonic ms and timer (spec/03 §2)
instanceseach mounted cell's instance id to its surface and cell
processeseach contained cell process's monitor to its instance (spec/02 §5)
nowthe instant of the last pulse (spec/01 §7)
configthe page's live settings, from its first mount: live:, clock:, tick:, timeout:, debounce:
turnedthe reductions its turns have spent, summed (spec/07 §0)
shortcutsthe shortcuts each mounted instance declares, the page's registry built from them and the viewer's shortcuts preference (spec/05 §6)
streama connected page's binary stream: its topic and token, and the joined channel's pid and monitor, or nil before it connects (spec/05 §9)
navigationby surface, the faults of the last navigation step of one of its cells that its behavior or Macaw.Page.steps/2 refused, gone once one succeeds (spec/01 §9)
themesby surface, the faults of the last relink of its theme sheet after its theme changed, gone once one succeeds (spec/06 §2.4)
budgetits visit's event budget, a Macaw.Live.Visit.Budget built from its event_budget: at its first client event; nil before it or for :unlimited (spec/01 §5.1)

It holds no copy of a value another place holds: a state's values are its Macaw.State's, a source's chunks its manager's, a delivery, once proved, its cell's assigns'.

This module holds the value and the runtime's LiveView hooks, routing each message to its concern: a surface's mount (Page.Mount), its cells built, proved and rendered (Page.Render), the runtime's events (Page.Events), its contained cells (Page.Contained), its :shared owners (Page.Mirrors), its scopes past :surface (Page.Scopes) and its place in the page DAG across processes (Page.Edges).

Summary

Types

A cell as the page holds it: its name, instance, module, kind and classes, the assigns it last rendered (proved, or tried and failed), what that proof rendered (placed, which its component places; nil for a crash and for a connected contained cell, whose component renders its process's proved value), the rows it keeps for its next proof (held, Macaw.Live.Keyed.kept/2, nil for a render that isn't keyed), the outcome of that proof (:loading for a contained cell whose process has not answered yet), the sequence its component last took, and for a contained cell its pending inputs, its process, its restarts and its run, the page's side of the process (spec/02 §3).

One mounted surface as the page holds it.

t()

Types

cell()

@type cell() :: %{
  name: String.t(),
  instance: String.t(),
  module: module(),
  kind: atom(),
  classes: String.t(),
  assigns: map(),
  placed: Macaw.Live.Proof.placed() | nil,
  held: Macaw.Live.Keyed.held() | nil,
  drawn: :ok | :loading | {:crashed, term()},
  seq: non_neg_integer(),
  pending: term(),
  pid: pid() | nil,
  restarts: non_neg_integer(),
  run: map() | nil
}

A cell as the page holds it: its name, instance, module, kind and classes, the assigns it last rendered (proved, or tried and failed), what that proof rendered (placed, which its component places; nil for a crash and for a connected contained cell, whose component renders its process's proved value), the rows it keeps for its next proof (held, Macaw.Live.Keyed.kept/2, nil for a render that isn't keyed), the outcome of that proof (:loading for a contained cell whose process has not answered yet), the sequence its component last took, and for a contained cell its pending inputs, its process, its restarts and its run, the page's side of the process (spec/02 §3).

surface()

@type surface() :: %{
  validated: Macaw.Surface.Validated.t(),
  state: Macaw.State.t(),
  env: keyword(),
  readers: %{required(String.t()) => [Macaw.Surface.reader_entry()]},
  order: [String.t()],
  cells: %{required(String.t()) => cell()},
  positions: %{required(String.t()) => non_neg_integer()},
  sizes: %{required(String.t()) => {number(), number()}},
  ratios: %{required(String.t()) => number()},
  font: number() | nil,
  plain: MapSet.t(String.t())
}

One mounted surface as the page holds it.

t()

@type t() :: %Macaw.Live.Page{
  budget: Macaw.Live.Visit.Budget.t() | nil,
  config: keyword(),
  derived: map(),
  digests: %{required({String.t(), String.t()}) => String.t()},
  due: %{required(term()) => {integer(), reference(), reference()}},
  hooks: [atom()],
  instances: %{required(String.t()) => {String.t(), String.t()}},
  mirrors: map(),
  navigation: %{required(String.t()) => [Macaw.Base.Fault.t(), ...]},
  now: DateTime.t() | nil,
  params: map(),
  params_done: boolean(),
  pending: MapSet.t(),
  place: map() | nil,
  processes: %{required(reference()) => String.t()},
  pulse: term(),
  readers: %{required(String.t()) => map()},
  reading: %{required(Macaw.Data.Manager.key()) => map()},
  reads: %{
    required(String.t()) =>
      {Macaw.Data.Manager.status(),
       Macaw.Live.Manager.Read.t() | Macaw.Data.Delivery.t() | nil}
  },
  refused: %{required(String.t()) => Macaw.Data.Manager.status()},
  scopes: map(),
  shortcuts: %{
    declared: %{required(String.t()) => [map()]},
    registry: Macaw.Live.Shortcuts.t() | nil,
    preference: Macaw.Live.Shortcuts.preference()
  },
  sliding: MapSet.t(),
  sources: %{required(Macaw.Data.Manager.key()) => map()},
  stream:
    %{
      topic: String.t(),
      token: String.t(),
      pid: pid() | nil,
      ref: reference() | nil
    }
    | nil,
  surfaces: %{required(String.t()) => surface()},
  themes: %{required(String.t()) => [Macaw.Base.Fault.t(), ...]},
  turned: non_neg_integer(),
  waiting: %{required({String.t(), String.t()}) => true}
}