tree

package
v0.0.0-...-b5b2f04 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 21, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package tree provides a generic Node interface to build tree data structures.

Index

Constants

This section is empty.

Variables

View Source
var BeforeMountEventType = events.NewType("BeforeMountNode")
View Source
var BeforeUnmountEventType = events.NewType("BeforeUnmountNode")
View Source
var MountedEventType = events.NewType("MountedNode")
View Source
var UnmountedEventType = events.NewType("UnmountedNode")

Functions

func BeforeMountEventListener

func BeforeMountEventListener(handler func(BeforeMountEvent)) (events.Type, events.Handler)

BeforeMountEventListener returns an events.Listener that will call the given handler on before mount node events.

func BeforeUnmountEventListener

func BeforeUnmountEventListener(handler func(BeforeUnmountEvent)) (events.Type, events.Handler)

BeforeUnmountEventListener returns an events.Listener that will call the given handler on before unmount node events.

func IsRoot

func IsRoot[T events.Target](n Node[T]) bool

IsRoot returns whether a node is a root node.

func MountedEventListener

func MountedEventListener(handler func(MountedEvent)) (events.Type, events.Handler)

MountedEventListener returns an events.Listener that will call the given handler on mounted node events.

func UnmountedEventListener

func UnmountedEventListener(handler func(UnmountedEvent)) (events.Type, events.Handler)

UnmountedEventListener returns an events.Listener that will call the given handler on unmounted node events.

Types

type BeforeMountEvent

type BeforeMountEvent struct {
	events.Event
}

BeforeMountEvent is dispatched before a node is mounted into a parent node.

func (BeforeMountEvent) WithTarget

func (bme BeforeMountEvent) WithTarget(t events.Target) events.Event

WithTarget implements events.Event.

type BeforeUnmountEvent

type BeforeUnmountEvent struct {
	events.Event
}

BeforeUnmountEvent is dispatched before a node is unmounted from parent node.

func (BeforeUnmountEvent) WithTarget

func (bue BeforeUnmountEvent) WithTarget(t events.Target) events.Event

WithTarget implements events.Event.

type MountedEvent

type MountedEvent struct {
	events.Event
}

MountedEvent is dispatched after a node is mounted into a parent node.

func (MountedEvent) WithTarget

func (me MountedEvent) WithTarget(t events.Target) events.Event

WithTarget implements events.Event.

type Node

type Node[T NodeData] interface {
	UnwrapNode() *T
	ParentNode() *T
	RootNode() *T
	NextNode() *T
	PreviousNode() *T
	FirstChildNode() *T
	LastChildNode() *T
	AppendChildNode(*T) error
	InsertBeforeNode(newChild, reference *T) error
	RemoveChildNode(*T) error
	IsAncestorOfNode(*T) bool
	IsDescendantOfNode(*T) bool
}

func NewNode

func NewNode[T NodeData](data T) Node[T]

NewNode returns a new node containing the given data.

func NewRoot

func NewRoot[T events.Target](data T) Node[T]

NewRoot creates a new root node. Node are considered as mounted only if one of their ancestor is a root node.

type NodeData

type NodeData interface {
	events.Target
	// contains filtered or unexported methods
}

type UnmountedEvent

type UnmountedEvent struct {
	events.Event
}

UnmountedEvent is dispatched before a node is unmounted from parent node.

func (UnmountedEvent) WithTarget

func (ue UnmountedEvent) WithTarget(t events.Target) events.Event

WithTarget implements events.Event.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL