The set of components on a surface, keyed by id.
An immutable collection: every function returns a new value. Adding an
id that already exists is a :state error (replacing is put/2);
removing an absent id is a no-op, as in the reference.
Iteration (to_list/1, ids/1) is in sorted id order, which keeps
graph validation deterministic.
iex> alias A2UICore.State.{Component, Components}
iex> {:ok, set} = Components.new() |> Components.add(Component.new("root", "Column"))
iex> Components.has?(set, "root")
true
iex> {:error, error} = Components.add(set, Component.new("root", "Text"))
iex> error.message
"Component with id 'root' already exists."
Summary
Functions
Adds a component; an existing id is a :state error.
Builds a set from components, the last one winning on a repeated id.
The component with id, or nil.
Whether a component with id exists.
The component ids, sorted.
An empty set.
Adds or replaces a component.
Removes a component (an absent id is ignored).
The number of components.
The components, sorted by id.
The component wire objects, sorted by id.
Types
@type t() :: %A2UICore.State.Components{ items: %{optional(String.t()) => A2UICore.State.Component.t()} }
Functions
@spec add(t(), A2UICore.State.Component.t()) :: {:ok, t()} | {:error, A2UICore.Error.t()}
Adds a component; an existing id is a :state error.
@spec from_list([A2UICore.State.Component.t()]) :: t()
Builds a set from components, the last one winning on a repeated id.
@spec get(t(), String.t()) :: A2UICore.State.Component.t() | nil
The component with id, or nil.
Whether a component with id exists.
The component ids, sorted.
@spec new() :: t()
An empty set.
@spec put(t(), A2UICore.State.Component.t()) :: t()
Adds or replaces a component.
Removes a component (an absent id is ignored).
@spec size(t()) :: non_neg_integer()
The number of components.
@spec to_list(t()) :: [A2UICore.State.Component.t()]
The components, sorted by id.
The component wire objects, sorted by id.