A2UI.DataModel.Binding (A2UI v0.3.0)

Copy Markdown View Source

Resolves dynamic values in A2UI component props.

Values can be:

  • Literals — returned as-is
  • Path bindings (%{"path" => "/some/path"}) — resolved from the data model
  • Function calls (%{"call" => "formatNumber", ...}) — known functions evaluated server-side, unknown ones (e.g., openUrl, validators) returned as-is

Summary

Functions

Resolves a value against the data model.

Functions

resolve(value, data_model, scope_path \\ nil)

@spec resolve(any(), A2UI.DataModel.t(), String.t() | nil) :: {:ok, any()} | :error

Resolves a value against the data model.

Parameters

  • value — the raw prop value (literal, path binding, or function call)
  • data_model — the %DataModel{} to resolve paths against
  • scope_path — base path for relative path resolution (used in templates)

Examples

iex> dm = A2UI.DataModel.new(%{"user" => %{"name" => "Alice"}})
iex> A2UI.DataModel.Binding.resolve(%{"path" => "/user/name"}, dm)
{:ok, "Alice"}

iex> A2UI.DataModel.Binding.resolve("hello", A2UI.DataModel.new())
{:ok, "hello"}