removeNode method
Removes the node specified at path.
Implementation
@override
void removeNode(String path, {bool recurse = true}) {
if (path == '/' || !path.startsWith('/')) return;
var node = getNode(path) as SimpleNode?;
if (node == null) {
return;
}
if (recurse) {
var base = path;
if (!base.endsWith('/')) {
base += '/';
}
var baseSlashFreq = countCharacterFrequency(base, '/');
var targets =
nodes.keys.where((String x) {
return x.startsWith(base) &&
baseSlashFreq == countCharacterFrequency(x, '/');
}).toList();
for (var target in targets) {
removeNode(target);
}
}
var p = Path(path);
var pnode = getNode(p.parentPath) as SimpleNode?;
node.onRemoving();
node.removed = true;
if (pnode != null) {
pnode.children.remove(p.name);
pnode.onChildRemoved(p.name, node);
pnode.updateList(p.name);
}
if (node.callbacks.isEmpty && !node._hasListListener) {
nodes.remove(path);
} else {
node._stub = true;
}
}