addNode method
Adds a node at the given path that is initialized with the given data in m.
Implementation
@override
LocalNode? addNode(String path, Map m) {
if (path == '/' || !path.startsWith('/')) return null;
var p = Path(path);
var oldNode = _getNode(path, allowStubs: true) as SimpleNode?;
var pnode = getNode(p.parentPath) as SimpleNode?;
SimpleNode? node;
if (pnode != null) {
node = pnode.onLoadChild(p.name, m, this);
}
if (node == null) {
String? profile = m[r'$is'];
if (_profiles.containsKey(profile)) {
node = _profiles[profile]!(path) as SimpleNode?;
} else {
node = getOrCreateNode(path, true, false) as SimpleNode?;
}
}
if (oldNode != null) {
logger.fine('Found old node for $path: Copying subscriptions.');
for (var func in oldNode.callbacks.keys) {
node?.subscribe(func, oldNode.callbacks[func]!);
}
if (node is SimpleNode) {
try {
node._listChangeController = oldNode._listChangeController;
node._listChangeController?.onStartListen = () {
node?.onStartListListen();
};
node._listChangeController?.onAllCancel = () {
node?.onAllListCancel();
};
} catch (e) {}
if (node._hasListListener) {
node.onStartListListen();
}
}
}
nodes[path] = node!;
node.load(m);
node.onCreated();
if (pnode != null) {
pnode.addChild(p.name, node);
pnode.onChildAdded(p.name, node);
pnode.updateList(p.name);
}
node.updateList(r'$is');
if (oldNode != null) {
oldNode.updateList(r'$is');
}
return node;
}