calculateTreeDiff<T extends ITreeNode> function

List<TreeDiffNodeChange> calculateTreeDiff<T extends ITreeNode>(
  1. T oldTree,
  2. T newTree
)

Implementation

List<TreeDiffNodeChange> calculateTreeDiff<T extends ITreeNode>(
    T oldTree, T newTree) {
  final updates = <TreeDiffNodeChange>[];

  final queue = ListQueue<(INode, INode)>();
  queue.add((oldTree, newTree));

  while (queue.isNotEmpty) {
    final (oldTree, newTree) = queue.removeFirst();

    if (oldTree.childrenAsList.isEmpty && newTree.childrenAsList.isEmpty)
      continue;

    final localUpdates = TreeDiff(
      oldTree: oldTree as ITreeNode,
      newTree: newTree as ITreeNode,
    );

    updates.addAll(localUpdates.allUpdates);
    queue.addAll(localUpdates.nodesUnchanged);
  }

  return updates;
}