addChild method
Add a node which has no children, don't change current parent node.
This method should be used to add leaf to parent. If for some reason
you need to go back to node added by this method use nextSibling and
prevSibling to navigate back. By default node added by this method
can't have children, trying add child will result in exception being
thrown. If for some reason this behaviour is not acceptable pass leaf
argument as false.
Consider tree:
S1
/ \
S2 S3
if S2 is current node, then call to this method will result in adding node S4 as shown below, but current node still is S2 (in contrast to push)
S1
/ \
S2 S3
/
S4
so calling it again will result in adding S5. For both S4 and S5 no
children should be added, if leaf
argument was false.
S1
/ \
S2 S3
/ \
S4 S5
Implementation
void addChild(PNDelegate delegate, dynamic data, {bool leaf = true}) {
var node = ProcessingNode(delegate, leaf ? const [] : [], data);
_current.children.add(node);
_parenthood[node] = _current;
}