Manage the component tree with Node
mainThe Node struct represents a component in a tree structure. Each node contains a Content (which must satisfy the Control interface) and a slice of Children nodes. You can use Node to build and manage a hierarchical tree of components that can be mounted and updated.
Key behaviors:
- Mounting: Calling
Mount()on a node triggers a recursive mounting process where each component'sMountmethod is called with its parent as the argument. - Updating: The
Updatemethod allows you to synchronize an existing node tree with a new one. It performs efficient updates by attempting to callUpdateon existing components. If a component cannot be updated (i.e.,Updatereturnsfalse), it is unmounted (if it implementsUnmountable) and replaced with the new component.
type Node struct {
Content Control
Children []Node
}