@metreeca/core - v0.12.0
    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<T>> = {
        capture(): DeepReadonly<
            {
                [K in string
                | number
                | symbol as T[K] extends Function ? never : K]: T[K]
            },
        >;
        restore(
            snapshot: DeepReadonly<
                {
                    [K in string
                    | number
                    | symbol as T[K] extends Function ? never : K]: T[K]
                },
            >,
        ): T;
        attach(observer: Observer<T>): T;
        detach(observer: Observer<T>): T;
    }

    Type Parameters

    • T extends State<T>

      The state type this manager is attached to

    Index

    Methods

    • Captures a snapshot of the current version.

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

      Returns DeepReadonly<
          {
              [K in string
              | number
              | symbol as T[K] extends Function ? never : K]: T[K]
          },
      >

      A deeply read-only 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: DeepReadonly<
            {
                [K in string
                | number
                | symbol as T[K] extends Function ? never : K]: T[K]
            },
        >

        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 state 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