Skip to content
Version: xstate@5.0.0

StateMachine class​

Signature:

export declare class StateMachine<TContext extends MachineContext, TEvent extends EventObject, TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string, TTag extends string, TInput, TOutput, TResolvedTypesMeta = ResolveTypegenMeta<TypegenDisabled, NoInfer<TEvent>, TActor, TAction, TGuard, TDelay, TTag>> implements ActorLogic<MachineSnapshot<TContext, TEvent, TActor, TTag, TOutput, TResolvedTypesMeta>, TEvent, TInput, TODO> 

Implements: ActorLogic<MachineSnapshot<TContext, TEvent, TActor, TTag, TOutput, TResolvedTypesMeta>, TEvent, TInput, TODO>

Constructors​

ConstructorModifiersDescription
(constructor)(config, implementations)Constructs a new instance of the StateMachine class

Properties​

PropertyModifiersTypeDescription
__TActionTAction
__TActorTActor
__TContextTContext
__TDelayTDelay
__TEventTEvent
__TGuardTGuard
__TInputTInput
__TOutputTOutput
__TResolvedTypesMetaTResolvedTypesMeta
__TTagTTag
__xstatenodetrue
configMachineConfig<TContext, TEvent, any, any, any, any, any, any, TOutput, any>The raw config used to create the machine.
definitionreadonlyStateMachineDefinition<TContext, TEvent>
eventsArray<TEvent['type']>
idstring
idMapMap<string, StateNode<TContext, TEvent>>
implementationsMachineImplementationsSimplified<TContext, TEvent>
rootStateNode<TContext, TEvent>
statesStateNode<TContext, TEvent>['states']
typesMachineTypes<TContext, TEvent, TActor, TAction, TGuard, TDelay, TTag, TInput, TOutput, TResolvedTypesMeta>
version?string(Optional) The machine's own version.

Methods​

MethodModifiersDescription
createState(stateConfig)
getInitialState(actorCtx, input)Returns the initial State instance, with reference to self as an ActorRef.
getPersistedState(state)
getStateNodeById(stateId)
getTransitionData(state, event)
microstep(state, event, actorCtx)Determines the next state given the current state and event. Calculates a microstep.
provide(implementations)Clones this state machine with the provided implementations and merges the context (if provided).
resolveState(state)

Resolves the given state to a new State instance relative to this machine.

This ensures that .nextEvents represent the correct values.

resolveStateValue(stateValue, [context])
restoreState(snapshot, _actorCtx)
start(state)
toJSON()
transition(state, event, actorCtx)Determines the next state given the current state and received event. Calculates a full macrostep from all microsteps.