# `Dala.Node`
[🔗](https://github.com/manhvu/dala/blob/main/lib/dala/node.ex#L1)

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.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"}}
      ]
    }

# `t`

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

# `compute_layout_hash`

```elixir
@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`

```elixir
@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.Node.from_map(%{
      type: :text,
      props: %{text: "Hello"},
      children: []
    }, "parent:0")

# `stable_id`

```elixir
@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.
Results are cached in an ETS table so repeated lookups for the same ID
(which is the common case across renders) are O(1) map reads instead of
full SHA-256 computation.

# `to_map`

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

Convert a Node struct back to a map representation.

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

---

*Consult [api-reference.md](api-reference.md) for complete listing*
