Raxol.UI.Rendering.TreeDiffer (Raxol v0.5.0)

View Source

Provides functions to compute the difference (diff) between two UI trees. This module is responsible for identifying changes, additions, removals, and reordering of nodes, supporting both keyed and non-keyed children.

Summary

Functions

Computes the minimal set of changes (diff) between two UI trees.

Functions

diff_trees(old_tree, new_tree)

@spec diff_trees(old_tree :: map() | nil, new_tree :: map() | nil) ::
  :no_change | {:replace, map()} | {:update, [integer()], any()}

Computes the minimal set of changes (diff) between two UI trees.

Returns:

  • :no_change if trees are identical
  • if the root node differs significantly
  • for subtree updates. path is a list of indices to the parent node, and changes describes the modifications to its children (either as indexed diffs or keyed operations).

The path in {:update, path, changes} always refers to the parent node whose children have changed. For keyed children, the recursive diffs for individual children (e.g., in {:key_update, key, child_diff}) will have their own paths relative to that child (i.e., starting with [] if the child itself is the root of that sub-diff).