UNPKG

2.3 kBTypeScriptView Raw
1import { StateMachine } from "./StateMachine.js";
2import { ResolvedStateMachineTypes, TODO } from "./types.js";
3import { AnyActorRef, EventObject, AnyEventObject, Cast, InternalMachineImplementations, MachineConfig, MachineContext, MachineTypes, NonReducibleUnknown, ParameterizedObject, ProvidedActor, StateValue, ToChildren, MetaObject } from "./types.js";
4/**
5 * Creates a state machine (statechart) with the given configuration.
6 *
7 * The state machine represents the pure logic of a state machine actor.
8 *
9 * @example
10 *
11 * ```ts
12 * import { createMachine } from 'xstate';
13 *
14 * const lightMachine = createMachine({
15 * id: 'light',
16 * initial: 'green',
17 * states: {
18 * green: {
19 * on: {
20 * TIMER: { target: 'yellow' }
21 * }
22 * },
23 * yellow: {
24 * on: {
25 * TIMER: { target: 'red' }
26 * }
27 * },
28 * red: {
29 * on: {
30 * TIMER: { target: 'green' }
31 * }
32 * }
33 * }
34 * });
35 *
36 * const lightActor = createActor(lightMachine);
37 * lightActor.start();
38 *
39 * lightActor.send({ type: 'TIMER' });
40 * ```
41 *
42 * @param config The state machine configuration.
43 * @param options DEPRECATED: use `setup({ ... })` or `machine.provide({ ... })`
44 * to provide machine implementations instead.
45 */
46export declare function createMachine<TContext extends MachineContext, TEvent extends AnyEventObject, // TODO: consider using a stricter `EventObject` here
47TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string, TTag extends string, TInput, TOutput extends NonReducibleUnknown, TEmitted extends EventObject, TMeta extends MetaObject, _ = any>(config: {
48 types?: MachineTypes<TContext, TEvent, TActor, TAction, TGuard, TDelay, TTag, TInput, TOutput, TEmitted, TMeta>;
49 schemas?: unknown;
50} & MachineConfig<TContext, TEvent, TActor, TAction, TGuard, TDelay, TTag, TInput, TOutput, TEmitted, TMeta>, implementations?: InternalMachineImplementations<ResolvedStateMachineTypes<TContext, TEvent, TActor, TAction, TGuard, TDelay, TTag, TEmitted>>): StateMachine<TContext, TEvent, Cast<ToChildren<TActor>, Record<string, AnyActorRef | undefined>>, TActor, TAction, TGuard, TDelay, StateValue, TTag & string, TInput, TOutput, TEmitted, TMeta, // TMeta
51TODO>;