Class Transition<TContext>

Manages state transitions within a state machine, allowing configuration of transition conditions, actions, and targets. This class enables defining multiple guarded and unguarded transitions for a single event, providing robust control over state changes based on complex conditions.

Typeparam

TContext Defines the context type for the state machine, describing the state's structure.

Type Parameters

  • TContext extends Record<string, any>

Constructors

Properties

Accessors

Methods

Constructors

  • Constructs a Transition instance with basic transition parameters.

    Type Parameters

    • TContext extends Record<string, any>

    Parameters

    • on: string

      Event name triggering the transition.

    • config: {
          actions?: Action<TContext, Record<string, any>>[];
          description?: string;
          guards?: GuardedTransitionV3<TContext, Record<string, any>>[];
          schema?: ZodObject<Record<string, any>, UnknownKeysParam, ZodTypeAny, {}, {}>;
          target: string;
      }

      Configuration object for the transition:

      • target: The state machine's target state for this transition.
      • schema: Optional Zod schema to validate the event data.
      • actions: Optional array of actions to perform during the transition. Default is all the actions provided by withBasicActions()
      • description: Optional description of the transition's purpose and functionality.
      • Optional actions?: Action<TContext, Record<string, any>>[]
      • Optional description?: string
      • Optional guards?: GuardedTransitionV3<TContext, Record<string, any>>[]
      • Optional schema?: ZodObject<Record<string, any>, UnknownKeysParam, ZodTypeAny, {}, {}>
      • target: string

    Returns Transition<TContext>

Properties

guards?: GuardedTransitionV3<TContext, Record<string, any>>[]
params: {
    actions?: Action<TContext, Record<string, any>>[];
    description?: string;
    on: string;
    schema?: ZodObject<Record<string, any>, UnknownKeysParam, ZodTypeAny, {}, {}>;
    target: string;
}

Type declaration

  • Optional actions?: Action<TContext, Record<string, any>>[]
  • Optional description?: string
  • on: string
  • Optional schema?: ZodObject<Record<string, any>, UnknownKeysParam, ZodTypeAny, {}, {}>
  • target: string

Accessors

Methods

  • Adds a guard condition to this transition, allowing further control over whether the transition should occur based on dynamic context or event conditions.

    Parameters

    • guard: GuardedTransitionV3<TContext, Record<string, any>>

      A GuardedTransition configuration, specifying the condition, associated actions, and any additional metadata.

    Returns Transition<TContext>

    The instance of this Transition class to allow method chaining.

    Note

    While using this, explicitly mention the Machine context type on the new Transition definition

Generated using TypeDoc