UNPKG

1.21 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
5 * the given `snapshot` and `event`.
6 *
7 * If the `snapshot` is `undefined`, the initial snapshot of the
8 * `actorLogic` is used.
9 *
10 * @example
11 ```ts
12 import { getNextSnapshot } from 'xstate';
13 import { trafficLightMachine } from './trafficLightMachine.ts';
14
15 const nextSnapshot = getNextSnapshot(
16 trafficLightMachine, // actor logic
17 undefined, // snapshot (or initial state if undefined)
18 { type: 'TIMER' }); // event object
19
20 console.log(nextSnapshot.value);
21 // => 'yellow'
22
23 const nextSnapshot2 = getNextSnapshot(
24 trafficLightMachine, // actor logic
25 nextSnapshot, // snapshot
26 { type: 'TIMER' }); // event object
27
28 console.log(nextSnapshot2.value);
29 // =>'red'
30 ```
31 */
32export declare function getNextSnapshot<T extends AnyActorLogic>(actorLogic: T, snapshot: SnapshotFrom<T>, event: EventFromLogic<T>): SnapshotFrom<T>;