Dala.Ui.Node (dala v0.0.9)

Copy Markdown View Source

Structured representation of a UI node in the Dala framework.

Using a struct instead of raw maps provides:

  • Compile-time verification of field names
  • Default values for optional fields
  • Clear documentation of the node structure

Fields

  • :id — Stable identity for diffing (required for proper reconciliation)
  • :type — Atom indicating the component type (:text, :button, :column, etc.)
  • :props — Map of component-specific properties
  • :children — List of child Dala.Ui.Node structs

Example

%Dala.Ui.Node{
  id: "root",
  type: :column,
  props: %{padding: :md},
  children: [
    %Dala.Ui.Node{id: "t1", type: :text, props: %{text: "Hello"}},
    %Dala.Ui.Node{id: "b1", type: :button, props: %{title: "Click"}}
  ]
}

Summary

Functions

Create a new Node struct from a map.

Convert a Node struct back to a map representation.

Types

t()

@type t() :: %Dala.Ui.Node{
  children: [t()],
  id: String.t() | atom(),
  props: map(),
  type: atom()
}

Functions

from_map(map, default_id)

@spec from_map(map(), String.t()) :: t()

Create a new Node struct from a map.

Converts the map representation (used by Dala.Ui.Widgets functions) to a proper Node struct. Generates an ID if not present.

Example

Dala.Ui.Node.from_map(%{
  type: :text,
  props: %{text: "Hello"},
  children: []
}, "parent:0")

to_map(node)

@spec to_map(t()) :: map()

Convert a Node struct back to a map representation.

This is used before sending to the renderer/native side.