A2UICore.State.SurfaceGroup (A2UICore v0.1.1)

Copy Markdown View Source

All live surfaces of a session, keyed by surface id.

Lifecycle operations return the updated group and the effects a host may react to ({:surface_created, id}, {:surface_deleted, id}). Adding an existing id and deleting an unknown id are no-ops with no effects, as in the reference.

iex> alias A2UICore.State.{Surface, SurfaceGroup}
iex> {group, [{:surface_created, "main"}]} =
...>   SurfaceGroup.new() |> SurfaceGroup.add(Surface.new("main"))
iex> SurfaceGroup.ids(group)
["main"]
iex> {group, [{:surface_deleted, "main"}]} = SurfaceGroup.delete(group, "main")
iex> SurfaceGroup.ids(group)
[]

Summary

Functions

Adds a surface; an id already present is left untouched.

Deletes and disposes a surface; an unknown id is ignored.

Deletes every surface.

The surface with id, or nil.

Whether a surface with id exists.

The surface ids, sorted.

An empty group.

The surfaces, sorted by id.

Replaces an existing surface's state (after a data or component update). An unknown id is ignored.

Types

effect()

(since 0.1.0)
@type effect() :: {:surface_created, String.t()} | {:surface_deleted, String.t()}

t()

(since 0.1.0)
@type t() :: %A2UICore.State.SurfaceGroup{
  surfaces: %{optional(String.t()) => A2UICore.State.Surface.t()}
}

Functions

add(group, surface)

(since 0.1.0)
@spec add(t(), A2UICore.State.Surface.t()) :: {t(), [effect()]}

Adds a surface; an id already present is left untouched.

delete(group, id)

(since 0.1.0)
@spec delete(t(), String.t()) :: {t(), [effect()]}

Deletes and disposes a surface; an unknown id is ignored.

dispose(group)

(since 0.1.0)
@spec dispose(t()) :: {t(), [effect()]}

Deletes every surface.

get(surface_group, id)

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

The surface with id, or nil.

has?(surface_group, id)

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

Whether a surface with id exists.

ids(surface_group)

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

The surface ids, sorted.

new()

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

An empty group.

to_list(surface_group)

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

The surfaces, sorted by id.

update(group, surface)

(since 0.1.0)
@spec update(t(), A2UICore.State.Surface.t()) :: t()

Replaces an existing surface's state (after a data or component update). An unknown id is ignored.