plushie/node

Tree node types for plushie’s UI tree.

PropValue is a JSON-like union representing wire-compatible values. Node is the fundamental tree building block: widget builders produce these, tree operations consume them, and the protocol encoder serializes them to wire format.

Types

A node in the UI tree. Produced by widget builders, consumed by tree operations and the protocol encoder.

  • id: widget identifier (scoped during normalization)
  • kind: widget type string (“button”, “column”, etc.)
  • props: encoded property values (string-keyed)
  • children: child nodes
  • meta: runtime-only metadata, never sent to the renderer
pub type Node {
  Node(
    id: String,
    kind: String,
    props: dict.Dict(String, PropValue),
    children: List(Node),
    meta: dict.Dict(String, PropValue),
  )
}

Constructors

  • Node(
      id: String,
      kind: String,
      props: dict.Dict(String, PropValue),
      children: List(Node),
      meta: dict.Dict(String, PropValue),
    )

    Arguments

    meta

    Runtime-only metadata. Not sent to the renderer. Used by the widget system for state/def storage during normalization. Widget builders should leave this as dict.new().

Value type for node props and meta. Most variants are wire-compatible (JSON/MessagePack). Widget builders convert typed Gleam values (Length, Padding, Color, etc.) into PropValue at build() time. OpaqueVal is runtime-only and encodes as null on the wire.

pub type PropValue {
  StringVal(String)
  IntVal(Int)
  FloatVal(Float)
  BoolVal(Bool)
  NullVal
  BinaryVal(BitArray)
  ListVal(List(PropValue))
  DictVal(dict.Dict(String, PropValue))
  OpaqueVal(dynamic.Dynamic)
}

Constructors

  • StringVal(String)
  • IntVal(Int)
  • FloatVal(Float)
  • BoolVal(Bool)
  • NullVal
  • BinaryVal(BitArray)

    Raw binary data. Encoded as base64 on the JSON wire format and as raw bytes on the MessagePack wire format.

  • ListVal(List(PropValue))
  • DictVal(dict.Dict(String, PropValue))
  • OpaqueVal(dynamic.Dynamic)

    Opaque runtime value. Used internally by the memo system and widget state storage. Never sent on the wire; the encoder ignores this variant.

Values

pub fn add_child(node: Node, child: Node) -> Node

Append a child to a node.

pub fn empty_container() -> Node

An empty container node, useful as a default root.

pub fn new(id: String, kind: String) -> Node

Create a node with no props and no children.

pub fn with_children(node: Node, children: List(Node)) -> Node

Replace a node’s children.

pub fn with_prop(
  node: Node,
  key: String,
  value: PropValue,
) -> Node

Set a single prop on a node.

pub fn with_props(
  node: Node,
  props: List(#(String, PropValue)),
) -> Node

Set multiple props on a node.

Search Document