Dala.Node (dala v0.0.13)

Copy Markdown View Source

Structured representation of a UI node in the Dala framework.

This is a public API wrapper around Dala.Ui.Node. The struct definition mirrors Dala.Ui.Node so that %Dala.Node{} and %Dala.Ui.Node{} are compatible.

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.Node structs

Example

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

Summary

Functions

Compute the layout hash for a node.

Creates a node struct from a map representation.

Compute a stable numeric u64 ID by hashing the string/atom ID.

Convert a node struct back to a map representation.

Types

t()

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

Functions

compute_layout_hash(node)

@spec compute_layout_hash(t()) :: non_neg_integer()

Compute the layout hash for a node.

The layout hash is computed from the node type, layout-relevant props (width, height, padding, flex_grow, flex_direction, justify_content, align_items), and the number of children. Uses SHA-256 and takes the first 8 bytes as a big-endian unsigned 64-bit integer.

from_map(map, default_id)

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

Creates a node struct from a map representation.

The map should have :type and :props keys. Optionally :id and :children. If :id is not provided, it will be generated from the parent id and child index.

stable_id(id)

@spec stable_id(String.t() | atom()) :: non_neg_integer()

Compute a stable numeric u64 ID by hashing the string/atom ID.

Uses SHA-256 and takes the first 8 bytes as a big-endian unsigned 64-bit integer. This matches the hash_id function in Dala.Ui.Renderer.

to_map(node)

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

Convert a node struct back to a map representation.