Immertation
    Preparing search index...

    Class State<M>

    State management class that tracks model mutations with annotations.

    Type Parameters

    • M extends Model

      The model type extending Model

    Index

    Constructors

    Properties

    Accessors

    Methods

    Constructors

    • Creates a new State instance.

      Type Parameters

      • M extends Objectish

      Parameters

      • Optionalidentity: Identity<M> = utils.identity

        Optional function to generate unique IDs for snapshots

      Returns State<M>

    Properties

    "δ": <T>(operation: Operation, value: T) => T = ...

    Shorthand alias for annotate using the Greek delta symbol.

    Type Declaration

      • <T>(operation: Operation, value: T): T
      • Wraps a value with an annotation for tracking operations.

        Type Parameters

        • T

          The value type

        Parameters

        • operation: Operation

          The operation type (Add, Remove, Update, etc.)

        • value: T

          The value to annotate

        Returns T

        The annotated value (typed as T for assignment compatibility)

    "κ": () => string = State.pk

    Shorthand alias for State.pk using the Greek kappa symbol.

    Type Declaration

      • (): string
      • Generates a unique primary key using nanoid.

        Returns string

        A unique identifier

    Accessors

    • get inspect(): Inspect<M>

      Returns a proxy for inspecting pending operations at any path.

      Returns Inspect<M>

      Proxy with pending(), is(), draft(), and settled() methods

    • get model(): M

      Returns the current model state.

      Returns M

      The current model

    Methods

    • Wraps a value with an annotation for tracking operations.

      Type Parameters

      • T

        The value type

      Parameters

      • operation: Operation

        The operation type (Add, Remove, Update, etc.)

      • value: T

        The value to annotate

      Returns T

      The annotated value (typed as T for assignment compatibility)

    • Hydrates the state with a model, extracting annotations and registering them. Unlike produce(), annotation values become the actual model values.

      Parameters

      • model: M

        The model to hydrate with (may contain annotations)

      Returns symbol

      A unique process symbol for tracking this mutation batch

    • Subscribes to model changes.

      Parameters

      • callback: (model: M) => void

        Function called with the model on every change

      Returns () => void

      Unsubscribe function

    • Applies mutations to the model using an Immer recipe.

      Parameters

      • recipe: Recipe<M>

        Function that mutates the draft

      Returns symbol

      A unique process symbol for tracking this mutation batch

    • Removes all annotations associated with a specific process.

      Parameters

      • process: symbol

        The process symbol to prune

      Returns void

    • Generates a unique primary key using nanoid.

      Returns string

      A unique identifier