Documentation
¶
Index ¶
- func MustRemember[T any](c state.SupportState, key string, calc func() T) T
- func Remember[T any](c state.SupportState, key string, calc func() T) (T, error)
- func RememberUnsafe[T any](c state.SupportState, key string, calc func() T) T
- type MutableValue
- type MutableValueInterface
- type MutableValueTyped
- type MutableValueTypedWrapper
- type MutableValueWrapper
- type PersistentState
- type PersistentStateInterface
- type StateOption
- type StateOptions
- type TypedMutableValueInterface
- func MustState[T any](c state.SupportState, key string, initial func() T, options ...StateOption[T]) TypedMutableValueInterface[T]
- func MutableValueToTyped[T any](mv *MutableValue) (TypedMutableValueInterface[T], error)
- func State[T any](c state.SupportState, key string, initial func() T, options ...StateOption[T]) (TypedMutableValueInterface[T], error)
- func StateUnsafe[T any](c state.SupportState, key string, initial func() T, options ...StateOption[T]) TypedMutableValueInterface[T]
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MustRemember ¶
func MustRemember[T any](c state.SupportState, key string, calc func() T) T
func RememberUnsafe ¶
func RememberUnsafe[T any](c state.SupportState, key string, calc func() T) T
Types ¶
type MutableValue ¶
type MutableValue struct {
// contains filtered or unexported fields
}
MutableValue is a state container that notifies subscribers when its value changes.
func NewMutableValue ¶
func (*MutableValue) Get ¶
func (mv *MutableValue) Get() any
func (*MutableValue) Set ¶
func (mv *MutableValue) Set(value any)
func (*MutableValue) Subscribe ¶ added in v0.1.67
func (mv *MutableValue) Subscribe(callback func()) state.Subscription
Subscribe registers a callback to be invoked when the value changes. Returns a Subscription that can be used to stop receiving notifications.
type MutableValueInterface ¶
type MutableValueInterface = state.MutableValue
func MutableValueTypedToUntyped ¶ added in v0.1.71
func MutableValueTypedToUntyped[T any](mv *MutableValueTyped[T]) MutableValueInterface
type MutableValueTyped ¶
type MutableValueTyped[T any] struct { // contains filtered or unexported fields }
MutableValue is a state container that notifies subscribers when its value changes.
func NewMutableValueTyped ¶
func NewMutableValueTyped[T any](initial T, changeNotifier func(T), compare func(T, T) bool) *MutableValueTyped[T]
func (*MutableValueTyped[T]) Get ¶ added in v0.1.71
func (mv *MutableValueTyped[T]) Get() T
func (*MutableValueTyped[T]) Set ¶ added in v0.1.71
func (mv *MutableValueTyped[T]) Set(value T)
func (*MutableValueTyped[T]) Subscribe ¶ added in v0.1.71
func (mv *MutableValueTyped[T]) Subscribe(callback func()) state.Subscription
Subscribe registers a callback to be invoked when the value changes. Returns a Subscription that can be used to stop receiving notifications.
func (*MutableValueTyped[T]) Unwrap ¶ added in v0.1.71
func (mv *MutableValueTyped[T]) Unwrap() MutableValueInterface
type MutableValueTypedWrapper ¶
type MutableValueTypedWrapper[T any] struct { // contains filtered or unexported fields }
func (*MutableValueTypedWrapper[T]) Get ¶
func (w *MutableValueTypedWrapper[T]) Get() T
func (*MutableValueTypedWrapper[T]) Set ¶
func (w *MutableValueTypedWrapper[T]) Set(value T)
func (*MutableValueTypedWrapper[T]) Subscribe ¶ added in v0.1.67
func (w *MutableValueTypedWrapper[T]) Subscribe(callback func()) state.Subscription
func (*MutableValueTypedWrapper[T]) Unwrap ¶
func (w *MutableValueTypedWrapper[T]) Unwrap() MutableValueInterface
type MutableValueWrapper ¶ added in v0.1.71
type MutableValueWrapper[T any] struct { // contains filtered or unexported fields }
func (*MutableValueWrapper[T]) Get ¶ added in v0.1.71
func (w *MutableValueWrapper[T]) Get() any
func (*MutableValueWrapper[T]) Set ¶ added in v0.1.71
func (w *MutableValueWrapper[T]) Set(value any)
func (*MutableValueWrapper[T]) Subscribe ¶ added in v0.1.71
func (w *MutableValueWrapper[T]) Subscribe(callback func()) state.Subscription
type PersistentState ¶
type PersistentState struct {
// contains filtered or unexported fields
}
func (*PersistentState) GetState ¶
func (ps *PersistentState) GetState(id string, initial func() any, options ...state.StateOption) MutableValueInterface
func (*PersistentState) SetOnStateChange ¶
func (ps *PersistentState) SetOnStateChange(callback func())
type PersistentStateInterface ¶
type PersistentStateInterface = state.PersistentState
func NewPersistentState ¶
func NewPersistentState(scopes map[string]MutableValueInterface) PersistentStateInterface
type StateOption ¶ added in v0.1.67
type StateOption[T any] func(*StateOptions[T])
func WithCompare ¶ added in v0.1.67
func WithCompare[T any](compare func(T, T) bool) StateOption[T]
type StateOptions ¶ added in v0.1.67
type TypedMutableValueInterface ¶
type TypedMutableValueInterface[T any] = state.TypedMutableValue[T]
func MustState ¶
func MustState[T any](c state.SupportState, key string, initial func() T, options ...StateOption[T]) TypedMutableValueInterface[T]
func MutableValueToTyped ¶ added in v0.1.71
func MutableValueToTyped[T any](mv *MutableValue) (TypedMutableValueInterface[T], error)
func State ¶
func State[T any](c state.SupportState, key string, initial func() T, options ...StateOption[T]) (TypedMutableValueInterface[T], error)
func StateUnsafe ¶
func StateUnsafe[T any](c state.SupportState, key string, initial func() T, options ...StateOption[T]) TypedMutableValueInterface[T]
Click to show internal directories.
Click to hide internal directories.