Documentation
¶
Overview ¶
Package traverse implements an extensible interface that allows children widgets to announce state changes to their parent container.
The objective of this package is to allow for easier parent traversal without cluttering its structure with too much state. It also allows for proper encapsulation as well as a fallback mechanism without lengthy boolean checks.
Index ¶
- func Traverse(bc Breadcrumber, traverser func(b Breadcrumber) bool)
- func TryBreadcrumb(i Breadcrumber) (breadcrumbs []string)
- func TryID(i Breadcrumber, appended ...cchat.ID) (ids []cchat.ID)
- func TrySetUnread(parent Breadcrumber, selfID string, unread, mentioned bool)
- type BreadcrumbNamer
- type Breadcrumber
- type UnreadSetter
- type Unreadable
- type UnreadableState
- type Unreadabler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Traverse ¶
func Traverse(bc Breadcrumber, traverser func(b Breadcrumber) bool)
Traverse traverses the given breadcrumber recursively. If traverser returns true, then the function halts. Traversal is done from parent down to children.
func TryBreadcrumb ¶
func TryBreadcrumb(i Breadcrumber) (breadcrumbs []string)
TryBreadcrumb accepts a nilable breadcrumber and handles it appropriately.
func TrySetUnread ¶
func TrySetUnread(parent Breadcrumber, selfID string, unread, mentioned bool)
TrySetUnread tries to check if a breadcrumber parent node supports Unreadabler. If it does, then this function will set the state appropriately.
Types ¶
type BreadcrumbNamer ¶
type BreadcrumbNamer interface { // Breadcrumb returns the breadcrumb name. Breadcrumb() string }
type Breadcrumber ¶
type Breadcrumber interface { // Breadcrumb returns the parent's path before the children's breadcrumb. // This method recursively joins the parent's crumb with the children's, // then eventually make its way up to the root node. ParentBreadcrumb() Breadcrumber }
Breadcrumber is the base interface that other interfaces extend on. A child must at minimum implement this interface to use any other.
type UnreadSetter ¶
type UnreadSetter interface {
SetUnreadUnsafe(unread, mentioned bool)
}
UnreadSetter is an interface that a single row implements to set state. It does not have to do with Breadcrumber.
type Unreadable ¶
type Unreadable struct { UnreadableState // contains filtered or unexported fields }
Unreadable is a struct that nodes could embed to implement unreadable capability, that is, the unread and mentioned states. A zero-value Unreadable is a valid Unreadable without an update handler.
Typically, parent nodes would implement this as a way to count the number of unread and mentioned children nodes.
func NewUnreadable ¶
func NewUnreadable(unreadHandler UnreadSetter) *Unreadable
func (*Unreadable) SetState ¶
func (u *Unreadable) SetState(id string, unread, mentioned bool)
SetState updates the node ID's state in this parent unreadable state container.
func (*Unreadable) SetUnreadHandler ¶
func (u *Unreadable) SetUnreadHandler(updateHandler func(unread, mentioned bool))
SetUpdateHandler sets the parent's update handler. This update handler must refer to the parent's breadcrumb.
type UnreadableState ¶
type UnreadableState struct {
// contains filtered or unexported fields
}
UnreadableState implements a map of unread children for indication. A zero-value UnreadableState is a valid value.
func NewUnreadableState ¶
func NewUnreadableState() *UnreadableState
func (*UnreadableState) Reset ¶
func (s *UnreadableState) Reset()
func (*UnreadableState) SetState ¶
func (s *UnreadableState) SetState(id string, unread, mentioned bool)
func (*UnreadableState) State ¶
func (s *UnreadableState) State() (unread, mentioned bool)
type Unreadabler ¶
Unreadabler extends Breadcrumber to add unread states to the parent node.