xstate 5.14.0 → 5.16.0
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 +2 -2
- package/actions/dist/xstate-actions.development.cjs.js +2 -2
- package/actions/dist/xstate-actions.development.esm.js +2 -2
- package/actions/dist/xstate-actions.esm.js +2 -2
- 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 +272 -65
- package/actors/dist/xstate-actors.development.cjs.js +272 -65
- package/actors/dist/xstate-actors.development.esm.js +272 -65
- package/actors/dist/xstate-actors.esm.js +272 -65
- package/actors/dist/xstate-actors.umd.min.js.map +1 -1
- package/dist/declarations/src/State.d.ts +23 -27
- package/dist/declarations/src/StateMachine.d.ts +19 -31
- package/dist/declarations/src/StateNode.d.ts +29 -51
- package/dist/declarations/src/actions/assign.d.ts +29 -27
- package/dist/declarations/src/actions/cancel.d.ts +28 -22
- package/dist/declarations/src/actions/emit.d.ts +33 -33
- package/dist/declarations/src/actions/enqueueActions.d.ts +21 -18
- package/dist/declarations/src/actions/log.d.ts +5 -4
- package/dist/declarations/src/actions/send.d.ts +5 -3
- package/dist/declarations/src/actors/callback.d.ts +65 -26
- package/dist/declarations/src/actors/index.d.ts +4 -4
- package/dist/declarations/src/actors/observable.d.ts +65 -22
- package/dist/declarations/src/actors/promise.d.ts +86 -9
- package/dist/declarations/src/actors/transition.d.ts +89 -15
- package/dist/declarations/src/assert.d.ts +21 -20
- package/dist/declarations/src/createActor.d.ts +51 -42
- package/dist/declarations/src/createMachine.d.ts +40 -54
- package/dist/declarations/src/getNextSnapshot.d.ts +27 -24
- package/dist/declarations/src/guards.d.ts +67 -66
- package/dist/declarations/src/index.d.ts +1 -2
- package/dist/declarations/src/inspection.d.ts +1 -0
- package/dist/declarations/src/setup.d.ts +1 -2
- package/dist/declarations/src/spawn.d.ts +2 -5
- package/dist/declarations/src/stateUtils.d.ts +5 -10
- package/dist/declarations/src/toPromise.d.ts +1 -0
- package/dist/declarations/src/types.d.ts +164 -189
- package/dist/declarations/src/waitFor.d.ts +9 -9
- package/dist/{log-c943e6aa.development.esm.js → log-17f4495d.development.esm.js} +115 -117
- package/dist/{log-505687fd.development.cjs.js → log-31321d85.development.cjs.js} +115 -117
- package/dist/{log-b87cb6bd.esm.js → log-8320f5e6.esm.js} +115 -117
- package/dist/{log-7ae0ddf8.cjs.js → log-f9587b82.cjs.js} +115 -117
- package/dist/{raise-4e39e875.esm.js → raise-2cfe6b8f.esm.js} +164 -154
- package/dist/{raise-0f400094.development.esm.js → raise-7d030497.development.esm.js} +164 -154
- package/dist/{raise-f79d2832.cjs.js → raise-a6298350.cjs.js} +164 -154
- package/dist/{raise-0cd7e521.development.cjs.js → raise-bad6a97b.development.cjs.js} +164 -154
- package/dist/xstate.cjs.js +134 -157
- package/dist/xstate.development.cjs.js +134 -157
- package/dist/xstate.development.esm.js +136 -159
- package/dist/xstate.esm.js +136 -159
- package/dist/xstate.umd.min.js +1 -1
- package/dist/xstate.umd.min.js.map +1 -1
- package/guards/dist/xstate-guards.cjs.js +1 -1
- package/guards/dist/xstate-guards.development.cjs.js +1 -1
- package/guards/dist/xstate-guards.development.esm.js +1 -1
- package/guards/dist/xstate-guards.esm.js +1 -1
- package/guards/dist/xstate-guards.umd.min.js.map +1 -1
- package/package.json +1 -1
- package/dist/declarations/src/typegenTypes.d.ts +0 -168
|
@@ -13,22 +13,21 @@ export declare enum ProcessingStatus {
|
|
|
13
13
|
Stopped = 2
|
|
14
14
|
}
|
|
15
15
|
/**
|
|
16
|
-
* An Actor is a running process that can receive events, send events and change
|
|
16
|
+
* An Actor is a running process that can receive events, send events and change
|
|
17
|
+
* its behavior based on the events it receives, which can cause effects outside
|
|
18
|
+
* of the actor. When you run a state machine, it becomes an actor.
|
|
17
19
|
*/
|
|
18
20
|
export declare class Actor<TLogic extends AnyActorLogic> implements ActorRef<SnapshotFrom<TLogic>, EventFromLogic<TLogic>, EmittedFrom<TLogic>> {
|
|
19
21
|
logic: TLogic;
|
|
20
|
-
/**
|
|
21
|
-
* The current internal state of the actor.
|
|
22
|
-
*/
|
|
22
|
+
/** The current internal state of the actor. */
|
|
23
23
|
private _snapshot;
|
|
24
24
|
/**
|
|
25
|
-
* The clock that is responsible for setting and clearing timeouts, such as
|
|
25
|
+
* The clock that is responsible for setting and clearing timeouts, such as
|
|
26
|
+
* delayed events and transitions.
|
|
26
27
|
*/
|
|
27
28
|
clock: Clock;
|
|
28
29
|
options: Readonly<ActorOptions<TLogic>>;
|
|
29
|
-
/**
|
|
30
|
-
* The unique identifier for this actor relative to its parent.
|
|
31
|
-
*/
|
|
30
|
+
/** The unique identifier for this actor relative to its parent. */
|
|
32
31
|
id: string;
|
|
33
32
|
private mailbox;
|
|
34
33
|
private observers;
|
|
@@ -38,18 +37,15 @@ export declare class Actor<TLogic extends AnyActorLogic> implements ActorRef<Sna
|
|
|
38
37
|
ref: ActorRef<SnapshotFrom<TLogic>, EventFromLogic<TLogic>, EmittedFrom<TLogic>>;
|
|
39
38
|
private _actorScope;
|
|
40
39
|
private _systemId;
|
|
41
|
-
/**
|
|
42
|
-
* The globally unique process ID for this invocation.
|
|
43
|
-
*/
|
|
40
|
+
/** The globally unique process ID for this invocation. */
|
|
44
41
|
sessionId: string;
|
|
45
|
-
/**
|
|
46
|
-
* The system to which this actor belongs.
|
|
47
|
-
*/
|
|
42
|
+
/** The system to which this actor belongs. */
|
|
48
43
|
system: AnyActorSystem;
|
|
49
44
|
private _doneEvent?;
|
|
50
45
|
src: string | AnyActorLogic;
|
|
51
46
|
/**
|
|
52
|
-
* Creates a new actor instance for the given logic with the provided options,
|
|
47
|
+
* Creates a new actor instance for the given logic with the provided options,
|
|
48
|
+
* if any.
|
|
53
49
|
*
|
|
54
50
|
* @param logic The logic to create an actor from
|
|
55
51
|
* @param options Actor options
|
|
@@ -62,11 +58,15 @@ export declare class Actor<TLogic extends AnyActorLogic> implements ActorRef<Sna
|
|
|
62
58
|
* Subscribe an observer to an actor’s snapshot values.
|
|
63
59
|
*
|
|
64
60
|
* @remarks
|
|
65
|
-
* The observer will receive the actor’s snapshot value when it is emitted.
|
|
61
|
+
* The observer will receive the actor’s snapshot value when it is emitted.
|
|
62
|
+
* The observer can be:
|
|
63
|
+
*
|
|
66
64
|
* - A plain function that receives the latest snapshot, or
|
|
67
|
-
* - An observer object whose `.next(snapshot)` method receives the latest
|
|
65
|
+
* - An observer object whose `.next(snapshot)` method receives the latest
|
|
66
|
+
* snapshot
|
|
68
67
|
*
|
|
69
68
|
* @example
|
|
69
|
+
*
|
|
70
70
|
* ```ts
|
|
71
71
|
* // Observer as a plain function
|
|
72
72
|
* const subscription = actor.subscribe((snapshot) => {
|
|
@@ -75,6 +75,7 @@ export declare class Actor<TLogic extends AnyActorLogic> implements ActorRef<Sna
|
|
|
75
75
|
* ```
|
|
76
76
|
*
|
|
77
77
|
* @example
|
|
78
|
+
*
|
|
78
79
|
* ```ts
|
|
79
80
|
* // Observer as an object
|
|
80
81
|
* const subscription = actor.subscribe({
|
|
@@ -86,13 +87,16 @@ export declare class Actor<TLogic extends AnyActorLogic> implements ActorRef<Sna
|
|
|
86
87
|
* },
|
|
87
88
|
* complete() {
|
|
88
89
|
* // ...
|
|
89
|
-
* }
|
|
90
|
+
* }
|
|
90
91
|
* });
|
|
91
92
|
* ```
|
|
92
93
|
*
|
|
93
|
-
* The return value of `actor.subscribe(observer)` is a subscription object
|
|
94
|
+
* The return value of `actor.subscribe(observer)` is a subscription object
|
|
95
|
+
* that has an `.unsubscribe()` method. You can call
|
|
96
|
+
* `subscription.unsubscribe()` to unsubscribe the observer:
|
|
94
97
|
*
|
|
95
98
|
* @example
|
|
99
|
+
*
|
|
96
100
|
* ```ts
|
|
97
101
|
* const subscription = actor.subscribe((snapshot) => {
|
|
98
102
|
* // ...
|
|
@@ -102,24 +106,23 @@ export declare class Actor<TLogic extends AnyActorLogic> implements ActorRef<Sna
|
|
|
102
106
|
* subscription.unsubscribe();
|
|
103
107
|
* ```
|
|
104
108
|
*
|
|
105
|
-
* When the actor is stopped, all of its observers will automatically be
|
|
109
|
+
* When the actor is stopped, all of its observers will automatically be
|
|
110
|
+
* unsubscribed.
|
|
106
111
|
*
|
|
107
|
-
* @param observer - Either a plain function that receives the latest
|
|
112
|
+
* @param observer - Either a plain function that receives the latest
|
|
113
|
+
* snapshot, or an observer object whose `.next(snapshot)` method receives
|
|
114
|
+
* the latest snapshot
|
|
108
115
|
*/
|
|
109
116
|
subscribe(observer: Observer<SnapshotFrom<TLogic>>): Subscription;
|
|
110
117
|
subscribe(nextListener?: (snapshot: SnapshotFrom<TLogic>) => void, errorListener?: (error: any) => void, completeListener?: () => void): Subscription;
|
|
111
118
|
on<TType extends EmittedFrom<TLogic>['type'] | '*'>(type: TType, handler: (emitted: EmittedFrom<TLogic> & (TType extends '*' ? {} : {
|
|
112
119
|
type: TType;
|
|
113
120
|
})) => void): Subscription;
|
|
114
|
-
/**
|
|
115
|
-
* Starts the Actor from the initial state
|
|
116
|
-
*/
|
|
121
|
+
/** Starts the Actor from the initial state */
|
|
117
122
|
start(): this;
|
|
118
123
|
private _process;
|
|
119
124
|
private _stop;
|
|
120
|
-
/**
|
|
121
|
-
* Stops the Actor and unsubscribe all listeners.
|
|
122
|
-
*/
|
|
125
|
+
/** Stops the Actor and unsubscribe all listeners. */
|
|
123
126
|
stop(): this;
|
|
124
127
|
private _complete;
|
|
125
128
|
private _reportError;
|
|
@@ -142,10 +145,11 @@ export declare class Actor<TLogic extends AnyActorLogic> implements ActorRef<Sna
|
|
|
142
145
|
* @remarks
|
|
143
146
|
* The internal state can be persisted from any actor, not only machines.
|
|
144
147
|
*
|
|
145
|
-
* Note that the persisted state is not the same as the snapshot from
|
|
148
|
+
* Note that the persisted state is not the same as the snapshot from
|
|
149
|
+
* {@link Actor.getSnapshot}. Persisted state represents the internal state of
|
|
150
|
+
* the actor, while snapshots represent the actor's last emitted value.
|
|
146
151
|
*
|
|
147
152
|
* Can be restored with {@link ActorOptions.state}
|
|
148
|
-
*
|
|
149
153
|
* @see https://stately.ai/docs/persistence
|
|
150
154
|
*/
|
|
151
155
|
getPersistedSnapshot(): Snapshot<unknown>;
|
|
@@ -156,11 +160,11 @@ export declare class Actor<TLogic extends AnyActorLogic> implements ActorRef<Sna
|
|
|
156
160
|
* @remarks
|
|
157
161
|
* The snapshot represent an actor's last emitted value.
|
|
158
162
|
*
|
|
159
|
-
* When an actor receives an event, its internal state may change.
|
|
160
|
-
*
|
|
161
|
-
*
|
|
162
|
-
* Note that some actors, such as callback actors generated with `fromCallback`, will not emit snapshots.
|
|
163
|
+
* When an actor receives an event, its internal state may change. An actor
|
|
164
|
+
* may emit a snapshot when a state transition occurs.
|
|
163
165
|
*
|
|
166
|
+
* Note that some actors, such as callback actors generated with
|
|
167
|
+
* `fromCallback`, will not emit snapshots.
|
|
164
168
|
* @see {@link Actor.subscribe} to subscribe to an actor’s snapshot values.
|
|
165
169
|
* @see {@link Actor.getPersistedSnapshot} to persist the internal state of an actor (which is more than just a snapshot).
|
|
166
170
|
*/
|
|
@@ -168,13 +172,16 @@ export declare class Actor<TLogic extends AnyActorLogic> implements ActorRef<Sna
|
|
|
168
172
|
}
|
|
169
173
|
type RequiredOptions<TLogic extends AnyActorLogic> = undefined extends InputFrom<TLogic> ? never : 'input';
|
|
170
174
|
/**
|
|
171
|
-
* Creates a new actor instance for the given actor logic with the provided
|
|
175
|
+
* Creates a new actor instance for the given actor logic with the provided
|
|
176
|
+
* options, if any.
|
|
172
177
|
*
|
|
173
178
|
* @remarks
|
|
174
|
-
* When you create an actor from actor logic via `createActor(logic)`, you
|
|
175
|
-
*
|
|
176
|
-
*
|
|
179
|
+
* When you create an actor from actor logic via `createActor(logic)`, you
|
|
180
|
+
* implicitly create an actor system where the created actor is the root actor.
|
|
181
|
+
* Any actors spawned from this root actor and its descendants are part of that
|
|
182
|
+
* actor system.
|
|
177
183
|
* @example
|
|
184
|
+
*
|
|
178
185
|
* ```ts
|
|
179
186
|
* import { createActor } from 'xstate';
|
|
180
187
|
* import { someActorLogic } from './someActorLogic.ts';
|
|
@@ -196,7 +203,10 @@ type RequiredOptions<TLogic extends AnyActorLogic> = undefined extends InputFrom
|
|
|
196
203
|
* actor.stop();
|
|
197
204
|
* ```
|
|
198
205
|
*
|
|
199
|
-
* @param logic - The actor logic to create an actor from. For a state machine
|
|
206
|
+
* @param logic - The actor logic to create an actor from. For a state machine
|
|
207
|
+
* actor logic creator, see {@link createMachine}. Other actor logic creators
|
|
208
|
+
* include {@link fromCallback}, {@link fromEventObservable},
|
|
209
|
+
* {@link fromObservable}, {@link fromPromise}, and {@link fromTransition}.
|
|
200
210
|
* @param options - Actor options
|
|
201
211
|
*/
|
|
202
212
|
export declare function createActor<TLogic extends AnyActorLogic>(logic: TLogic, ...[options]: ConditionalRequired<[
|
|
@@ -205,13 +215,12 @@ export declare function createActor<TLogic extends AnyActorLogic>(logic: TLogic,
|
|
|
205
215
|
}
|
|
206
216
|
], IsNotNever<RequiredOptions<TLogic>>>): Actor<TLogic>;
|
|
207
217
|
/**
|
|
208
|
-
* Creates a new Interpreter instance for the given machine with the provided
|
|
218
|
+
* Creates a new Interpreter instance for the given machine with the provided
|
|
219
|
+
* options, if any.
|
|
209
220
|
*
|
|
210
221
|
* @deprecated Use `createActor` instead
|
|
211
222
|
*/
|
|
212
223
|
export declare const interpret: typeof createActor;
|
|
213
|
-
/**
|
|
214
|
-
* @deprecated Use `Actor` instead.
|
|
215
|
-
*/
|
|
224
|
+
/** @deprecated Use `Actor` instead. */
|
|
216
225
|
export type Interpreter = typeof Actor;
|
|
217
226
|
export {};
|
|
@@ -1,64 +1,50 @@
|
|
|
1
1
|
import { StateMachine } from "./StateMachine.js";
|
|
2
|
-
import {
|
|
3
|
-
import { AnyActorRef, EventObject, AnyEventObject, Cast, InternalMachineImplementations,
|
|
4
|
-
type TestValue = string | {
|
|
5
|
-
[k: string]: TestValue | undefined;
|
|
6
|
-
};
|
|
7
|
-
type _GroupTestValues<TTestValue extends string | TestValue> = TTestValue extends string ? TTestValue extends `${string}.${string}` ? [never, never] : [TTestValue, never] : [never, TTestValue];
|
|
8
|
-
type GroupTestValues<TTestValue extends string | TestValue> = {
|
|
9
|
-
leafCandidates: _GroupTestValues<TTestValue>[0];
|
|
10
|
-
nonLeaf: _GroupTestValues<TTestValue>[1];
|
|
11
|
-
};
|
|
12
|
-
type FilterLeafValues<TLeafCandidate extends string, TNonLeaf extends {
|
|
13
|
-
[k: string]: TestValue | undefined;
|
|
14
|
-
}> = IsNever<TNonLeaf> extends true ? TLeafCandidate : TLeafCandidate extends string ? TLeafCandidate extends keyof TNonLeaf ? never : TLeafCandidate : never;
|
|
15
|
-
type ToStateValue<TTestValue extends string | TestValue> = FilterLeafValues<GroupTestValues<TTestValue>['leafCandidates'], GroupTestValues<TTestValue>['nonLeaf']> | (IsNever<GroupTestValues<TTestValue>['nonLeaf']> extends false ? {
|
|
16
|
-
[K in keyof GroupTestValues<TTestValue>['nonLeaf']]: ToStateValue<NonNullable<GroupTestValues<TTestValue>['nonLeaf'][K]>>;
|
|
17
|
-
} : never);
|
|
2
|
+
import { ResolvedStateMachineTypes } from "./types.js";
|
|
3
|
+
import { AnyActorRef, EventObject, AnyEventObject, Cast, InternalMachineImplementations, MachineConfig, MachineContext, MachineTypes, NonReducibleUnknown, ParameterizedObject, ProvidedActor, StateValue, ToChildren, MetaObject } from "./types.js";
|
|
18
4
|
/**
|
|
19
5
|
* Creates a state machine (statechart) with the given configuration.
|
|
20
6
|
*
|
|
21
7
|
* The state machine represents the pure logic of a state machine actor.
|
|
22
8
|
*
|
|
23
|
-
* @param config The state machine configuration.
|
|
24
|
-
* @param options DEPRECATED: use `setup({ ... })` or `machine.provide({ ... })` to provide machine implementations instead.
|
|
25
|
-
*
|
|
26
9
|
* @example
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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.
|
|
57
45
|
*/
|
|
58
46
|
export declare function createMachine<TContext extends MachineContext, TEvent extends AnyEventObject, // TODO: consider using a stricter `EventObject` here
|
|
59
|
-
TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string, TTag extends string, TInput, TOutput extends NonReducibleUnknown, TEmitted extends EventObject, TMeta extends MetaObject,
|
|
60
|
-
types?: MachineTypes<TContext, TEvent, TActor, TAction, TGuard, TDelay, TTag, TInput, TOutput, TEmitted, TMeta
|
|
47
|
+
TActor 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>;
|
|
61
49
|
schemas?: unknown;
|
|
62
|
-
} & MachineConfig<TContext, TEvent, TActor, TAction, TGuard, TDelay, TTag, TInput, TOutput, TEmitted, TMeta
|
|
63
|
-
ResolveTypegenMeta<TTypesMeta, TEvent, TActor, TAction, TGuard, TDelay, TTag, TEmitted>>;
|
|
64
|
-
export {};
|
|
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>;
|
|
@@ -1,32 +1,35 @@
|
|
|
1
1
|
import { AnyActorLogic, EventFromLogic, InputFrom, SnapshotFrom } from "./types.js";
|
|
2
2
|
export declare function getInitialSnapshot<T extends AnyActorLogic>(actorLogic: T, ...[input]: undefined extends InputFrom<T> ? [input?: InputFrom<T>] : [input: InputFrom<T>]): SnapshotFrom<T>;
|
|
3
3
|
/**
|
|
4
|
-
* Determines the next snapshot for the given `actorLogic` based on
|
|
5
|
-
*
|
|
4
|
+
* Determines the next snapshot for the given `actorLogic` based on the given
|
|
5
|
+
* `snapshot` and `event`.
|
|
6
6
|
*
|
|
7
|
-
* If the `snapshot` is `undefined`, the initial snapshot of the
|
|
8
|
-
*
|
|
7
|
+
* If the `snapshot` is `undefined`, the initial snapshot of the `actorLogic` is
|
|
8
|
+
* used.
|
|
9
9
|
*
|
|
10
10
|
* @example
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
+
* ```
|
|
31
34
|
*/
|
|
32
35
|
export declare function getNextSnapshot<T extends AnyActorLogic>(actorLogic: T, snapshot: SnapshotFrom<T>, event: EventFromLogic<T>): SnapshotFrom<T>;
|
|
@@ -27,29 +27,32 @@ type UnknownReferencedGuard = Guard<MachineContext, EventObject, ParameterizedOb
|
|
|
27
27
|
type UnknownInlineGuard = Guard<MachineContext, EventObject, undefined, ParameterizedObject>;
|
|
28
28
|
export declare function stateIn<TContext extends MachineContext, TExpressionEvent extends EventObject, TParams extends ParameterizedObject['params'] | undefined>(stateValue: StateValue): GuardPredicate<TContext, TExpressionEvent, TParams, any>;
|
|
29
29
|
/**
|
|
30
|
-
* Higher-order guard that evaluates to `true` if the `guard` passed to it
|
|
30
|
+
* Higher-order guard that evaluates to `true` if the `guard` passed to it
|
|
31
|
+
* evaluates to `false`.
|
|
31
32
|
*
|
|
32
33
|
* @category Guards
|
|
33
34
|
* @example
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
35
|
+
*
|
|
36
|
+
* ```ts
|
|
37
|
+
* import { setup, not } from 'xstate';
|
|
38
|
+
*
|
|
39
|
+
* const machine = setup({
|
|
40
|
+
* guards: {
|
|
41
|
+
* someNamedGuard: () => false
|
|
42
|
+
* }
|
|
43
|
+
* }).createMachine({
|
|
44
|
+
* on: {
|
|
45
|
+
* someEvent: {
|
|
46
|
+
* guard: not('someNamedGuard'),
|
|
47
|
+
* actions: () => {
|
|
48
|
+
* // will be executed if guard in `not(...)`
|
|
49
|
+
* // evaluates to `false`
|
|
50
|
+
* }
|
|
51
|
+
* }
|
|
52
|
+
* }
|
|
53
|
+
* });
|
|
54
|
+
* ```
|
|
55
|
+
*
|
|
53
56
|
* @returns A guard
|
|
54
57
|
*/
|
|
55
58
|
export declare function not<TContext extends MachineContext, TExpressionEvent extends EventObject, TArg>(guard: SingleGuardArg<TContext, TExpressionEvent, unknown, TArg>): GuardPredicate<TContext, TExpressionEvent, unknown, NormalizeGuardArg<DoNotInfer<TArg>>>;
|
|
@@ -59,28 +62,27 @@ export declare function not<TContext extends MachineContext, TExpressionEvent ex
|
|
|
59
62
|
*
|
|
60
63
|
* @category Guards
|
|
61
64
|
* @example
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
```
|
|
65
|
+
*
|
|
66
|
+
* ```ts
|
|
67
|
+
* import { setup, and } from 'xstate';
|
|
68
|
+
*
|
|
69
|
+
* const machine = setup({
|
|
70
|
+
* guards: {
|
|
71
|
+
* someNamedGuard: () => true
|
|
72
|
+
* }
|
|
73
|
+
* }).createMachine({
|
|
74
|
+
* on: {
|
|
75
|
+
* someEvent: {
|
|
76
|
+
* guard: and([({ context }) => context.value > 0, 'someNamedGuard']),
|
|
77
|
+
* actions: () => {
|
|
78
|
+
* // will be executed if all guards in `and(...)`
|
|
79
|
+
* // evaluate to true
|
|
80
|
+
* }
|
|
81
|
+
* }
|
|
82
|
+
* }
|
|
83
|
+
* });
|
|
84
|
+
* ```
|
|
85
|
+
*
|
|
84
86
|
* @returns A guard action object
|
|
85
87
|
*/
|
|
86
88
|
export declare function and<TContext extends MachineContext, TExpressionEvent extends EventObject, TArg extends unknown[]>(guards: readonly [
|
|
@@ -89,33 +91,32 @@ export declare function and<TContext extends MachineContext, TExpressionEvent ex
|
|
|
89
91
|
}
|
|
90
92
|
]): GuardPredicate<TContext, TExpressionEvent, unknown, NormalizeGuardArgArray<DoNotInfer<TArg>>>;
|
|
91
93
|
/**
|
|
92
|
-
* Higher-order guard that evaluates to `true` if any of the `guards` passed to
|
|
93
|
-
* evaluate to `true`.
|
|
94
|
+
* Higher-order guard that evaluates to `true` if any of the `guards` passed to
|
|
95
|
+
* it evaluate to `true`.
|
|
94
96
|
*
|
|
95
97
|
* @category Guards
|
|
96
98
|
* @example
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
```
|
|
99
|
+
*
|
|
100
|
+
* ```ts
|
|
101
|
+
* import { setup, or } from 'xstate';
|
|
102
|
+
*
|
|
103
|
+
* const machine = setup({
|
|
104
|
+
* guards: {
|
|
105
|
+
* someNamedGuard: () => true
|
|
106
|
+
* }
|
|
107
|
+
* }).createMachine({
|
|
108
|
+
* on: {
|
|
109
|
+
* someEvent: {
|
|
110
|
+
* guard: or([({ context }) => context.value > 0, 'someNamedGuard']),
|
|
111
|
+
* actions: () => {
|
|
112
|
+
* // will be executed if any of the guards in `or(...)`
|
|
113
|
+
* // evaluate to true
|
|
114
|
+
* }
|
|
115
|
+
* }
|
|
116
|
+
* }
|
|
117
|
+
* });
|
|
118
|
+
* ```
|
|
119
|
+
*
|
|
119
120
|
* @returns A guard action object
|
|
120
121
|
*/
|
|
121
122
|
export declare function or<TContext extends MachineContext, TExpressionEvent extends EventObject, TArg extends unknown[]>(guards: readonly [
|
|
@@ -5,12 +5,11 @@ export { type Spawner } from "./spawn.js";
|
|
|
5
5
|
export { isMachineSnapshot, type MachineSnapshot } from "./State.js";
|
|
6
6
|
export { StateMachine } from "./StateMachine.js";
|
|
7
7
|
export { getStateNodes } from "./stateUtils.js";
|
|
8
|
-
export * from "./typegenTypes.js";
|
|
9
8
|
export * from "./types.js";
|
|
10
9
|
export { waitFor } from "./waitFor.js";
|
|
11
10
|
import { createMachine } from "./createMachine.js";
|
|
12
11
|
export { getInitialSnapshot, getNextSnapshot } from "./getNextSnapshot.js";
|
|
13
|
-
import { Actor, createActor, interpret, Interpreter } from "./createActor.js";
|
|
12
|
+
import { Actor, createActor, interpret, type Interpreter } from "./createActor.js";
|
|
14
13
|
import { StateNode } from "./StateNode.js";
|
|
15
14
|
export { and, not, or, stateIn } from "./guards.js";
|
|
16
15
|
export { setup } from "./setup.js";
|
|
@@ -4,6 +4,7 @@ export interface BaseInspectionEventProperties {
|
|
|
4
4
|
rootId: string;
|
|
5
5
|
/**
|
|
6
6
|
* The relevant actorRef for the inspection event.
|
|
7
|
+
*
|
|
7
8
|
* - For snapshot events, this is the `actorRef` of the snapshot.
|
|
8
9
|
* - For event events, this is the target `actorRef` (recipient of event).
|
|
9
10
|
* - For actor events, this is the `actorRef` of the registered actor.
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { StateMachine } from "./StateMachine.js";
|
|
2
2
|
import { GuardPredicate } from "./guards.js";
|
|
3
|
-
import { ResolveTypegenMeta, TypegenDisabled } from "./typegenTypes.js";
|
|
4
3
|
import { ActionFunction, AnyActorRef, AnyEventObject, Cast, ConditionalRequired, DelayConfig, EventObject, Invert, IsNever, MachineConfig, MachineContext, MetaObject, NonReducibleUnknown, ParameterizedObject, SetupTypes, StateSchema, ToChildren, UnknownActorLogic, Values } from "./types.js";
|
|
5
4
|
type ToParameterizedObject<TParameterizedMap extends Record<string, ParameterizedObject['params'] | undefined>> = IsNever<TParameterizedMap> extends true ? never : Values<{
|
|
6
5
|
[K in keyof TParameterizedMap & string]: {
|
|
@@ -51,6 +50,6 @@ TActors extends Record<string, UnknownActorLogic> = {}, TChildrenMap extends Rec
|
|
|
51
50
|
} & {
|
|
52
51
|
[K in RequiredSetupKeys<TChildrenMap>]: unknown;
|
|
53
52
|
}): {
|
|
54
|
-
createMachine: <const TConfig extends MachineConfig<TContext, TEvent, ToProvidedActor<TChildrenMap, TActors>, ToParameterizedObject<TActions>, ToParameterizedObject<TGuards>, TDelay, TTag, TInput, TOutput, TEmitted, TMeta
|
|
53
|
+
createMachine: <const TConfig extends MachineConfig<TContext, TEvent, ToProvidedActor<TChildrenMap, TActors>, ToParameterizedObject<TActions>, ToParameterizedObject<TGuards>, TDelay, TTag, TInput, TOutput, TEmitted, TMeta>>(config: TConfig) => StateMachine<TContext, TEvent, Cast<ToChildren<ToProvidedActor<TChildrenMap, TActors>>, Record<string, AnyActorRef | undefined>>, ToProvidedActor<TChildrenMap, TActors>, ToParameterizedObject<TActions>, ToParameterizedObject<TGuards>, TDelay, ToStateValue<TConfig>, TTag, TInput, TOutput, TEmitted, TMeta>;
|
|
55
54
|
};
|
|
56
55
|
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ActorRefFrom, AnyActorLogic, AnyActorRef, AnyActorScope, AnyEventObject, AnyMachineSnapshot, ConditionalRequired, InputFrom, IsLiteralString, IsNotNever, ProvidedActor, RequiredActorOptions } from "./types.js";
|
|
1
|
+
import { ActorRefFrom, AnyActorLogic, AnyActorRef, AnyActorScope, AnyEventObject, AnyMachineSnapshot, ConditionalRequired, GetConcreteByKey, InputFrom, IsLiteralString, IsNotNever, ProvidedActor, RequiredActorOptions } from "./types.js";
|
|
2
2
|
type SpawnOptions<TActor extends ProvidedActor, TSrc extends TActor['src']> = TActor extends {
|
|
3
3
|
src: TSrc;
|
|
4
4
|
} ? ConditionalRequired<[
|
|
@@ -11,11 +11,8 @@ type SpawnOptions<TActor extends ProvidedActor, TSrc extends TActor['src']> = TA
|
|
|
11
11
|
[K in RequiredActorOptions<TActor>]: unknown;
|
|
12
12
|
}
|
|
13
13
|
], IsNotNever<RequiredActorOptions<TActor>>> : never;
|
|
14
|
-
type GetConcreteLogic<TActor extends ProvidedActor, TSrc extends TActor['src']> = Extract<TActor, {
|
|
15
|
-
src: TSrc;
|
|
16
|
-
}>['logic'];
|
|
17
14
|
export type Spawner<TActor extends ProvidedActor> = IsLiteralString<TActor['src']> extends true ? {
|
|
18
|
-
<TSrc extends TActor['src']>(logic: TSrc, ...[options]: SpawnOptions<TActor, TSrc>): ActorRefFrom<
|
|
15
|
+
<TSrc extends TActor['src']>(logic: TSrc, ...[options]: SpawnOptions<TActor, TSrc>): ActorRefFrom<GetConcreteByKey<TActor, 'src', TSrc>['logic']>;
|
|
19
16
|
<TLogic extends AnyActorLogic>(src: TLogic, options?: {
|
|
20
17
|
id?: never;
|
|
21
18
|
systemId?: string;
|
|
@@ -11,9 +11,7 @@ export declare function getStateValue(rootNode: AnyStateNode, stateNodes: AnySta
|
|
|
11
11
|
export declare function isInFinalState(stateNodeSet: Set<AnyStateNode>, stateNode: AnyStateNode): boolean;
|
|
12
12
|
export declare const isStateId: (str: string) => boolean;
|
|
13
13
|
export declare function getCandidates<TEvent extends EventObject>(stateNode: StateNode<any, TEvent>, receivedEventType: TEvent['type']): Array<TransitionDefinition<any, TEvent>>;
|
|
14
|
-
/**
|
|
15
|
-
* All delayed transitions from the config.
|
|
16
|
-
*/
|
|
14
|
+
/** All delayed transitions from the config. */
|
|
17
15
|
export declare function getDelayedTransitions(stateNode: AnyStateNode): Array<DelayedTransitionDefinition<MachineContext, EventObject>>;
|
|
18
16
|
export declare function formatTransition<TContext extends MachineContext, TEvent extends EventObject>(stateNode: AnyStateNode, descriptor: string, transitionConfig: AnyTransitionConfig): AnyTransitionDefinition;
|
|
19
17
|
export declare function formatTransitions<TContext extends MachineContext, TEvent extends EventObject>(stateNode: AnyStateNode): Map<string, TransitionDefinition<TContext, TEvent>[]>;
|
|
@@ -21,9 +19,7 @@ export declare function formatInitialTransition<TContext extends MachineContext,
|
|
|
21
19
|
export declare function resolveTarget(stateNode: AnyStateNode, targets: ReadonlyArray<string | AnyStateNode> | undefined): ReadonlyArray<AnyStateNode> | undefined;
|
|
22
20
|
export declare function getInitialStateNodesWithTheirAncestors(stateNode: AnyStateNode): Set<AnyStateNode>;
|
|
23
21
|
export declare function getInitialStateNodes(stateNode: AnyStateNode): Set<AnyStateNode>;
|
|
24
|
-
/**
|
|
25
|
-
* Returns the child state node from its relative `stateKey`, or throws.
|
|
26
|
-
*/
|
|
22
|
+
/** Returns the child state node from its relative `stateKey`, or throws. */
|
|
27
23
|
export declare function getStateNode(stateNode: AnyStateNode, stateKey: string): AnyStateNode;
|
|
28
24
|
/**
|
|
29
25
|
* Returns the relative state node from the given `statePath`, or throws.
|
|
@@ -42,9 +38,7 @@ export declare function transitionCompoundNode<TContext extends MachineContext,
|
|
|
42
38
|
export declare function transitionParallelNode<TContext extends MachineContext, TEvent extends EventObject>(stateNode: AnyStateNode, stateValue: StateValueMap, snapshot: MachineSnapshot<TContext, TEvent, any, any, any, any, any>, event: TEvent): Array<TransitionDefinition<TContext, TEvent>> | undefined;
|
|
43
39
|
export declare function transitionNode<TContext extends MachineContext, TEvent extends EventObject>(stateNode: AnyStateNode, stateValue: StateValue, snapshot: MachineSnapshot<TContext, TEvent, any, any, any, any, any>, event: TEvent): Array<TransitionDefinition<TContext, TEvent>> | undefined;
|
|
44
40
|
export declare function removeConflictingTransitions(enabledTransitions: Array<AnyTransitionDefinition>, stateNodeSet: Set<AnyStateNode>, historyValue: AnyHistoryValue): Array<AnyTransitionDefinition>;
|
|
45
|
-
/**
|
|
46
|
-
* https://www.w3.org/TR/scxml/#microstepProcedure
|
|
47
|
-
*/
|
|
41
|
+
/** https://www.w3.org/TR/scxml/#microstepProcedure */
|
|
48
42
|
export declare function microstep<TContext extends MachineContext, TEvent extends EventObject>(transitions: Array<AnyTransitionDefinition>, currentSnapshot: AnyMachineSnapshot, actorScope: AnyActorScope, event: AnyEventObject, isInitial: boolean, internalQueue: Array<AnyEventObject>): AnyMachineSnapshot;
|
|
49
43
|
export declare let executingCustomAction: ActionFunction<any, any, any, any, any, any, any, any, any> | false;
|
|
50
44
|
export declare function resolveActionsAndContext(currentSnapshot: AnyMachineSnapshot, event: AnyEventObject, actorScope: AnyActorScope, actions: UnknownAction[], internalQueue: AnyEventObject[], deferredActorIds?: string[]): AnyMachineSnapshot;
|
|
@@ -53,7 +47,8 @@ export declare function macrostep(snapshot: AnyMachineSnapshot, event: EventObje
|
|
|
53
47
|
microstates: Array<typeof snapshot>;
|
|
54
48
|
};
|
|
55
49
|
/**
|
|
56
|
-
* Resolves a partial state value with its full representation in the state
|
|
50
|
+
* Resolves a partial state value with its full representation in the state
|
|
51
|
+
* node's machine.
|
|
57
52
|
*
|
|
58
53
|
* @param stateValue The partial state value to resolve.
|
|
59
54
|
*/
|