onchangemap

package
v1.0.2-alpha.3 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithChangedCallback

func WithChangedCallback[K comparable, C constraints.ComparableStringer[K], I Item[K, C]](changedCallback func([]I) error) options.Option[OnChangeMap[K, C, I]]

WithChangedCallback is triggered when something in the OnChangeMap is changed (added/modified/deleted).

func WithItemAddedCallback

func WithItemAddedCallback[K comparable, C constraints.ComparableStringer[K], I Item[K, C]](itemAddedCallback func(I) error) options.Option[OnChangeMap[K, C, I]]

WithItemAddedCallback is triggered when a new item is added.

func WithItemDeletedCallback

func WithItemDeletedCallback[K comparable, C constraints.ComparableStringer[K], I Item[K, C]](itemDeletedCallback func(I) error) options.Option[OnChangeMap[K, C, I]]

WithItemDeletedCallback is triggered when an item is deleted.

func WithItemModifiedCallback

func WithItemModifiedCallback[K comparable, C constraints.ComparableStringer[K], I Item[K, C]](itemModifiedCallback func(I) error) options.Option[OnChangeMap[K, C, I]]

WithItemModifiedCallback is triggered when an item is modified.

Types

type Item

type Item[K comparable, C constraints.ComparableStringer[K]] interface {
	ID() C
	Clone() Item[K, C]
}

Item represents an item in the OnChangeMap.

type OnChangeMap

type OnChangeMap[K comparable, C constraints.ComparableStringer[K], I Item[K, C]] struct {
	// contains filtered or unexported fields
}

OnChangeMap is a map that executes callbacks if the map or an item is modified, in case callbackEnabled is true.

func NewOnChangeMap

func NewOnChangeMap[K comparable, C constraints.ComparableStringer[K], I Item[K, C]](opts ...options.Option[OnChangeMap[K, C, I]]) *OnChangeMap[K, C, I]

NewOnChangeMap creates a new OnChangeMap.

func (*OnChangeMap[K, C, I]) Add

func (r *OnChangeMap[K, C, I]) Add(item I) error

Add adds an item to the map.

func (*OnChangeMap[K, C, I]) All

func (r *OnChangeMap[K, C, I]) All() map[K]I

All returns a copy of all items.

func (*OnChangeMap[K, C, I]) CallbacksEnabled

func (r *OnChangeMap[K, C, I]) CallbacksEnabled(enabled bool)

CallbacksEnabled sets whether executing the callbacks on change is active or not.

func (*OnChangeMap[K, C, I]) Delete

func (r *OnChangeMap[K, C, I]) Delete(id C) error

Delete removes an item from the map.

func (*OnChangeMap[K, C, I]) ExecuteChangedCallback

func (r *OnChangeMap[K, C, I]) ExecuteChangedCallback() error

ExecuteChangedCallback calls the changedCallback if callbackEnabled is true.

func (*OnChangeMap[K, C, I]) Get

func (r *OnChangeMap[K, C, I]) Get(id C) (I, error)

Get returns a copy of an item.

func (*OnChangeMap[K, C, I]) Modify

func (r *OnChangeMap[K, C, I]) Modify(id C, callback func(item I) bool) (I, error)

Modify modifies an item in the map and returns a copy.

Jump to

Keyboard shortcuts

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