Table of Contents

Class Store<TState>

Namespace
Velvet
Assembly
Velvet.Docs.dll

State container for immutable state, collocated actions, and synchronous change notifications.

public abstract class Store<TState> : IStoreWriter<TState>

Type Parameters

TState

Immutable state record type.

Inheritance
object
Store<TState>
Implements
IStoreWriter<TState>

Remarks

Stores are single-threaded. Reads, mutations, and subscription changes must occur on the Unity main thread.

Do not mutate the store from a state-change notification. The pass reads the current value per listener rather than the one it started with, so a nested mutation leaves every listener after the mutating one never called with the outer state and called twice with the inner one. Defer the update until notification completes. Listener exceptions propagate and stop the current notification pass.

Constructors

Store(TState)

Properties

CancellationToken

Cancelled when the store is disposed. Subclasses can thread this through async work so in-flight operations observe disposal.

Current
InitialState

The construction value, unchanged when Current changes.

Logger

Logger captured from Default at construction. See StoreLogger to suppress output in tests.

Methods

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

Mutate(Func<TState, TState>)

Updates state without an equality check.

OnDispose()

Subclass-specific dispose logic (overridable). The state notifier is already disposed at this point and must not be accessed. Subscriptions a subclass opened via Subscribe(Action<TState>, bool) / Select<T>(Func<TState, T>, Action<T, T>, IEqualityComparer<T>?, bool) are owned by the subclass and should be disposed here.

Reset()

Resets state to the initial value unless the store has been disposed.

ResetCore()
Select<T>(Func<TState, T>, Action<T, T>, IEqualityComparer<T>?, bool)

Subscribes to a selected slice with a (currentSlice, previousSlice) signature. The listener fires only when the selected slice changes under the given comparer.

SetState(Func<TState, TState>)

Updates state (equality-checked).

Subscribe(Action<TState, TState>, bool)

Subscribes to state changes with a (current, previous) signature.

Subscribe(Action<TState>, bool)

Subscribes to state changes.