state

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package state provides page-level shared state management with dot-path access and subscription-based change notification.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store is a concurrency-safe key-value store with dot-path access.

func New

func New() *Store

New creates an empty state store.

func (*Store) AsContext

func (s *Store) AsContext() map[string]any

AsContext returns the values map for use as an expression context. The returned map is the live reference (caller must hold no write lock).

func (*Store) Get

func (s *Store) Get(path string) (any, bool)

Get retrieves a value by dot-path. Returns the value and whether it was found.

func (*Store) Load

func (s *Store) Load(initial map[string]any)

Load bulk-loads initial state, replacing any existing values.

func (*Store) Set

func (s *Store) Set(path string, value any)

Set writes a value at the given dot-path, creating intermediate maps as needed. Notifies all matching watchers.

func (*Store) Snapshot

func (s *Store) Snapshot() map[string]any

Snapshot returns a deep copy of all state values.

func (*Store) Subscribe

func (s *Store) Subscribe(pathPrefix string, fn func(key string, value any)) func()

Subscribe registers a callback for changes at or under pathPrefix. Returns an unsubscribe function.

func (*Store) Toggle

func (s *Store) Toggle(path string) error

Toggle flips a boolean value at the given path.

Jump to

Keyboard shortcuts

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