The viewer's preferences, standard state sources every surface holds (spec/03 §1.7.3):
theme, zone, units and shortcuts. They live at :viewer scope when the host
knows the viewer (Macaw.State.new/2's instances: gives :viewer) and at :session
otherwise, and they reach every component in its context, so one person's unit system
follows them across every component on every page they visit.
theme, the name of the theme the page renders in: a name, ornil, the host's default; the host swaps the root's theme class and gives the theme it names astheme:(spec/11);zone, a time zone name ("Europe/Paris"),"Etc/UTC"by default;units, a unit system, one ofMacaw.Format.Quantity.systems/0,:as_postedby default, given as the atom or its spelling;shortcuts, the page shortcuts the viewer has remapped or turned off, a map of an action's name to its key, orfalsefor off (the page-shortcut registry, spec/10),%{}by default.
Each is judged by its kind:
iex> Macaw.State.Preferences.judge("units", "metric")
{:ok, :metric}
iex> Macaw.State.Preferences.judge("zone", "")
{:error, {:type, :zone}}
Summary
Functions
The preferences a component's context carries (spec/03 §1.7.3), from a state's values:
%{zone, units, shortcuts}, as Macaw.Component.Context takes them.
Each preference's value before the viewer chooses one, by name.
A preference's value judged (spec/03 §1.7.3): {:ok, value}, nil its default, or
{:error, reason}: a theme that isn't a name {:type, :name}, a zone that isn't a zone's
name {:type, :zone}, units not a system {:enum, systems}, and shortcuts that aren't a
map of names to a key or false {:type, :shortcuts}.
The preferences' names, in name order.
The scope the preferences live at (spec/03 §2.1): :viewer when the host gives the
viewer's instance, :session otherwise.
Functions
The preferences a component's context carries (spec/03 §1.7.3), from a state's values:
%{zone, units, shortcuts}, as Macaw.Component.Context takes them.
Each preference's value before the viewer chooses one, by name.
A preference's value judged (spec/03 §1.7.3): {:ok, value}, nil its default, or
{:error, reason}: a theme that isn't a name {:type, :name}, a zone that isn't a zone's
name {:type, :zone}, units not a system {:enum, systems}, and shortcuts that aren't a
map of names to a key or false {:type, :shortcuts}.
@spec names() :: [String.t(), ...]
The preferences' names, in name order.
The scope the preferences live at (spec/03 §2.1): :viewer when the host gives the
viewer's instance, :session otherwise.