AshSDUI.Binding (ash_sdui v0.2.0)

Copy Markdown View Source

Generic data binding model for views.

Bindings describe where data comes from. The current implementation supports planning and basic runtime loading for Ash resources, relationships, and assigns, while staying small enough to compose declaratively in the SDUI DSL.

Summary

Functions

Normalizes an incoming live update and applies it to the current binding value.

Loads binding values that require an Ash read.

Builds a loading plan for a list of bindings.

Normalizes a binding source into a concrete runtime binding.

Returns true when a message matches a binding subscription spec.

Returns normalized subscription specs for bindings that can update live.

Types

t()

@type t() :: %AshSDUI.Binding{
  default: term(),
  many?: boolean(),
  name: atom(),
  query: AshSDUI.Query.t() | atom() | nil,
  refresh: term(),
  source: term(),
  source_kind: atom(),
  source_meta: term(),
  status: atom(),
  subscription: map() | nil,
  update: term(),
  update_strategy: atom() | term(),
  value: term()
}

Functions

apply_update(binding, current, message)

@spec apply_update(t(), term(), term()) :: {:ok, term(), map()} | {:error, term()}

Normalizes an incoming live update and applies it to the current binding value.

load(bindings, opts \\ [])

@spec load(
  [t()],
  keyword()
) :: {:ok, map()} | {:error, term()}

Loads binding values that require an Ash read.

normalize_update_strategy(strategy)

plan(bindings, context \\ nil)

@spec plan([struct() | map()], AshSDUI.Context.t() | map() | keyword() | nil) :: [t()]

Builds a loading plan for a list of bindings.

resolve(binding, context \\ nil)

@spec resolve(struct() | map(), AshSDUI.Context.t() | map() | keyword() | nil) :: t()

Normalizes a binding source into a concrete runtime binding.

subscription_match?(binding, message)

@spec subscription_match?(t(), term()) :: boolean()

Returns true when a message matches a binding subscription spec.

subscription_specs(bindings, opts \\ [])

@spec subscription_specs(
  [t()],
  keyword()
) :: [map()]

Returns normalized subscription specs for bindings that can update live.