UNPKG

1.25 kBTypeScriptView Raw
1import { AnyActorLogic, EventFromLogic, InputFrom, SnapshotFrom } from "./types.js";
2export declare function getInitialSnapshot<T extends AnyActorLogic>(actorLogic: T, ...[input]: undefined extends InputFrom<T> ? [input?: InputFrom<T>] : [input: InputFrom<T>]): SnapshotFrom<T>;
3/**
4 * Determines the next snapshot for the given `actorLogic` based on the given
5 * `snapshot` and `event`.
6 *
7 * If the `snapshot` is `undefined`, the initial snapshot of the `actorLogic` is
8 * used.
9 *
10 * @example
11 *
12 * ```ts
13 * import { getNextSnapshot } from 'xstate';
14 * import { trafficLightMachine } from './trafficLightMachine.ts';
15 *
16 * const nextSnapshot = getNextSnapshot(
17 * trafficLightMachine, // actor logic
18 * undefined, // snapshot (or initial state if undefined)
19 * { type: 'TIMER' }
20 * ); // event object
21 *
22 * console.log(nextSnapshot.value);
23 * // => 'yellow'
24 *
25 * const nextSnapshot2 = getNextSnapshot(
26 * trafficLightMachine, // actor logic
27 * nextSnapshot, // snapshot
28 * { type: 'TIMER' }
29 * ); // event object
30 *
31 * console.log(nextSnapshot2.value);
32 * // =>'red'
33 * ```
34 */
35export declare function getNextSnapshot<T extends AnyActorLogic>(actorLogic: T, snapshot: SnapshotFrom<T>, event: EventFromLogic<T>): SnapshotFrom<T>;