Node constructor

Node({
  1. required String type,
  2. String? id,
  3. Node? parent,
  4. Attributes attributes = const {},
  5. Iterable<Node> children = const [],
})

Implementation

Node({
  required this.type,
  String? id,
  this.parent,
  Attributes attributes = const {},
  Iterable<Node> children = const [],
})  : _children = LinkedList<Node>()
        ..addAll(
          children.map(
            (e) => e..unlink(),
          ),
        ), // unlink the given children to avoid the error of "node has already a parent"
      _attributes = attributes,
      id = id ?? nanoid(6) {
  for (final child in children) {
    child.parent = this;
  }
}