admin.go has infrastructure code outside of the [Node] interface. New returns a new node of the given type with the given optional parent. If the name is unspecified, it defaults to the ID (kebab-case) name of the type, plus the [Node.NumLifetimeChildren] of the parent.
(parent ...Node)
| 20 | // If the name is unspecified, it defaults to the ID (kebab-case) name of |
| 21 | // the type, plus the [Node.NumLifetimeChildren] of the parent. |
| 22 | func New[T NodeValue](parent ...Node) *T { //yaegi:add |
| 23 | n := new(T) |
| 24 | ni := any(n).(Node) |
| 25 | InitNode(ni) |
| 26 | if len(parent) == 0 { |
| 27 | ni.AsTree().SetName(ni.AsTree().NodeType().IDName) |
| 28 | return n |
| 29 | } |
| 30 | p := parent[0] |
| 31 | p.AsTree().Children = append(p.AsTree().Children, ni) |
| 32 | SetParent(ni, p) |
| 33 | return n |
| 34 | } |
| 35 | |
| 36 | // NewOfType returns a new node of the given [types.Type] with the given optional parent. |
| 37 | // If the name is unspecified, it defaults to the ID (kebab-case) name of |