state

package
v0.1.63 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MustRemember

func MustRemember[T any](c SupportState, key string, calc func() T) T

func NotifyRead added in v0.1.61

func NotifyRead(source any)

NotifyRead notifies the active read observer that a state object has been read. Source is typically the state object itself (e.g. *MutableValue).

func Remember

func Remember[T any](c SupportState, key string, calc func() T) (T, error)

func RememberUnsafe

func RememberUnsafe[T any](c SupportState, key string, calc func() T) T

func WithReadObserver added in v0.1.61

func WithReadObserver(observer ReadObserver, block func())

WithReadObserver executes the block with the given read observer. It restores the previous observer after the block finishes.

Types

type DerivedState added in v0.1.61

type DerivedState[T any] struct {
	// contains filtered or unexported fields
}

func DerivedStateOf added in v0.1.61

func DerivedStateOf[T any](calculation func() T) *DerivedState[T]

func DerivedStateOfCustom added in v0.1.61

func DerivedStateOfCustom[T any](calculation func() T, compare func(T, T) bool) *DerivedState[T]

DerivedStateOfCustom allows providing a custom comparison function

func (*DerivedState[T]) Get added in v0.1.61

func (ds *DerivedState[T]) Get() T

func (*DerivedState[T]) Version added in v0.1.61

func (ds *DerivedState[T]) Version() int64

type Memo

type Memo = immap.ImmutableMap[any]

type MemoTyped

type MemoTyped[T any] = immap.ImmutableMap[T]

func EmptyMemo

func EmptyMemo[T any]() MemoTyped[T]

type MutableValue

type MutableValue interface {
	Value
	Set(value any)
}

type PersistentState

type PersistentState interface {
	GetState(key string, initial func() any) MutableValue
	SetOnStateChange(callback func())
}

type ReadObserver added in v0.1.61

type ReadObserver func(source any)

type SupportState

type SupportState interface {
	Remember(key string, calc func() any) any          // transient state
	State(key string, initial func() any) MutableValue // persistent state
}

type TypedMutableValue

type TypedMutableValue[T any] interface {
	TypedValue[T]
	Set(value T)

	Unwrap() MutableValue
}

type TypedValue

type TypedValue[T any] interface {
	Get() T
}

type Value

type Value interface {
	Get() any
}

type Versionable added in v0.1.61

type Versionable interface {
	Version() int64
}

Jump to

Keyboard shortcuts

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