A2UICore.State.Components (A2UICore v0.1.1)

Copy Markdown View Source

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

t()

(since 0.1.0)
@type t() :: %A2UICore.State.Components{
  items: %{optional(String.t()) => A2UICore.State.Component.t()}
}

Functions

add(set, component)

(since 0.1.0)
@spec add(t(), A2UICore.State.Component.t()) ::
  {:ok, t()} | {:error, A2UICore.Error.t()}

Adds a component; an existing id is a :state error.

from_list(components)

(since 0.1.0)
@spec from_list([A2UICore.State.Component.t()]) :: t()

Builds a set from components, the last one winning on a repeated id.

get(components, id)

(since 0.1.0)
@spec get(t(), String.t()) :: A2UICore.State.Component.t() | nil

The component with id, or nil.

has?(components, id)

(since 0.1.0)
@spec has?(t(), String.t()) :: boolean()

Whether a component with id exists.

ids(components)

(since 0.1.0)
@spec ids(t()) :: [String.t()]

The component ids, sorted.

new()

(since 0.1.0)
@spec new() :: t()

An empty set.

put(set, component)

(since 0.1.0)
@spec put(t(), A2UICore.State.Component.t()) :: t()

Adds or replaces a component.

remove(set, id)

(since 0.1.0)
@spec remove(t(), String.t()) :: t()

Removes a component (an absent id is ignored).

size(components)

(since 0.1.0)
@spec size(t()) :: non_neg_integer()

The number of components.

to_list(components)

(since 0.1.0)
@spec to_list(t()) :: [A2UICore.State.Component.t()]

The components, sorted by id.

trees(set)

(since 0.1.0)
@spec trees(t()) :: [map()]

The component wire objects, sorted by id.