@metreeca/core - v0.9.17
    Preparing search index...

    Type Alias Manager<T>

    State manager.

    Provides housekeeping operations for state instances, including snapshotting, restoration, and observer management. See module documentation for detailed usage examples.

    type Manager<T extends State> = {
        capture(): Version<T>;
        restore(snapshot: Version<T>): T;
        attach(observer: Observer<T>): T;
        detach(observer: Observer<T>): T;
    }

    Type Parameters

    • T extends State

      The state type this manager is attached to

    Index

    Methods

    • Captures a snapshot of the current version.

      Returns a snapshot containing only the data properties, excluding transition methods and observers. Useful for persistence, undo/redo, or time-travel debugging.

      Returns Version<T>

      Snapshot of the current version

    • Restores a state from a snapshot.

      Returns a new state with version data restored from the snapshot. Transition methods and observers are preserved.

      Parameters

      • snapshot: Version<T>

        Snapshot created by calling capture() on this State or a related state

      Returns T

      A new state with restored version data

    • Attaches an observer.

      Returns a new state with the observer attached. Observers are notified asynchronously when transitions occur. Observer errors are caught and silently ignored.

      The operation is idempotent - attaching an already-attached observer returns the same State reference. Observer identity is determined by reference equality (===).

      Parameters

      • observer: Observer<T>

        Function called with the new version after each transition

      Returns T

      A new state with observer attached, or same reference if already attached

    • Detaches an observer.

      Returns a new state with the observer detached.

      The operation is idempotent - detaching a non-attached observer returns the same State reference. Observer identity is determined by reference equality (===).

      Parameters

      • observer: Observer<T>

        Function to remove from observers

      Returns T

      A new state with observer detached, or same reference if not attached