didUpdateTree method

  1. @visibleForTesting
void didUpdateTree()
inherited

Implementation

@visibleForTesting
void didUpdateTree() {
  final treeDiff = calculateTreeDiff<ITreeNode<Data>>(_tree, widget.tree);
  if (treeDiff.isEmpty) return;

  for (final update in treeDiff) {
    switch (update) {
      case TreeDiffNodeAdd tree:
        {
          final node = tree.data as Tree;
          final parentNode = _tree
              .elementAt(node.parent?.path ?? node.root.path) as INodeActions;
          parentNode.add(node);
        }
      case TreeDiffNodeInsert tree:
        {
          final node = tree.data as Tree;
          final parentNode =
              _tree.elementAt(node.parent?.path ?? node.root.path)
                  as IIndexedNodeActions;
          parentNode.insert(tree.position, node as IndexedNode);
        }
      case TreeDiffNodeRemove tree:
        {
          final node = tree.data as Tree;
          final parentNode = _tree
              .elementAt(node.parent?.path ?? node.root.path) as INodeActions;

          parentNode.remove(node);
        }
      case TreeDiffNodeUpdate tree:
        {
          final node = tree.data as Tree;
          final oldNode = _tree.elementAt(node.path) as Tree;
          oldNode.data = node.data;
        }
    }
  }
}