-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode.go
More file actions
42 lines (36 loc) · 1023 Bytes
/
node.go
File metadata and controls
42 lines (36 loc) · 1023 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package fairytale
import (
"github.com/gosimple/slug"
"github.com/macabot/hypp"
)
// Node in the navigation tree.
type Node[S hypp.State] interface {
Name() string
Slug() string
Children() []Node[S]
Tale() *Tale[S]
IsOpen() bool
SetIsOpen(bool)
}
var _ Node[struct{}] = &Bundle[struct{}]{}
// Bundle forms a bundle of Nodes.
type Bundle[S hypp.State] struct {
name string
slug string
children []Node[S]
isOpen bool
}
func (b Bundle[S]) Name() string { return b.name }
func (b Bundle[S]) Slug() string { return b.slug }
func (b Bundle[S]) Children() []Node[S] { return b.children }
func (b Bundle[S]) Tale() *Tale[S] { return nil }
func (b Bundle[S]) IsOpen() bool { return b.isOpen }
func (b *Bundle[S]) SetIsOpen(isOpen bool) { b.isOpen = isOpen }
// NewBundle creates a new Branch.
func NewBundle[S hypp.State](name string, children ...Node[S]) *Bundle[S] {
return &Bundle[S]{
name: name,
slug: slug.Make(name),
children: children,
}
}