xstate 5.0.0-beta.41 → 5.0.0-beta.43
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/actions/dist/xstate-actions.cjs.js +3 -3
- package/actions/dist/xstate-actions.development.cjs.js +3 -3
- package/actions/dist/xstate-actions.development.esm.js +3 -3
- package/actions/dist/xstate-actions.esm.js +3 -3
- package/actions/dist/xstate-actions.umd.min.js +1 -1
- package/actions/dist/xstate-actions.umd.min.js.map +1 -1
- package/actors/dist/xstate-actors.cjs.js +45 -1
- package/actors/dist/xstate-actors.development.cjs.js +45 -1
- package/actors/dist/xstate-actors.development.esm.js +45 -1
- package/actors/dist/xstate-actors.esm.js +45 -1
- package/actors/dist/xstate-actors.umd.min.js.map +1 -1
- package/dist/declarations/src/State.d.ts +36 -43
- package/dist/declarations/src/StateMachine.d.ts +12 -29
- package/dist/declarations/src/StateNode.d.ts +2 -2
- package/dist/declarations/src/actions/spawn.d.ts +3 -3
- package/dist/declarations/src/actors/promise.d.ts +53 -0
- package/dist/declarations/src/index.d.ts +3 -4
- package/dist/declarations/src/interpreter.d.ts +12 -0
- package/dist/declarations/src/stateUtils.d.ts +7 -8
- package/dist/declarations/src/types.d.ts +153 -21
- package/dist/declarations/src/utils.d.ts +2 -8
- package/dist/{interpreter-fb2829f1.cjs.js → interpreter-36d5556e.cjs.js} +25 -19
- package/dist/{interpreter-70ed981b.development.cjs.js → interpreter-4e8e2a0d.development.cjs.js} +25 -19
- package/dist/{interpreter-480db258.esm.js → interpreter-63c80754.esm.js} +26 -19
- package/dist/{interpreter-936da690.development.esm.js → interpreter-80eb3bec.development.esm.js} +26 -19
- package/dist/{raise-5ab465ed.development.cjs.js → raise-23dea0d7.development.cjs.js} +101 -188
- package/dist/{raise-9d6921da.esm.js → raise-8dc8e1aa.esm.js} +95 -181
- package/dist/{raise-beae3fd3.cjs.js → raise-e0fe5c2d.cjs.js} +96 -183
- package/dist/{raise-f757be00.development.esm.js → raise-f4ad5a87.development.esm.js} +100 -186
- package/dist/{send-fb87a01a.development.cjs.js → send-0174c155.development.cjs.js} +10 -10
- package/dist/{send-b26e3812.development.esm.js → send-5d129d95.development.esm.js} +10 -10
- package/dist/{send-a931d1b8.esm.js → send-84e2e742.esm.js} +10 -10
- package/dist/{send-ca5f706c.cjs.js → send-87bbaaab.cjs.js} +10 -10
- package/dist/xstate.cjs.js +24 -50
- package/dist/xstate.cjs.mjs +0 -2
- package/dist/xstate.development.cjs.js +24 -50
- package/dist/xstate.development.cjs.mjs +0 -2
- package/dist/xstate.development.esm.js +28 -52
- package/dist/xstate.esm.js +28 -52
- package/dist/xstate.umd.min.js +1 -1
- package/dist/xstate.umd.min.js.map +1 -1
- package/guards/dist/xstate-guards.cjs.js +2 -2
- package/guards/dist/xstate-guards.development.cjs.js +2 -2
- package/guards/dist/xstate-guards.development.esm.js +2 -2
- package/guards/dist/xstate-guards.esm.js +2 -2
- package/guards/dist/xstate-guards.umd.min.js.map +1 -1
- package/package.json +1 -1
- package/dist/declarations/src/mapState.d.ts +0 -3
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { MachineSnapshot } from "./StateMachine.js";
|
|
2
1
|
import type { StateNode } from "./StateNode.js";
|
|
2
|
+
import type { StateMachine } from "./StateMachine.js";
|
|
3
3
|
import { TypegenDisabled, TypegenEnabled } from "./typegenTypes.js";
|
|
4
|
-
import type { ProvidedActor, ActorRefFrom, AnyState, AnyStateMachine, EventObject, HistoryValue, MachineContext, Prop, StateConfig, StateValue,
|
|
4
|
+
import type { ProvidedActor, ActorRefFrom, AnyState, AnyStateMachine, EventObject, HistoryValue, MachineContext, Prop, StateConfig, StateValue, AnyActorRef, Compute, EventDescriptor, Snapshot, ParameterizedObject } from "./types.js";
|
|
5
5
|
type ComputeConcreteChildren<TActor extends ProvidedActor> = {
|
|
6
6
|
[A in TActor as 'id' extends keyof A ? A['id'] & string : never]?: ActorRefFrom<A['logic']>;
|
|
7
7
|
};
|
|
@@ -10,20 +10,14 @@ type ComputeChildren<TActor extends ProvidedActor> = string extends TActor['src'
|
|
|
10
10
|
} : {})>;
|
|
11
11
|
export declare function isStateConfig<TContext extends MachineContext, TEvent extends EventObject>(state: any): state is StateConfig<TContext, TEvent>;
|
|
12
12
|
/**
|
|
13
|
-
* @deprecated Use `isStateConfig(object)`
|
|
13
|
+
* @deprecated Use `isStateConfig(object)`
|
|
14
14
|
*/
|
|
15
15
|
export declare const isState: typeof isStateConfig;
|
|
16
|
-
|
|
17
|
-
machine:
|
|
16
|
+
interface MachineSnapshotBase<TContext extends MachineContext, TEvent extends EventObject, TActor extends ProvidedActor, TTag extends string, TOutput, TResolvedTypesMeta = TypegenDisabled> {
|
|
17
|
+
machine: StateMachine<TContext, TEvent, TActor, ParameterizedObject, ParameterizedObject, string, TTag, unknown, TOutput, TResolvedTypesMeta>;
|
|
18
18
|
tags: Set<string>;
|
|
19
19
|
value: StateValue;
|
|
20
|
-
/**
|
|
21
|
-
* Indicates whether the state is a final state.
|
|
22
|
-
*/
|
|
23
20
|
status: 'active' | 'done' | 'error' | 'stopped';
|
|
24
|
-
/**
|
|
25
|
-
* The output data of the top-level finite state.
|
|
26
|
-
*/
|
|
27
21
|
error: unknown;
|
|
28
22
|
context: TContext;
|
|
29
23
|
historyValue: Readonly<HistoryValue<TContext, TEvent>>;
|
|
@@ -36,39 +30,20 @@ export declare class State<TContext extends MachineContext, TEvent extends Event
|
|
|
36
30
|
*/
|
|
37
31
|
children: ComputeChildren<TActor>;
|
|
38
32
|
/**
|
|
39
|
-
*
|
|
40
|
-
* @param stateValue
|
|
41
|
-
* @param context
|
|
42
|
-
*/
|
|
43
|
-
static from<TContext extends MachineContext, TEvent extends EventObject = EventObject>(stateValue: State<TContext, TEvent, TODO, any, // tags
|
|
44
|
-
any> | StateValue, context: TContext | undefined, machine: AnyStateMachine): State<TContext, TEvent, TODO, any, // tags
|
|
45
|
-
any>;
|
|
46
|
-
/**
|
|
47
|
-
* Creates a new `State` instance that represents the current state of a running machine.
|
|
48
|
-
*
|
|
49
|
-
* @param config
|
|
50
|
-
*/
|
|
51
|
-
constructor(config: StateConfig<TContext, TEvent>, machine: AnyStateMachine);
|
|
52
|
-
/**
|
|
53
|
-
* Returns an array of all the string leaf state node paths.
|
|
54
|
-
* @param stateValue
|
|
55
|
-
* @param delimiter The character(s) that separate each subpath in the string state node path.
|
|
33
|
+
* The next events that will cause a transition from the current state.
|
|
56
34
|
*/
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
tags: string[];
|
|
60
|
-
meta: Record<string, any>;
|
|
61
|
-
};
|
|
35
|
+
nextEvents: Array<EventDescriptor<TEvent>>;
|
|
36
|
+
meta: Record<string, any>;
|
|
62
37
|
/**
|
|
63
38
|
* Whether the current state value is a subset of the given parent state value.
|
|
64
|
-
* @param
|
|
39
|
+
* @param testValue
|
|
65
40
|
*/
|
|
66
|
-
matches<TSV extends TResolvedTypesMeta extends TypegenEnabled ? Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'matchesStates'> : StateValue>(
|
|
41
|
+
matches: <TSV extends TResolvedTypesMeta extends TypegenEnabled ? Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'matchesStates'> : StateValue>(this: MachineSnapshotBase<TContext, TEvent, TActor, TTag, TOutput, TResolvedTypesMeta>, testValue: TSV) => boolean;
|
|
67
42
|
/**
|
|
68
43
|
* Whether the current state configuration has a state node with the specified `tag`.
|
|
69
44
|
* @param tag
|
|
70
45
|
*/
|
|
71
|
-
hasTag(tag: TTag)
|
|
46
|
+
hasTag: (this: MachineSnapshotBase<TContext, TEvent, TActor, TTag, TOutput, TResolvedTypesMeta>, tag: TTag) => boolean;
|
|
72
47
|
/**
|
|
73
48
|
* Determines whether sending the `event` will cause a non-forbidden transition
|
|
74
49
|
* to be selected, even if the transitions have no actions nor
|
|
@@ -77,13 +52,31 @@ export declare class State<TContext extends MachineContext, TEvent extends Event
|
|
|
77
52
|
* @param event The event to test
|
|
78
53
|
* @returns Whether the event will cause a transition
|
|
79
54
|
*/
|
|
80
|
-
can(event: TEvent)
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
55
|
+
can: (this: MachineSnapshotBase<TContext, TEvent, TActor, TTag, TOutput, TResolvedTypesMeta>, event: TEvent) => boolean;
|
|
56
|
+
toJSON: (this: MachineSnapshotBase<TContext, TEvent, TActor, TTag, TOutput, TResolvedTypesMeta>) => unknown;
|
|
57
|
+
}
|
|
58
|
+
interface ActiveMachineSnapshot<TContext extends MachineContext, TEvent extends EventObject, TActor extends ProvidedActor, TTag extends string, TOutput, TResolvedTypesMeta = TypegenDisabled> extends MachineSnapshotBase<TContext, TEvent, TActor, TTag, TOutput, TResolvedTypesMeta> {
|
|
59
|
+
status: 'active';
|
|
60
|
+
output: undefined;
|
|
61
|
+
error: undefined;
|
|
62
|
+
}
|
|
63
|
+
interface DoneMachineSnapshot<TContext extends MachineContext, TEvent extends EventObject, TActor extends ProvidedActor, TTag extends string, TOutput, TResolvedTypesMeta = TypegenDisabled> extends MachineSnapshotBase<TContext, TEvent, TActor, TTag, TOutput, TResolvedTypesMeta> {
|
|
64
|
+
status: 'done';
|
|
65
|
+
output: TOutput;
|
|
66
|
+
error: undefined;
|
|
67
|
+
}
|
|
68
|
+
interface ErrorMachineSnapshot<TContext extends MachineContext, TEvent extends EventObject, TActor extends ProvidedActor, TTag extends string, TOutput, TResolvedTypesMeta = TypegenDisabled> extends MachineSnapshotBase<TContext, TEvent, TActor, TTag, TOutput, TResolvedTypesMeta> {
|
|
69
|
+
status: 'error';
|
|
70
|
+
output: undefined;
|
|
71
|
+
error: unknown;
|
|
72
|
+
}
|
|
73
|
+
interface StoppedMachineSnapshot<TContext extends MachineContext, TEvent extends EventObject, TActor extends ProvidedActor, TTag extends string, TOutput, TResolvedTypesMeta = TypegenDisabled> extends MachineSnapshotBase<TContext, TEvent, TActor, TTag, TOutput, TResolvedTypesMeta> {
|
|
74
|
+
status: 'stopped';
|
|
75
|
+
output: undefined;
|
|
76
|
+
error: undefined;
|
|
86
77
|
}
|
|
87
|
-
export
|
|
78
|
+
export type MachineSnapshot<TContext extends MachineContext, TEvent extends EventObject, TActor extends ProvidedActor, TTag extends string, TOutput, TResolvedTypesMeta = TypegenDisabled> = ActiveMachineSnapshot<TContext, TEvent, TActor, TTag, TOutput, TResolvedTypesMeta> | DoneMachineSnapshot<TContext, TEvent, TActor, TTag, TOutput, TResolvedTypesMeta> | ErrorMachineSnapshot<TContext, TEvent, TActor, TTag, TOutput, TResolvedTypesMeta> | StoppedMachineSnapshot<TContext, TEvent, TActor, TTag, TOutput, TResolvedTypesMeta>;
|
|
79
|
+
export declare function createMachineSnapshot<TContext extends MachineContext, TEvent extends EventObject, TActor extends ProvidedActor, TTag extends string, TResolvedTypesMeta = TypegenDisabled>(config: StateConfig<TContext, TEvent>, machine: AnyStateMachine): MachineSnapshot<TContext, TEvent, TActor, TTag, undefined, TResolvedTypesMeta>;
|
|
80
|
+
export declare function cloneMachineSnapshot<TState extends AnyState>(state: TState, config?: Partial<StateConfig<any, any>>): TState;
|
|
88
81
|
export declare function getPersistedState<TContext extends MachineContext, TEvent extends EventObject, TActor extends ProvidedActor, TTag extends string, TOutput, TResolvedTypesMeta = TypegenDisabled>(state: MachineSnapshot<TContext, TEvent, TActor, TTag, TOutput, TResolvedTypesMeta>, options?: unknown): Snapshot<unknown>;
|
|
89
82
|
export {};
|
|
@@ -1,26 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MachineSnapshot } from "./State.js";
|
|
2
2
|
import { StateNode } from "./StateNode.js";
|
|
3
3
|
import type { AreAllImplementationsAssumedToBeProvided, MarkAllImplementationsAsProvided, ResolveTypegenMeta, TypegenDisabled } from "./typegenTypes.js";
|
|
4
|
-
import type { ActorScope, ActorLogic, EventObject, InternalMachineImplementations, MachineConfig, MachineContext, MachineImplementationsSimplified, MachineTypes, NoInfer,
|
|
4
|
+
import type { ActorScope, ActorLogic, EventObject, InternalMachineImplementations, MachineConfig, MachineContext, MachineImplementationsSimplified, MachineTypes, NoInfer, StateMachineDefinition, StateValue, TransitionDefinition, ParameterizedObject, AnyActorScope, ProvidedActor, Equals, TODO, Snapshot, HistoryValue } from "./types.js";
|
|
5
5
|
export declare const STATE_IDENTIFIER = "#";
|
|
6
6
|
export declare const WILDCARD = "*";
|
|
7
|
-
export type MachineSnapshot<TContext extends MachineContext, TEvent extends EventObject, TActor extends ProvidedActor, TTag extends string, TOutput, TResolvedTypesMeta = TypegenDisabled> = (State<TContext, TEvent, TActor, TTag, TResolvedTypesMeta> & {
|
|
8
|
-
status: 'active';
|
|
9
|
-
output: undefined;
|
|
10
|
-
error: undefined;
|
|
11
|
-
}) | (State<TContext, TEvent, TActor, TTag, TResolvedTypesMeta> & {
|
|
12
|
-
status: 'done';
|
|
13
|
-
output: TOutput;
|
|
14
|
-
error: undefined;
|
|
15
|
-
}) | (State<TContext, TEvent, TActor, TTag, TResolvedTypesMeta> & {
|
|
16
|
-
status: 'error';
|
|
17
|
-
output: undefined;
|
|
18
|
-
error: unknown;
|
|
19
|
-
}) | (State<TContext, TEvent, TActor, TTag, TResolvedTypesMeta> & {
|
|
20
|
-
status: 'stopped';
|
|
21
|
-
output: undefined;
|
|
22
|
-
error: undefined;
|
|
23
|
-
});
|
|
24
7
|
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> {
|
|
25
8
|
/**
|
|
26
9
|
* The raw config used to create the machine.
|
|
@@ -53,15 +36,16 @@ export declare class StateMachine<TContext extends MachineContext, TEvent extend
|
|
|
53
36
|
* @returns A new `StateMachine` instance with the provided implementations.
|
|
54
37
|
*/
|
|
55
38
|
provide(implementations: InternalMachineImplementations<TContext, TEvent, TActor, TAction, TDelay, TResolvedTypesMeta, true>): StateMachine<TContext, TEvent, TActor, TAction, TGuard, TDelay, TTag, TInput, TOutput, AreAllImplementationsAssumedToBeProvided<TResolvedTypesMeta> extends false ? MarkAllImplementationsAsProvided<TResolvedTypesMeta> : TResolvedTypesMeta>;
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
39
|
+
resolveState(config: {
|
|
40
|
+
value: StateValue;
|
|
41
|
+
context?: TContext;
|
|
42
|
+
historyValue?: HistoryValue<TContext, TEvent>;
|
|
43
|
+
status?: 'active' | 'done' | 'error' | 'stopped';
|
|
44
|
+
output?: TOutput;
|
|
45
|
+
error?: unknown;
|
|
46
|
+
} & (Equals<TContext, MachineContext> extends false ? {
|
|
47
|
+
context: unknown;
|
|
48
|
+
} : {})): MachineSnapshot<TContext, TEvent, TActor, TTag, TOutput, TResolvedTypesMeta>;
|
|
65
49
|
/**
|
|
66
50
|
* Determines the next state given the current `state` and received `event`.
|
|
67
51
|
* Calculates a full macrostep from all microsteps.
|
|
@@ -93,7 +77,6 @@ export declare class StateMachine<TContext extends MachineContext, TEvent extend
|
|
|
93
77
|
get definition(): StateMachineDefinition<TContext, TEvent>;
|
|
94
78
|
toJSON(): StateMachineDefinition<TContext, TEvent>;
|
|
95
79
|
getPersistedState(state: MachineSnapshot<TContext, TEvent, TActor, TTag, TOutput, TResolvedTypesMeta>, options?: unknown): Snapshot<unknown>;
|
|
96
|
-
createState(stateConfig: MachineSnapshot<TContext, TEvent, TActor, TTag, TOutput, TResolvedTypesMeta> | StateConfig<TContext, TEvent>): MachineSnapshot<TContext, TEvent, TActor, TTag, TOutput, TResolvedTypesMeta>;
|
|
97
80
|
restoreState(snapshot: Snapshot<unknown>, _actorScope: ActorScope<MachineSnapshot<TContext, TEvent, TActor, TTag, TOutput, TResolvedTypesMeta>, TEvent>): MachineSnapshot<TContext, TEvent, TActor, TTag, TOutput, TResolvedTypesMeta>;
|
|
98
81
|
/**@deprecated an internal property acting as a "phantom" type, not meant to be used at runtime */
|
|
99
82
|
__TContext: TContext;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { MachineSnapshot } from "./State.js";
|
|
2
2
|
import type { StateMachine } from "./StateMachine.js";
|
|
3
3
|
import type { DelayedTransitionDefinition, EventObject, InitialTransitionDefinition, InvokeDefinition, MachineContext, Mapper, StateNodeConfig, StateNodeDefinition, StateNodesConfig, TransitionDefinition, TransitionDefinitionMap, TODO, UnknownAction, ParameterizedObject, AnyStateMachine, ProvidedActor, NonReducibleUnknown } from "./types.js";
|
|
4
4
|
interface StateNodeOptions<TContext extends MachineContext, TEvent extends EventObject> {
|
|
@@ -113,7 +113,7 @@ export declare class StateNode<TContext extends MachineContext = MachineContext,
|
|
|
113
113
|
get on(): TransitionDefinitionMap<TContext, TEvent>;
|
|
114
114
|
get after(): Array<DelayedTransitionDefinition<TContext, TEvent>>;
|
|
115
115
|
get initial(): InitialTransitionDefinition<TContext, TEvent>;
|
|
116
|
-
next(state:
|
|
116
|
+
next(state: MachineSnapshot<TContext, TEvent, any, any, any, any>, event: TEvent): TransitionDefinition<TContext, TEvent>[] | undefined;
|
|
117
117
|
/**
|
|
118
118
|
* All the event types accepted by this state node and its descendants.
|
|
119
119
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ActionArgs, EventObject, MachineContext, ParameterizedObject, AnyActorLogic, ProvidedActor, IsLiteralString, InputFrom, UnifiedArg } from "../types.js";
|
|
1
|
+
import { ActionArgs, EventObject, MachineContext, ParameterizedObject, AnyActorLogic, ProvidedActor, IsLiteralString, InputFrom, UnifiedArg, Mapper } from "../types.js";
|
|
2
2
|
type ResolvableActorId<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject, TId extends string | undefined> = TId | ((args: UnifiedArg<TContext, TExpressionEvent, TEvent>) => TId);
|
|
3
3
|
export interface SpawnAction<TContext extends MachineContext, TExpressionEvent extends EventObject, TParams extends ParameterizedObject['params'] | undefined, TEvent extends EventObject, TActor extends ProvidedActor> {
|
|
4
4
|
(args: ActionArgs<TContext, TExpressionEvent, TEvent>, params: TParams): void;
|
|
@@ -9,7 +9,7 @@ type DistributeActors<TContext extends MachineContext, TExpressionEvent extends
|
|
|
9
9
|
options: {
|
|
10
10
|
id: ResolvableActorId<TContext, TExpressionEvent, TEvent, TActor['id']>;
|
|
11
11
|
systemId?: string;
|
|
12
|
-
input?: InputFrom<TActor['logic']>;
|
|
12
|
+
input?: Mapper<TContext, TEvent, InputFrom<TActor['logic']>, TEvent> | InputFrom<TActor['logic']>;
|
|
13
13
|
syncSnapshot?: boolean;
|
|
14
14
|
}
|
|
15
15
|
] : [
|
|
@@ -17,7 +17,7 @@ type DistributeActors<TContext extends MachineContext, TExpressionEvent extends
|
|
|
17
17
|
options?: {
|
|
18
18
|
id?: ResolvableActorId<TContext, TExpressionEvent, TEvent, string>;
|
|
19
19
|
systemId?: string;
|
|
20
|
-
input?: InputFrom<TActor['logic']>;
|
|
20
|
+
input?: Mapper<TContext, TEvent, InputFrom<TActor['logic']>, TEvent> | InputFrom<TActor['logic']>;
|
|
21
21
|
syncSnapshot?: boolean;
|
|
22
22
|
}
|
|
23
23
|
] : never;
|
|
@@ -20,9 +20,62 @@ export type PromiseActorLogic<TOutput, TInput = unknown> = ActorLogic<PromiseSna
|
|
|
20
20
|
}, TInput, // input
|
|
21
21
|
ActorSystem<any>>;
|
|
22
22
|
export type PromiseActorRef<TOutput> = ActorRefFrom<PromiseActorLogic<TOutput, unknown>>;
|
|
23
|
+
/**
|
|
24
|
+
* An actor logic creator which returns promise logic as defined by an async process that resolves or rejects after some time.
|
|
25
|
+
*
|
|
26
|
+
* Actors created from promise actor logic (“promise actors”) can:
|
|
27
|
+
* - Emit the resolved value of the promise
|
|
28
|
+
* - Output the resolved value of the promise
|
|
29
|
+
*
|
|
30
|
+
* Sending events to promise actors will have no effect.
|
|
31
|
+
*
|
|
32
|
+
* @param promiseCreator
|
|
33
|
+
* A function which returns a Promise, and accepts an object with the following properties:
|
|
34
|
+
* - `input` - Data that was provided to the promise actor
|
|
35
|
+
* - `self` - The parent actor of the promise actor
|
|
36
|
+
* - `system` - The actor system to which the promise actor belongs
|
|
37
|
+
* @see {@link https://stately.ai/docs/input | Input docs} for more information about how input is passed
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```ts
|
|
41
|
+
* const promiseLogic = fromPromise(async () => {
|
|
42
|
+
* const result = await fetch('https://example.com/...')
|
|
43
|
+
* .then((data) => data.json());
|
|
44
|
+
*
|
|
45
|
+
* return result;
|
|
46
|
+
* });
|
|
47
|
+
*
|
|
48
|
+
* const promiseActor = createActor(promiseLogic);
|
|
49
|
+
* promiseActor.subscribe((snapshot) => {
|
|
50
|
+
* console.log(snapshot);
|
|
51
|
+
* });
|
|
52
|
+
* promiseActor.start();
|
|
53
|
+
* // => {
|
|
54
|
+
* // output: undefined,
|
|
55
|
+
* // status: 'active'
|
|
56
|
+
* // ...
|
|
57
|
+
* // }
|
|
58
|
+
*
|
|
59
|
+
* // After promise resolves
|
|
60
|
+
* // => {
|
|
61
|
+
* // output: { ... },
|
|
62
|
+
* // status: 'done',
|
|
63
|
+
* // ...
|
|
64
|
+
* // }
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
23
67
|
export declare function fromPromise<TOutput, TInput = unknown>(promiseCreator: ({ input, system }: {
|
|
68
|
+
/**
|
|
69
|
+
* Data that was provided to the promise actor
|
|
70
|
+
*/
|
|
24
71
|
input: TInput;
|
|
72
|
+
/**
|
|
73
|
+
* The actor system to which the promise actor belongs
|
|
74
|
+
*/
|
|
25
75
|
system: AnyActorSystem;
|
|
76
|
+
/**
|
|
77
|
+
* The parent actor of the promise actor
|
|
78
|
+
*/
|
|
26
79
|
self: PromiseActorRef<TOutput>;
|
|
27
80
|
}) => PromiseLike<TOutput>): PromiseActorLogic<TOutput, TInput>;
|
|
28
81
|
export {};
|
|
@@ -2,18 +2,17 @@ export * from "./actions.js";
|
|
|
2
2
|
export * from "./actors/index.js";
|
|
3
3
|
export { SimulatedClock } from "./SimulatedClock.js";
|
|
4
4
|
export { type Spawner } from "./spawn.js";
|
|
5
|
-
export { StateMachine
|
|
5
|
+
export { StateMachine } from "./StateMachine.js";
|
|
6
6
|
export { getStateNodes } from "./stateUtils.js";
|
|
7
7
|
export * from "./typegenTypes.js";
|
|
8
8
|
export * from "./types.js";
|
|
9
9
|
export { waitFor } from "./waitFor.js";
|
|
10
10
|
import { Actor, createActor, interpret, Interpreter } from "./interpreter.js";
|
|
11
11
|
import { createMachine } from "./Machine.js";
|
|
12
|
-
|
|
13
|
-
import { State } from "./State.js";
|
|
12
|
+
export { type MachineSnapshot } from "./State.js";
|
|
14
13
|
import { StateNode } from "./StateNode.js";
|
|
15
14
|
export { matchesState, pathToStateValue, toObserver } from "./utils.js";
|
|
16
|
-
export { Actor, createActor, createMachine, interpret,
|
|
15
|
+
export { Actor, createActor, createMachine, interpret, StateNode, type Interpreter };
|
|
17
16
|
export type { InspectedActorEvent, InspectedEventEvent, InspectedSnapshotEvent, InspectionEvent } from "./system.js";
|
|
18
17
|
export { and, not, or, stateIn } from "./guards.js";
|
|
19
18
|
declare global {
|
|
@@ -136,6 +136,18 @@ export declare class Actor<TLogic extends AnyActorLogic> implements ActorRef<Eve
|
|
|
136
136
|
xstate$$type: number;
|
|
137
137
|
id: string;
|
|
138
138
|
};
|
|
139
|
+
/**
|
|
140
|
+
* Obtain the internal state of the actor, which can be persisted.
|
|
141
|
+
*
|
|
142
|
+
* @remarks
|
|
143
|
+
* The internal state can be persisted from any actor, not only machines.
|
|
144
|
+
*
|
|
145
|
+
* Note that the persisted state is not the same as the snapshot from {@link Actor.getSnapshot}. Persisted state represents the internal state of the actor, while snapshots represent the actor's last emitted value.
|
|
146
|
+
*
|
|
147
|
+
* Can be restored with {@link ActorOptions.state}
|
|
148
|
+
*
|
|
149
|
+
* @see https://stately.ai/docs/persistence
|
|
150
|
+
*/
|
|
139
151
|
getPersistedState(): Snapshot<unknown>;
|
|
140
152
|
[symbolObservable](): InteropSubscribable<SnapshotFrom<TLogic>>;
|
|
141
153
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MachineSnapshot } from "./State.js";
|
|
2
2
|
import type { StateNode } from "./StateNode.js";
|
|
3
3
|
import { AnyEventObject, AnyHistoryValue, AnyState, AnyStateNode, AnyTransitionDefinition, DelayedTransitionDefinition, EventObject, InitialTransitionConfig, InitialTransitionDefinition, MachineContext, StateValue, StateValueMap, TransitionDefinition, TODO, UnknownAction, AnyTransitionConfig, AnyActorScope } from "./types.js";
|
|
4
4
|
type Configuration<TContext extends MachineContext, TE extends EventObject> = Iterable<StateNode<TContext, TE>>;
|
|
@@ -34,13 +34,13 @@ export declare function getStateNodeByPath(stateNode: AnyStateNode, statePath: s
|
|
|
34
34
|
/**
|
|
35
35
|
* Returns the state nodes represented by the current state value.
|
|
36
36
|
*
|
|
37
|
-
* @param
|
|
37
|
+
* @param stateValue The state value or State instance
|
|
38
38
|
*/
|
|
39
|
-
export declare function getStateNodes<TContext extends MachineContext, TEvent extends EventObject>(stateNode: AnyStateNode,
|
|
40
|
-
export declare function transitionAtomicNode<TContext extends MachineContext, TEvent extends EventObject>(stateNode: AnyStateNode, stateValue: string, state:
|
|
41
|
-
export declare function transitionCompoundNode<TContext extends MachineContext, TEvent extends EventObject>(stateNode: AnyStateNode, stateValue: StateValueMap, state:
|
|
42
|
-
export declare function transitionParallelNode<TContext extends MachineContext, TEvent extends EventObject>(stateNode: AnyStateNode, stateValue: StateValueMap, state:
|
|
43
|
-
export declare function transitionNode<TContext extends MachineContext, TEvent extends EventObject>(stateNode: AnyStateNode, stateValue: StateValue, state:
|
|
39
|
+
export declare function getStateNodes<TContext extends MachineContext, TEvent extends EventObject>(stateNode: AnyStateNode, stateValue: StateValue): Array<AnyStateNode>;
|
|
40
|
+
export declare function transitionAtomicNode<TContext extends MachineContext, TEvent extends EventObject>(stateNode: AnyStateNode, stateValue: string, state: MachineSnapshot<TContext, TEvent, any, any, any, any>, event: TEvent): Array<TransitionDefinition<TContext, TEvent>> | undefined;
|
|
41
|
+
export declare function transitionCompoundNode<TContext extends MachineContext, TEvent extends EventObject>(stateNode: AnyStateNode, stateValue: StateValueMap, state: MachineSnapshot<TContext, TEvent, any, any, any, any>, event: TEvent): Array<TransitionDefinition<TContext, TEvent>> | undefined;
|
|
42
|
+
export declare function transitionParallelNode<TContext extends MachineContext, TEvent extends EventObject>(stateNode: AnyStateNode, stateValue: StateValueMap, state: MachineSnapshot<TContext, TEvent, any, any, any, any>, event: TEvent): Array<TransitionDefinition<TContext, TEvent>> | undefined;
|
|
43
|
+
export declare function transitionNode<TContext extends MachineContext, TEvent extends EventObject>(stateNode: AnyStateNode, stateValue: StateValue, state: MachineSnapshot<TContext, TEvent, any, any, any, any>, event: TEvent): Array<TransitionDefinition<TContext, TEvent>> | undefined;
|
|
44
44
|
export declare function removeConflictingTransitions(enabledTransitions: Array<AnyTransitionDefinition>, configuration: Set<AnyStateNode>, historyValue: AnyHistoryValue): Array<AnyTransitionDefinition>;
|
|
45
45
|
/**
|
|
46
46
|
* https://www.w3.org/TR/scxml/#microstepProcedure
|
|
@@ -58,5 +58,4 @@ export declare function macrostep(state: AnyState, event: EventObject, actorScop
|
|
|
58
58
|
*/
|
|
59
59
|
export declare function resolveStateValue(rootNode: AnyStateNode, stateValue: StateValue): StateValue;
|
|
60
60
|
export declare function stateValuesEqual(a: StateValue | undefined, b: StateValue | undefined): boolean;
|
|
61
|
-
export declare function getInitialConfiguration(rootNode: AnyStateNode): AnyStateNode[];
|
|
62
61
|
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { StateNode } from "./StateNode.js";
|
|
2
|
-
import type {
|
|
2
|
+
import type { MachineSnapshot } from "./State.js";
|
|
3
3
|
import type { Clock, Actor } from "./interpreter.js";
|
|
4
|
-
import type {
|
|
4
|
+
import type { StateMachine } from "./StateMachine.js";
|
|
5
5
|
import { TypegenDisabled, ResolveTypegenMeta, TypegenConstraint, MarkAllImplementationsAsProvided, AreAllImplementationsAssumedToBeProvided } from "./typegenTypes.js";
|
|
6
6
|
import { PromiseActorLogic } from "./actors/promise.js";
|
|
7
7
|
import { Guard, GuardPredicate, UnknownGuard } from "./guards.js";
|
|
@@ -347,11 +347,7 @@ export interface StateMachineDefinition<TContext extends MachineContext, TEvent
|
|
|
347
347
|
}
|
|
348
348
|
export type AnyStateNode = StateNode<any, any>;
|
|
349
349
|
export type AnyStateNodeDefinition = StateNodeDefinition<any, any>;
|
|
350
|
-
export type AnyState =
|
|
351
|
-
any, // event
|
|
352
|
-
any, // actor
|
|
353
|
-
any, // tags
|
|
354
|
-
any>;
|
|
350
|
+
export type AnyState = MachineSnapshot<any, any, any, any, any, any>;
|
|
355
351
|
export type AnyStateMachine = StateMachine<any, any, any, any, any, any, any, any, any, // delays
|
|
356
352
|
any>;
|
|
357
353
|
export type AnyStateConfig = StateConfig<any, AnyEventObject>;
|
|
@@ -391,11 +387,8 @@ type MaybeNarrowedEvent<TIndexedEvents, TCausingLookup, K> = Cast<Prop<TIndexedE
|
|
|
391
387
|
type MachineImplementationsActions<TContext extends MachineContext, TResolvedTypesMeta, TEventsCausingActions = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'eventsCausingActions'>, TIndexedEvents = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'indexedEvents'>, TIndexedActors = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'indexedActors'>, TIndexedActions = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'indexedActions'>, TIndexedGuards = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'indexedGuards'>, TIndexedDelays = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'indexedDelays'>> = {
|
|
392
388
|
[K in keyof TIndexedActions]?: ActionFunction<TContext, MaybeNarrowedEvent<TIndexedEvents, TEventsCausingActions, K>, Cast<Prop<TIndexedEvents, keyof TIndexedEvents>, EventObject>, GetParameterizedParams<Cast<TIndexedActions[K], ParameterizedObject>>, Cast<Prop<TIndexedActors, keyof TIndexedActors>, ProvidedActor>, Cast<Prop<TIndexedActions, keyof TIndexedActions>, ParameterizedObject>, Cast<Prop<TIndexedGuards, keyof TIndexedGuards>, ParameterizedObject>, Cast<Prop<TIndexedDelays, keyof TIndexedDelays>, ParameterizedObject>['type']>;
|
|
393
389
|
};
|
|
394
|
-
type MachineImplementationsActors<
|
|
395
|
-
[K in keyof TIndexedActors]?: Cast<Prop<TIndexedActors[K], 'logic'>, AnyActorLogic
|
|
396
|
-
src: Cast<Prop<TIndexedActors[K], 'logic'>, AnyActorLogic>;
|
|
397
|
-
input: Mapper<TContext, MaybeNarrowedEvent<TIndexedEvents, TEventsCausingActors, K>, InputFrom<Cast<Prop<TIndexedActors[K], 'logic'>, AnyActorLogic>>, Cast<Prop<TIndexedEvents, keyof TIndexedEvents>, EventObject>> | InputFrom<Cast<Prop<TIndexedActors[K], 'logic'>, AnyActorLogic>>;
|
|
398
|
-
};
|
|
390
|
+
type MachineImplementationsActors<_TContext extends MachineContext, TResolvedTypesMeta, TIndexedActors = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'indexedActors'>, _TInvokeSrcNameMap = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'invokeSrcNameMap'>> = {
|
|
391
|
+
[K in keyof TIndexedActors]?: Cast<Prop<TIndexedActors[K], 'logic'>, AnyActorLogic>;
|
|
399
392
|
};
|
|
400
393
|
type MachineImplementationsDelays<TContext extends MachineContext, TResolvedTypesMeta, TEventsCausingDelays = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'eventsCausingDelays'>, TIndexedEvents = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'indexedEvents'>, TIndexedActions = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'indexedActions'>, TIndexedDelays = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'indexedDelays'>> = {
|
|
401
394
|
[K in keyof TIndexedDelays]?: DelayConfig<TContext, MaybeNarrowedEvent<TIndexedEvents, TEventsCausingDelays, K>, Cast<Prop<Prop<TIndexedActions, keyof TIndexedActions>, 'params'>, ParameterizedObject['params'] | undefined> | undefined, Cast<Prop<TIndexedEvents, keyof TIndexedEvents>, EventObject>>;
|
|
@@ -546,22 +539,37 @@ export interface StateLike<TContext extends MachineContext> {
|
|
|
546
539
|
event: EventObject;
|
|
547
540
|
}
|
|
548
541
|
export interface StateConfig<TContext extends MachineContext, TEvent extends EventObject> {
|
|
549
|
-
value: StateValue;
|
|
550
542
|
context: TContext;
|
|
551
543
|
historyValue?: HistoryValue<TContext, TEvent>;
|
|
552
|
-
|
|
553
|
-
configuration?: Array<StateNode<TContext, TEvent>>;
|
|
544
|
+
configuration: Array<StateNode<TContext, TEvent>>;
|
|
554
545
|
children: Record<string, ActorRef<any, any>>;
|
|
555
546
|
status: 'active' | 'done' | 'error' | 'stopped';
|
|
556
547
|
output?: any;
|
|
557
548
|
error?: unknown;
|
|
558
|
-
tags?: Set<string>;
|
|
559
549
|
machine?: StateMachine<TContext, TEvent, any, any, any, any, any, any, any>;
|
|
560
550
|
}
|
|
561
551
|
export interface ActorOptions<TLogic extends AnyActorLogic> {
|
|
552
|
+
/**
|
|
553
|
+
* The clock that is responsible for setting and clearing timeouts, such as delayed events and transitions.
|
|
554
|
+
*
|
|
555
|
+
* @remarks
|
|
556
|
+
* You can create your own “clock”. The clock interface is an object with two functions/methods:
|
|
557
|
+
*
|
|
558
|
+
* - `setTimeout` - same arguments as `window.setTimeout(fn, timeout)`
|
|
559
|
+
* - `clearTimeout` - same arguments as `window.clearTimeout(id)`
|
|
560
|
+
*
|
|
561
|
+
* By default, the native `setTimeout` and `clearTimeout` functions are used.
|
|
562
|
+
*
|
|
563
|
+
* For testing, XState provides `SimulatedClock`.
|
|
564
|
+
*
|
|
565
|
+
* @see {@link Clock}
|
|
566
|
+
* @see {@link SimulatedClock}
|
|
567
|
+
*/
|
|
562
568
|
clock?: Clock;
|
|
569
|
+
/**
|
|
570
|
+
* Specifies the logger to be used for log(...) actions. Defaults to the native console.log method.
|
|
571
|
+
*/
|
|
563
572
|
logger?: (...args: any[]) => void;
|
|
564
|
-
parent?: ActorRef<any, any>;
|
|
565
573
|
/**
|
|
566
574
|
* The custom `id` for referencing this service.
|
|
567
575
|
*/
|
|
@@ -572,7 +580,6 @@ export interface ActorOptions<TLogic extends AnyActorLogic> {
|
|
|
572
580
|
* Default: `false`
|
|
573
581
|
*/
|
|
574
582
|
devTools?: boolean | DevToolsAdapter;
|
|
575
|
-
sync?: boolean;
|
|
576
583
|
/**
|
|
577
584
|
* The system ID to register this actor under
|
|
578
585
|
*/
|
|
@@ -581,11 +588,98 @@ export interface ActorOptions<TLogic extends AnyActorLogic> {
|
|
|
581
588
|
* The input data to pass to the actor.
|
|
582
589
|
*/
|
|
583
590
|
input?: InputFrom<TLogic>;
|
|
591
|
+
/**
|
|
592
|
+
* Initializes actor logic from a specific persisted internal state.
|
|
593
|
+
*
|
|
594
|
+
* @remarks
|
|
595
|
+
*
|
|
596
|
+
* If the state is compatible with the actor logic, when the actor is started it will be at that persisted state.
|
|
597
|
+
* Actions from machine actors will not be re-executed, because they are assumed to have been already executed.
|
|
598
|
+
* However, invocations will be restarted, and spawned actors will be restored recursively.
|
|
599
|
+
*
|
|
600
|
+
* Can be generated with {@link Actor.getPersistedState}.
|
|
601
|
+
*
|
|
602
|
+
* @see https://stately.ai/docs/persistence
|
|
603
|
+
*/
|
|
584
604
|
state?: any;
|
|
585
605
|
/**
|
|
586
606
|
* The source definition.
|
|
587
607
|
*/
|
|
588
608
|
src?: string | AnyActorLogic;
|
|
609
|
+
/**
|
|
610
|
+
* A callback function or observer object which can be used to inspect actor system updates.
|
|
611
|
+
*
|
|
612
|
+
* @remarks
|
|
613
|
+
* If a callback function is provided, it can accept an inspection event argument. The types of inspection events that can be observed include:
|
|
614
|
+
*
|
|
615
|
+
* - `@xstate.actor` - An actor ref has been created in the system
|
|
616
|
+
* - `@xstate.event` - An event was sent from a source actor ref to a target actor ref in the system
|
|
617
|
+
* - `@xstate.snapshot` - An actor ref emitted a snapshot due to a received event
|
|
618
|
+
*
|
|
619
|
+
* @example
|
|
620
|
+
* ```ts
|
|
621
|
+
* import { createMachine } from 'xstate';
|
|
622
|
+
*
|
|
623
|
+
* const machine = createMachine({
|
|
624
|
+
* // ...
|
|
625
|
+
* });
|
|
626
|
+
*
|
|
627
|
+
* const actor = createActor(machine, {
|
|
628
|
+
* inspect: (inspectionEvent) => {
|
|
629
|
+
* if (inspectionEvent.actorRef === actor) {
|
|
630
|
+
* // This event is for the root actor
|
|
631
|
+
* }
|
|
632
|
+
*
|
|
633
|
+
* if (inspectionEvent.type === '@xstate.actor') {
|
|
634
|
+
* console.log(inspectionEvent.actorRef);
|
|
635
|
+
* }
|
|
636
|
+
*
|
|
637
|
+
* if (inspectionEvent.type === '@xstate.event') {
|
|
638
|
+
* console.log(inspectionEvent.sourceRef);
|
|
639
|
+
* console.log(inspectionEvent.actorRef);
|
|
640
|
+
* console.log(inspectionEvent.event);
|
|
641
|
+
* }
|
|
642
|
+
*
|
|
643
|
+
* if (inspectionEvent.type === '@xstate.snapshot') {
|
|
644
|
+
* console.log(inspectionEvent.actorRef);
|
|
645
|
+
* console.log(inspectionEvent.event);
|
|
646
|
+
* console.log(inspectionEvent.snapshot);
|
|
647
|
+
* }
|
|
648
|
+
* }
|
|
649
|
+
* });
|
|
650
|
+
* ```
|
|
651
|
+
*
|
|
652
|
+
* Alternately, an observer object (`{ next?, error?, complete? }`) can be provided:
|
|
653
|
+
*
|
|
654
|
+
* @example
|
|
655
|
+
* ```ts
|
|
656
|
+
* const actor = createActor(machine, {
|
|
657
|
+
* inspect: {
|
|
658
|
+
* next: (inspectionEvent) => {
|
|
659
|
+
* if (inspectionEvent.actorRef === actor) {
|
|
660
|
+
* // This event is for the root actor
|
|
661
|
+
* }
|
|
662
|
+
*
|
|
663
|
+
* if (inspectionEvent.type === '@xstate.actor') {
|
|
664
|
+
* console.log(inspectionEvent.actorRef);
|
|
665
|
+
* }
|
|
666
|
+
*
|
|
667
|
+
* if (inspectionEvent.type === '@xstate.event') {
|
|
668
|
+
* console.log(inspectionEvent.sourceRef);
|
|
669
|
+
* console.log(inspectionEvent.actorRef);
|
|
670
|
+
* console.log(inspectionEvent.event);
|
|
671
|
+
* }
|
|
672
|
+
*
|
|
673
|
+
* if (inspectionEvent.type === '@xstate.snapshot') {
|
|
674
|
+
* console.log(inspectionEvent.actorRef);
|
|
675
|
+
* console.log(inspectionEvent.event);
|
|
676
|
+
* console.log(inspectionEvent.snapshot);
|
|
677
|
+
* }
|
|
678
|
+
* }
|
|
679
|
+
* }
|
|
680
|
+
* });
|
|
681
|
+
* ```
|
|
682
|
+
*/
|
|
589
683
|
inspect?: Observer<InspectionEvent> | ((inspectionEvent: InspectionEvent) => void);
|
|
590
684
|
}
|
|
591
685
|
export type AnyActor = Actor<any>;
|
|
@@ -680,14 +774,52 @@ export type Snapshot<TOutput> = {
|
|
|
680
774
|
output: undefined;
|
|
681
775
|
error: undefined;
|
|
682
776
|
};
|
|
777
|
+
/**
|
|
778
|
+
* Represents logic which can be used by an actor.
|
|
779
|
+
*
|
|
780
|
+
* @template TSnapshot - The type of the snapshot.
|
|
781
|
+
* @template TEvent - The type of the event object.
|
|
782
|
+
* @template TInput - The type of the input.
|
|
783
|
+
* @template TSystem - The type of the actor system.
|
|
784
|
+
*/
|
|
683
785
|
export interface ActorLogic<TSnapshot extends Snapshot<unknown>, TEvent extends EventObject, TInput = unknown, TSystem extends ActorSystem<any> = ActorSystem<any>> {
|
|
786
|
+
/** The initial setup/configuration used to create the actor logic. */
|
|
684
787
|
config?: unknown;
|
|
788
|
+
/**
|
|
789
|
+
* Transition function that processes the current state and an incoming message
|
|
790
|
+
* to produce a new state.
|
|
791
|
+
* @param state - The current state.
|
|
792
|
+
* @param message - The incoming message.
|
|
793
|
+
* @param ctx - The actor scope.
|
|
794
|
+
* @returns The new state.
|
|
795
|
+
*/
|
|
685
796
|
transition: (state: TSnapshot, message: TEvent, ctx: ActorScope<TSnapshot, TEvent, TSystem>) => TSnapshot;
|
|
797
|
+
/**
|
|
798
|
+
* Called to provide the initial state of the actor.
|
|
799
|
+
* @param actorScope - The actor scope.
|
|
800
|
+
* @param input - The input for the initial state.
|
|
801
|
+
* @returns The initial state.
|
|
802
|
+
*/
|
|
686
803
|
getInitialState: (actorScope: ActorScope<TSnapshot, TEvent, TSystem>, input: TInput) => TSnapshot;
|
|
804
|
+
/**
|
|
805
|
+
* Called when Actor is created to restore the internal state of the actor given a persisted state.
|
|
806
|
+
* The persisted state can be created by `getPersistedState`.
|
|
807
|
+
* @param persistedState - The persisted state to restore from.
|
|
808
|
+
* @param actorScope - The actor scope.
|
|
809
|
+
* @returns The restored state.
|
|
810
|
+
*/
|
|
687
811
|
restoreState?: (persistedState: Snapshot<unknown>, actorScope: ActorScope<TSnapshot, TEvent>) => TSnapshot;
|
|
812
|
+
/**
|
|
813
|
+
* Called when the actor is started.
|
|
814
|
+
* @param state - The starting state.
|
|
815
|
+
* @param actorScope - The actor scope.
|
|
816
|
+
*/
|
|
688
817
|
start?: (state: TSnapshot, actorScope: ActorScope<TSnapshot, TEvent>) => void;
|
|
689
818
|
/**
|
|
690
|
-
*
|
|
819
|
+
* Obtains the internal state of the actor in a representation which can be be persisted.
|
|
820
|
+
* The persisted state can be restored by `restoreState`.
|
|
821
|
+
* @param state - The current state.
|
|
822
|
+
* @returns The a representation of the internal state to be persisted.
|
|
691
823
|
*/
|
|
692
824
|
getPersistedState: (state: TSnapshot, options?: unknown) => Snapshot<unknown>;
|
|
693
825
|
}
|
|
@@ -697,9 +829,9 @@ any, // input
|
|
|
697
829
|
any>;
|
|
698
830
|
export type SnapshotFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends ActorRef<infer _, infer TSnapshot> ? TSnapshot : R extends Actor<infer TLogic> ? SnapshotFrom<TLogic> : R extends StateMachine<infer _TContext, infer _TEvent, infer _TActor, infer _TAction, infer _TGuard, infer _TDelay, infer _TTag, infer _TInput, infer _TOutput, infer _TResolvedTypesMeta> ? StateFrom<R> : R extends ActorLogic<any, any, any, any> ? ReturnType<R['transition']> : R extends ActorScope<infer TSnapshot, infer _, infer __> ? TSnapshot : never : never;
|
|
699
831
|
export type EventFromLogic<TLogic extends ActorLogic<any, any, any, any>> = TLogic extends ActorLogic<infer _, infer TEvent, infer __, infer _____> ? TEvent : never;
|
|
700
|
-
type ResolveEventType<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<infer _TContext, infer TEvent, infer _TActor, infer _TAction, infer _TGuard, infer _TDelay, infer _TTag, infer _TInput, infer _TOutput, infer _TResolvedTypesMeta> ? TEvent : R extends
|
|
832
|
+
type ResolveEventType<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<infer _TContext, infer TEvent, infer _TActor, infer _TAction, infer _TGuard, infer _TDelay, infer _TTag, infer _TInput, infer _TOutput, infer _TResolvedTypesMeta> ? TEvent : R extends MachineSnapshot<infer _TContext, infer TEvent, infer _TActor, infer _TTag, infer _TOutput, infer _TResolvedTypesMeta> ? TEvent : R extends ActorRef<infer TEvent, infer _> ? TEvent : never : never;
|
|
701
833
|
export type EventFrom<T, K extends Prop<TEvent, 'type'> = never, TEvent extends EventObject = ResolveEventType<T>> = IsNever<K> extends true ? TEvent : ExtractEvent<TEvent, K>;
|
|
702
|
-
export type ContextFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<infer TContext, infer _TEvent, infer _TActor, infer _TAction, infer _TGuard, infer _TDelay, infer _TTag, infer _TInput, infer _TOutput, infer _TTypesMeta> ? TContext : R extends
|
|
834
|
+
export type ContextFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<infer TContext, infer _TEvent, infer _TActor, infer _TAction, infer _TGuard, infer _TDelay, infer _TTag, infer _TInput, infer _TOutput, infer _TTypesMeta> ? TContext : R extends MachineSnapshot<infer TContext, infer _TEvent, infer _TActor, infer _TTag, infer _TOutput, infer _TResolvedTypesMeta> ? TContext : R extends Actor<infer TActorLogic> ? TActorLogic extends StateMachine<infer TContext, infer _TEvent, infer _TActor, infer _TAction, infer _TGuard, infer _TDelay, infer _TTag, infer _TInput, infer _TOutput, infer _TTypesMeta> ? TContext : never : never : never;
|
|
703
835
|
export type InferEvent<E extends EventObject> = {
|
|
704
836
|
[T in E['type']]: {
|
|
705
837
|
type: T;
|