Macaw.Surface.Validated (macaw v0.6.0)

Copy Markdown View Source

A surface that passed the static pass (spec/06 §3.4), and what rendering needs of it: each cell's component module, validated settings and declarations, and each slot's source, description, resolved binding (Slot.resolve/3) and request params; layout the layout module and its checked options, from the host's registry; order is the cells in reading order.

Where state is bound is held here (spec/03 §1.4), so nothing walks the document again: a cell's bound is its settings bound to state, %{param => state}, and its actions its actions; a slot's bound is its request params bound to state, and a slot bound to a state source has {:state, name} as its source. A container cell's panes are its panes as built (spec/05 §5.1), by their surfaces' names, nil for any other cell.

A cell's settings are its stack (spec/07 §1.2): the preset it names, if any, then its own settings, judged as one; its stack is what that stack is made of, %{preset, own}, from which Macaw.Surface.explain_settings/2 builds its layers when it is asked, the component's defaults among them, never on a validation (#418).

A cell's component's default actions are resolved here (spec/03 §1.3): each that applies gives the cell a per-cell state <cell>.<param>, the parameter bound to it and the action setting it, so a cell's bound and actions are its explicit wiring. state is every state source of the surface, its declared ones and the per-cell ones, by name.

readers is each state's readers by its name, and each changed source's under {:overlay, source} (spec/13 §3.3), built here once (spec/03 §1.5): the slots a change of it fetches again and the cells it renders again, in reading order, so Macaw.State.affected/2 reads the changed names' entries and walks nothing.

identities is each cell the selection is handed to (spec/03 §1.7, §1.7.7), a cell whose slots' sources declare identity fields, :contained (through bound/3) or :pure (in its context): its identity fields by their canonical names through the surface's links (spec/03 §7), %{cell => %{canonical => [field]}}, each list in name order.

events is each cell by its instance id with what reading and applying its events needs (spec/03 §1.6), built here once: its declared events, the standard states it writes, its actions, and the type of each field its slots' schemas agree on. So Macaw.State.event/3 reads the one cell an event names, at the same cost on any number of cells.

exports is every export of the surface and its cells by name, each the name of the state it makes public (spec/03 §5.1), judged against the state the surface holds.

rendering is what each cell's render reads that no env changes (spec/06 §3.6), by its name, built here once: its instance id, its layout's classes, and its context's bindings and schemas, each slot's resolved binding and its source's schema, and prepared, what its component's prepare/2 built for the placement with what it was built from. So a render rebuilds none of them per call.

themes is the host's registry's themes by name (spec/12 §1.1), so a render resolves the viewer's theme preference (spec/03 §1.7.3) with no registry in hand.

A control cell's choices are the states it offers (spec/05 §6.7, Macaw.Control), each %{key, state}, nil for any other cell; offered is the values_from states among them, in name order, whose legal values a render reads when the host gives none.

changes is each source a cell's add or remove action changes (spec/13 §3), by its name, %{description:, cells:}: the description its slots read it by, and the cells whose actions change it, in reading order. Its readers are in readers under {:overlay, source}.

Rendering takes only a validated surface, so nothing renders that hasn't passed.

Summary

Types

cell()

@type cell() :: %{
  module: module(),
  kind: Macaw.Component.kind(),
  panes: [Macaw.Surface.Cell.pane(), ...] | nil,
  shows: boolean(),
  settings: map(),
  stack: %{preset: Macaw.Preset.t() | nil, own: map()},
  declarations: Macaw.Component.Declarations.t(),
  slots: %{required(String.t()) => slot()},
  bound: %{required(String.t()) => String.t()},
  actions: [Macaw.Surface.Cell.action()],
  choices: [%{key: String.t() | nil, state: String.t()}] | nil
}

rendering()

@type rendering() :: %{
  instance: String.t(),
  classes: String.t(),
  bindings: %{required(String.t()) => map()},
  schemas: %{required(String.t()) => Macaw.Data.Schema.t()},
  prepared: {map(), tuple(), term()} | nil
}

slot()

@type slot() :: %{
  source: String.t() | {:state, String.t()},
  description: Macaw.Data.Source.Description.t(),
  fields: map(),
  params: map(),
  bound: %{required(String.t()) => String.t()}
}

t()

@type t() :: %Macaw.Surface.Validated{
  cells: %{required(String.t()) => cell()},
  changes: %{
    required(String.t()) => %{
      description: Macaw.Data.Source.Description.t(),
      cells: [String.t(), ...]
    }
  },
  events: %{required(String.t()) => map()},
  exports: %{required(String.t()) => String.t()},
  identities: %{
    required(String.t()) => %{required(String.t()) => [String.t(), ...]}
  },
  layout: {module(), term()},
  offered: [String.t()],
  order: [String.t()],
  readers: %{required(String.t() | {:overlay, String.t()}) => map()},
  rendering: %{required(String.t()) => rendering()},
  state: %{required(String.t()) => Macaw.State.Source.t()},
  surface: Macaw.Surface.t(),
  themes: %{required(String.t()) => Macaw.Layers.Theme.t()}
}