import { createMachine } from "https://deno.land/x/xstate@xstate@5.9.1/src/createMachine.ts";
Creates a state machine (statechart) with the given configuration.
The state machine represents the pure logic of a state machine actor.
Examples
Example 1
Example 1
import { createMachine } from 'xstate';
const lightMachine = createMachine({
id: 'light',
initial: 'green',
states: {
green: {
on: {
TIMER: { target: 'yellow' }
}
},
yellow: {
on: {
TIMER: { target: 'red' }
}
},
red: {
on: {
TIMER: { target: 'green' }
}
}
}
});
const lightActor = createActor(lightMachine);
lightActor.start();
lightActor.send({ type: 'TIMER' });
Type Parameters
TContext extends MachineContext
TEvent extends AnyEventObject
TActor extends ProvidedActor
TAction extends ParameterizedObject
TGuard extends ParameterizedObject
TOutput extends NonReducibleUnknown
TEmitted extends EventObject
optional
TTypesMeta extends TypegenConstraint = TypegenDisabledParameters
config: { types?: MachineTypes<TContext, TEvent, TActor, TAction, TGuard, TDelay, TTag, TInput, TOutput, TEmitted, TTypesMeta>; schemas?: unknown; } & MachineConfig<TContext, TEvent, TActor, TAction, TGuard, TDelay, TTag, TInput, TOutput, TEmitted, TTypesMeta>
The state machine configuration.
optional
implementations: InternalMachineImplementations<TContext, ResolveTypegenMeta<TTypesMeta, TEvent, TActor, TAction, TGuard, TDelay, TTag, TEmitted>>DEPRECATED: use setup({ ... })
or machine.provide({ ... })
to provide machine implementations instead.
Returns
StateMachine<TContext, TEvent, Cast<ToChildren<TActor>, Record<string, AnyActorRef | undefined>>, TActor, TAction, TGuard, TDelay, "matchesStates" extends keyof TTypesMeta ? ToStateValue<Cast<TTypesMeta["matchesStates"], TestValue>> : StateValue, Prop<ResolveTypegenMeta<TTypesMeta, TEvent, TActor, TAction, TGuard, TDelay, TTag, TEmitted>["resolved"], "tags"> & string, TInput, TOutput, TEmitted, ResolveTypegenMeta<TTypesMeta, TEvent, TActor, TAction, TGuard, TDelay, TTag, TEmitted>>