addWrite method
This write with node written at path.
Implementation
CompoundWrite addWrite(Path path, Node node) {
if (path.isEmpty) {
return CompoundWrite(ImmutableTree<Node>(node));
}
final PathAndValue<Node>? rootMost = writeTree.findRootMostValueAndPath(
path,
);
if (rootMost != null) {
final Path relativePath = Path.relative(rootMost.path, path);
Node value = rootMost.value;
final ChildKey? back = relativePath.back;
if (back != null && back.isPriorityKey) {
final Node target = value.getChild(relativePath.parent!);
if (!ChildrenNode.takesPriority(target)) {
// Ignore priority updates on empty nodes, except one that holds hidden state.
return this;
}
}
value = value.updateChild(relativePath, node);
return CompoundWrite(writeTree.set(rootMost.path, value));
}
return CompoundWrite(writeTree.setTree(path, ImmutableTree<Node>(node)));
}