xstate 5.0.0-beta.40 → 5.0.0-beta.42
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 +1 -1
- package/actors/dist/xstate-actors.development.cjs.js +1 -1
- package/actors/dist/xstate-actors.development.esm.js +1 -1
- package/actors/dist/xstate-actors.esm.js +1 -1
- package/actors/dist/xstate-actors.umd.min.js +1 -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 +13 -30
- package/dist/declarations/src/StateNode.d.ts +2 -2
- package/dist/declarations/src/index.d.ts +4 -5
- package/dist/declarations/src/interpreter.d.ts +14 -10
- package/dist/declarations/src/stateUtils.d.ts +7 -8
- package/dist/declarations/src/types.d.ts +114 -22
- package/dist/{interpreter-bae5c279.development.cjs.js → interpreter-23e4041c.development.cjs.js} +49 -42
- package/dist/{interpreter-ed0fac7e.esm.js → interpreter-3d0c0ff2.esm.js} +49 -40
- package/dist/{interpreter-586abde4.cjs.js → interpreter-b6bdd134.cjs.js} +49 -42
- package/dist/{interpreter-410d7ca9.development.esm.js → interpreter-f2620ea7.development.esm.js} +49 -40
- package/dist/{raise-37f9f3b8.development.esm.js → raise-51ae36e5.development.esm.js} +84 -183
- package/dist/{raise-27909189.cjs.js → raise-6b64c553.cjs.js} +81 -181
- package/dist/{raise-8325e2df.development.cjs.js → raise-8f482ce9.development.cjs.js} +85 -185
- package/dist/{raise-2b2fdec3.esm.js → raise-d2084327.esm.js} +80 -179
- package/dist/{send-59f66c58.esm.js → send-4e732fa5.esm.js} +7 -6
- package/dist/{send-f6b49072.development.esm.js → send-7a350091.development.esm.js} +7 -6
- package/dist/{send-4fdf275e.cjs.js → send-85b562d8.cjs.js} +7 -6
- package/dist/{send-c45d0d2c.development.cjs.js → send-cc8f864e.development.cjs.js} +7 -6
- package/dist/xstate.cjs.js +27 -56
- package/dist/xstate.cjs.mjs +0 -4
- package/dist/xstate.development.cjs.js +27 -56
- package/dist/xstate.development.cjs.mjs +0 -4
- package/dist/xstate.development.esm.js +31 -56
- package/dist/xstate.esm.js +31 -56
- 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,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.
|
|
@@ -92,8 +76,7 @@ export declare class StateMachine<TContext extends MachineContext, TEvent extend
|
|
|
92
76
|
getStateNodeById(stateId: string): StateNode<TContext, TEvent>;
|
|
93
77
|
get definition(): StateMachineDefinition<TContext, TEvent>;
|
|
94
78
|
toJSON(): StateMachineDefinition<TContext, TEvent>;
|
|
95
|
-
getPersistedState(state: MachineSnapshot<TContext, TEvent, TActor, TTag, TOutput, TResolvedTypesMeta
|
|
96
|
-
createState(stateConfig: MachineSnapshot<TContext, TEvent, TActor, TTag, TOutput, TResolvedTypesMeta> | StateConfig<TContext, TEvent>): MachineSnapshot<TContext, TEvent, TActor, TTag, TOutput, TResolvedTypesMeta>;
|
|
79
|
+
getPersistedState(state: MachineSnapshot<TContext, TEvent, TActor, TTag, TOutput, TResolvedTypesMeta>, options?: unknown): Snapshot<unknown>;
|
|
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
|
*/
|
|
@@ -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
|
-
import { Actor,
|
|
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,
|
|
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 {
|
|
@@ -11,15 +11,11 @@ export interface Clock {
|
|
|
11
11
|
setTimeout(fn: (...args: any[]) => void, timeout: number): any;
|
|
12
12
|
clearTimeout(id: any): void;
|
|
13
13
|
}
|
|
14
|
-
export declare enum
|
|
14
|
+
export declare enum ProcessingStatus {
|
|
15
15
|
NotStarted = 0,
|
|
16
16
|
Running = 1,
|
|
17
17
|
Stopped = 2
|
|
18
18
|
}
|
|
19
|
-
/**
|
|
20
|
-
* @deprecated Use `ActorStatus` instead.
|
|
21
|
-
*/
|
|
22
|
-
export declare const InterpreterStatus: typeof ActorStatus;
|
|
23
19
|
/**
|
|
24
20
|
* An Actor is a running process that can receive events, send events and change its behavior based on the events it receives, which can cause effects outside of the actor. When you run a state machine, it becomes an actor.
|
|
25
21
|
*/
|
|
@@ -42,10 +38,6 @@ export declare class Actor<TLogic extends AnyActorLogic> implements ActorRef<Eve
|
|
|
42
38
|
private delayedEventsMap;
|
|
43
39
|
private observers;
|
|
44
40
|
private logger;
|
|
45
|
-
/**
|
|
46
|
-
* Whether the service is started.
|
|
47
|
-
*/
|
|
48
|
-
status: ActorStatus;
|
|
49
41
|
_parent?: ActorRef<any, any>;
|
|
50
42
|
ref: ActorRef<EventFromLogic<TLogic>, SnapshotFrom<TLogic>>;
|
|
51
43
|
private _actorScope;
|
|
@@ -59,7 +51,7 @@ export declare class Actor<TLogic extends AnyActorLogic> implements ActorRef<Eve
|
|
|
59
51
|
*/
|
|
60
52
|
system: ActorSystem<any>;
|
|
61
53
|
private _doneEvent?;
|
|
62
|
-
src
|
|
54
|
+
src: string | AnyActorLogic;
|
|
63
55
|
/**
|
|
64
56
|
* Creates a new actor instance for the given logic with the provided options, if any.
|
|
65
57
|
*
|
|
@@ -144,6 +136,18 @@ export declare class Actor<TLogic extends AnyActorLogic> implements ActorRef<Eve
|
|
|
144
136
|
xstate$$type: number;
|
|
145
137
|
id: string;
|
|
146
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
|
+
*/
|
|
147
151
|
getPersistedState(): Snapshot<unknown>;
|
|
148
152
|
[symbolObservable](): InteropSubscribable<SnapshotFrom<TLogic>>;
|
|
149
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 {
|
|
3
|
-
import type {
|
|
4
|
-
import type {
|
|
2
|
+
import type { MachineSnapshot } from "./State.js";
|
|
3
|
+
import type { Clock, Actor } from "./interpreter.js";
|
|
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>;
|
|
@@ -546,26 +542,37 @@ export interface StateLike<TContext extends MachineContext> {
|
|
|
546
542
|
event: EventObject;
|
|
547
543
|
}
|
|
548
544
|
export interface StateConfig<TContext extends MachineContext, TEvent extends EventObject> {
|
|
549
|
-
value: StateValue;
|
|
550
545
|
context: TContext;
|
|
551
546
|
historyValue?: HistoryValue<TContext, TEvent>;
|
|
552
|
-
|
|
553
|
-
configuration?: Array<StateNode<TContext, TEvent>>;
|
|
547
|
+
configuration: Array<StateNode<TContext, TEvent>>;
|
|
554
548
|
children: Record<string, ActorRef<any, any>>;
|
|
555
549
|
status: 'active' | 'done' | 'error' | 'stopped';
|
|
556
550
|
output?: any;
|
|
557
551
|
error?: unknown;
|
|
558
|
-
tags?: Set<string>;
|
|
559
552
|
machine?: StateMachine<TContext, TEvent, any, any, any, any, any, any, any>;
|
|
560
553
|
}
|
|
561
554
|
export interface ActorOptions<TLogic extends AnyActorLogic> {
|
|
562
555
|
/**
|
|
563
|
-
*
|
|
556
|
+
* The clock that is responsible for setting and clearing timeouts, such as delayed events and transitions.
|
|
557
|
+
*
|
|
558
|
+
* @remarks
|
|
559
|
+
* You can create your own “clock”. The clock interface is an object with two functions/methods:
|
|
560
|
+
*
|
|
561
|
+
* - `setTimeout` - same arguments as `window.setTimeout(fn, timeout)`
|
|
562
|
+
* - `clearTimeout` - same arguments as `window.clearTimeout(id)`
|
|
563
|
+
*
|
|
564
|
+
* By default, the native `setTimeout` and `clearTimeout` functions are used.
|
|
565
|
+
*
|
|
566
|
+
* For testing, XState provides `SimulatedClock`.
|
|
567
|
+
*
|
|
568
|
+
* @see {@link Clock}
|
|
569
|
+
* @see {@link SimulatedClock}
|
|
564
570
|
*/
|
|
565
|
-
execute?: boolean;
|
|
566
571
|
clock?: Clock;
|
|
572
|
+
/**
|
|
573
|
+
* Specifies the logger to be used for log(...) actions. Defaults to the native console.log method.
|
|
574
|
+
*/
|
|
567
575
|
logger?: (...args: any[]) => void;
|
|
568
|
-
parent?: ActorRef<any, any>;
|
|
569
576
|
/**
|
|
570
577
|
* The custom `id` for referencing this service.
|
|
571
578
|
*/
|
|
@@ -576,7 +583,6 @@ export interface ActorOptions<TLogic extends AnyActorLogic> {
|
|
|
576
583
|
* Default: `false`
|
|
577
584
|
*/
|
|
578
585
|
devTools?: boolean | DevToolsAdapter;
|
|
579
|
-
sync?: boolean;
|
|
580
586
|
/**
|
|
581
587
|
* The system ID to register this actor under
|
|
582
588
|
*/
|
|
@@ -585,11 +591,98 @@ export interface ActorOptions<TLogic extends AnyActorLogic> {
|
|
|
585
591
|
* The input data to pass to the actor.
|
|
586
592
|
*/
|
|
587
593
|
input?: InputFrom<TLogic>;
|
|
594
|
+
/**
|
|
595
|
+
* Initializes actor logic from a specific persisted internal state.
|
|
596
|
+
*
|
|
597
|
+
* @remarks
|
|
598
|
+
*
|
|
599
|
+
* If the state is compatible with the actor logic, when the actor is started it will be at that persisted state.
|
|
600
|
+
* Actions from machine actors will not be re-executed, because they are assumed to have been already executed.
|
|
601
|
+
* However, invocations will be restarted, and spawned actors will be restored recursively.
|
|
602
|
+
*
|
|
603
|
+
* Can be generated with {@link Actor.getPersistedState}.
|
|
604
|
+
*
|
|
605
|
+
* @see https://stately.ai/docs/persistence
|
|
606
|
+
*/
|
|
588
607
|
state?: any;
|
|
589
608
|
/**
|
|
590
609
|
* The source definition.
|
|
591
610
|
*/
|
|
592
|
-
src?: string;
|
|
611
|
+
src?: string | AnyActorLogic;
|
|
612
|
+
/**
|
|
613
|
+
* A callback function or observer object which can be used to inspect actor system updates.
|
|
614
|
+
*
|
|
615
|
+
* @remarks
|
|
616
|
+
* If a callback function is provided, it can accept an inspection event argument. The types of inspection events that can be observed include:
|
|
617
|
+
*
|
|
618
|
+
* - `@xstate.actor` - An actor ref has been created in the system
|
|
619
|
+
* - `@xstate.event` - An event was sent from a source actor ref to a target actor ref in the system
|
|
620
|
+
* - `@xstate.snapshot` - An actor ref emitted a snapshot due to a received event
|
|
621
|
+
*
|
|
622
|
+
* @example
|
|
623
|
+
* ```ts
|
|
624
|
+
* import { createMachine } from 'xstate';
|
|
625
|
+
*
|
|
626
|
+
* const machine = createMachine({
|
|
627
|
+
* // ...
|
|
628
|
+
* });
|
|
629
|
+
*
|
|
630
|
+
* const actor = createActor(machine, {
|
|
631
|
+
* inspect: (inspectionEvent) => {
|
|
632
|
+
* if (inspectionEvent.actorRef === actor) {
|
|
633
|
+
* // This event is for the root actor
|
|
634
|
+
* }
|
|
635
|
+
*
|
|
636
|
+
* if (inspectionEvent.type === '@xstate.actor') {
|
|
637
|
+
* console.log(inspectionEvent.actorRef);
|
|
638
|
+
* }
|
|
639
|
+
*
|
|
640
|
+
* if (inspectionEvent.type === '@xstate.event') {
|
|
641
|
+
* console.log(inspectionEvent.sourceRef);
|
|
642
|
+
* console.log(inspectionEvent.actorRef);
|
|
643
|
+
* console.log(inspectionEvent.event);
|
|
644
|
+
* }
|
|
645
|
+
*
|
|
646
|
+
* if (inspectionEvent.type === '@xstate.snapshot') {
|
|
647
|
+
* console.log(inspectionEvent.actorRef);
|
|
648
|
+
* console.log(inspectionEvent.event);
|
|
649
|
+
* console.log(inspectionEvent.snapshot);
|
|
650
|
+
* }
|
|
651
|
+
* }
|
|
652
|
+
* });
|
|
653
|
+
* ```
|
|
654
|
+
*
|
|
655
|
+
* Alternately, an observer object (`{ next?, error?, complete? }`) can be provided:
|
|
656
|
+
*
|
|
657
|
+
* @example
|
|
658
|
+
* ```ts
|
|
659
|
+
* const actor = createActor(machine, {
|
|
660
|
+
* inspect: {
|
|
661
|
+
* next: (inspectionEvent) => {
|
|
662
|
+
* if (inspectionEvent.actorRef === actor) {
|
|
663
|
+
* // This event is for the root actor
|
|
664
|
+
* }
|
|
665
|
+
*
|
|
666
|
+
* if (inspectionEvent.type === '@xstate.actor') {
|
|
667
|
+
* console.log(inspectionEvent.actorRef);
|
|
668
|
+
* }
|
|
669
|
+
*
|
|
670
|
+
* if (inspectionEvent.type === '@xstate.event') {
|
|
671
|
+
* console.log(inspectionEvent.sourceRef);
|
|
672
|
+
* console.log(inspectionEvent.actorRef);
|
|
673
|
+
* console.log(inspectionEvent.event);
|
|
674
|
+
* }
|
|
675
|
+
*
|
|
676
|
+
* if (inspectionEvent.type === '@xstate.snapshot') {
|
|
677
|
+
* console.log(inspectionEvent.actorRef);
|
|
678
|
+
* console.log(inspectionEvent.event);
|
|
679
|
+
* console.log(inspectionEvent.snapshot);
|
|
680
|
+
* }
|
|
681
|
+
* }
|
|
682
|
+
* }
|
|
683
|
+
* });
|
|
684
|
+
* ```
|
|
685
|
+
*/
|
|
593
686
|
inspect?: Observer<InspectionEvent> | ((inspectionEvent: InspectionEvent) => void);
|
|
594
687
|
}
|
|
595
688
|
export type AnyActor = Actor<any>;
|
|
@@ -636,8 +729,7 @@ export interface ActorRef<TEvent extends EventObject, TSnapshot extends Snapshot
|
|
|
636
729
|
toJSON?: () => any;
|
|
637
730
|
_parent?: ActorRef<any, any>;
|
|
638
731
|
system?: ActorSystem<any>;
|
|
639
|
-
|
|
640
|
-
src?: string;
|
|
732
|
+
src: string | AnyActorLogic;
|
|
641
733
|
}
|
|
642
734
|
export type AnyActorRef = ActorRef<any, any>;
|
|
643
735
|
export type ActorLogicFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<any, any, any, any, any, any, any, any, any> ? R : R extends Promise<infer U> ? PromiseActorLogic<U> : never : never;
|
|
@@ -694,7 +786,7 @@ export interface ActorLogic<TSnapshot extends Snapshot<unknown>, TEvent extends
|
|
|
694
786
|
/**
|
|
695
787
|
* @returns Persisted state
|
|
696
788
|
*/
|
|
697
|
-
getPersistedState: (state: TSnapshot) => Snapshot<unknown>;
|
|
789
|
+
getPersistedState: (state: TSnapshot, options?: unknown) => Snapshot<unknown>;
|
|
698
790
|
}
|
|
699
791
|
export type AnyActorLogic = ActorLogic<any, // snapshot
|
|
700
792
|
any, // event
|
|
@@ -702,9 +794,9 @@ any, // input
|
|
|
702
794
|
any>;
|
|
703
795
|
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;
|
|
704
796
|
export type EventFromLogic<TLogic extends ActorLogic<any, any, any, any>> = TLogic extends ActorLogic<infer _, infer TEvent, infer __, infer _____> ? TEvent : never;
|
|
705
|
-
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
|
|
797
|
+
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;
|
|
706
798
|
export type EventFrom<T, K extends Prop<TEvent, 'type'> = never, TEvent extends EventObject = ResolveEventType<T>> = IsNever<K> extends true ? TEvent : ExtractEvent<TEvent, K>;
|
|
707
|
-
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
|
|
799
|
+
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;
|
|
708
800
|
export type InferEvent<E extends EventObject> = {
|
|
709
801
|
[T in E['type']]: {
|
|
710
802
|
type: T;
|
package/dist/{interpreter-bae5c279.development.cjs.js → interpreter-23e4041c.development.cjs.js}
RENAMED
|
@@ -2,15 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
var dev_dist_xstateDev = require('../dev/dist/xstate-dev.development.cjs.js');
|
|
4
4
|
|
|
5
|
-
const STATE_DELIMITER = '.';
|
|
6
|
-
const TARGETLESS_KEY = '';
|
|
7
|
-
const NULL_EVENT = '';
|
|
8
|
-
const STATE_IDENTIFIER = '#';
|
|
9
|
-
const WILDCARD = '*';
|
|
10
|
-
const XSTATE_INIT = 'xstate.init';
|
|
11
|
-
const XSTATE_ERROR = 'xstate.error';
|
|
12
|
-
const XSTATE_STOP = 'xstate.stop';
|
|
13
|
-
|
|
14
5
|
class Mailbox {
|
|
15
6
|
constructor(_process) {
|
|
16
7
|
this._process = _process;
|
|
@@ -58,6 +49,15 @@ class Mailbox {
|
|
|
58
49
|
}
|
|
59
50
|
}
|
|
60
51
|
|
|
52
|
+
const STATE_DELIMITER = '.';
|
|
53
|
+
const TARGETLESS_KEY = '';
|
|
54
|
+
const NULL_EVENT = '';
|
|
55
|
+
const STATE_IDENTIFIER = '#';
|
|
56
|
+
const WILDCARD = '*';
|
|
57
|
+
const XSTATE_INIT = 'xstate.init';
|
|
58
|
+
const XSTATE_ERROR = 'xstate.error';
|
|
59
|
+
const XSTATE_STOP = 'xstate.stop';
|
|
60
|
+
|
|
61
61
|
/**
|
|
62
62
|
* Returns an event that represents an implicit event that
|
|
63
63
|
* is sent after the specified `delay`.
|
|
@@ -336,17 +336,13 @@ function resolveReferencedActor(machine, src) {
|
|
|
336
336
|
}
|
|
337
337
|
|
|
338
338
|
const $$ACTOR_TYPE = 1;
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
339
|
+
// those values are currently used by @xstate/react directly so it's important to keep the assigned values in sync
|
|
340
|
+
let ProcessingStatus = /*#__PURE__*/function (ProcessingStatus) {
|
|
341
|
+
ProcessingStatus[ProcessingStatus["NotStarted"] = 0] = "NotStarted";
|
|
342
|
+
ProcessingStatus[ProcessingStatus["Running"] = 1] = "Running";
|
|
343
|
+
ProcessingStatus[ProcessingStatus["Stopped"] = 2] = "Stopped";
|
|
344
|
+
return ProcessingStatus;
|
|
344
345
|
}({});
|
|
345
|
-
|
|
346
|
-
/**
|
|
347
|
-
* @deprecated Use `ActorStatus` instead.
|
|
348
|
-
*/
|
|
349
|
-
const InterpreterStatus = ActorStatus;
|
|
350
346
|
const defaultOptions = {
|
|
351
347
|
clock: {
|
|
352
348
|
setTimeout: (fn, ms) => {
|
|
@@ -376,9 +372,7 @@ class Actor {
|
|
|
376
372
|
* The unique identifier for this actor relative to its parent.
|
|
377
373
|
*/
|
|
378
374
|
|
|
379
|
-
/**
|
|
380
|
-
* Whether the service is started.
|
|
381
|
-
*/
|
|
375
|
+
/** @internal */
|
|
382
376
|
|
|
383
377
|
// Actor Ref
|
|
384
378
|
|
|
@@ -408,7 +402,7 @@ class Actor {
|
|
|
408
402
|
this.delayedEventsMap = {};
|
|
409
403
|
this.observers = new Set();
|
|
410
404
|
this.logger = void 0;
|
|
411
|
-
this.
|
|
405
|
+
this._processingStatus = ProcessingStatus.NotStarted;
|
|
412
406
|
this._parent = void 0;
|
|
413
407
|
this.ref = void 0;
|
|
414
408
|
this._actorScope = void 0;
|
|
@@ -441,7 +435,7 @@ class Actor {
|
|
|
441
435
|
this.clock = clock;
|
|
442
436
|
this._parent = parent;
|
|
443
437
|
this.options = resolvedOptions;
|
|
444
|
-
this.src = resolvedOptions.src;
|
|
438
|
+
this.src = resolvedOptions.src ?? logic;
|
|
445
439
|
this.ref = this;
|
|
446
440
|
this._actorScope = {
|
|
447
441
|
self: this,
|
|
@@ -467,14 +461,14 @@ class Actor {
|
|
|
467
461
|
type: '@xstate.actor',
|
|
468
462
|
actorRef: this
|
|
469
463
|
});
|
|
470
|
-
this._initState();
|
|
464
|
+
this._initState(options?.state);
|
|
471
465
|
if (systemId && this._state.status === 'active') {
|
|
472
466
|
this._systemId = systemId;
|
|
473
467
|
this.system._set(systemId, this);
|
|
474
468
|
}
|
|
475
469
|
}
|
|
476
|
-
_initState() {
|
|
477
|
-
this._state =
|
|
470
|
+
_initState(persistedState) {
|
|
471
|
+
this._state = persistedState ? this.logic.restoreState ? this.logic.restoreState(persistedState, this._actorScope) : persistedState : this.logic.getInitialState(this._actorScope, this.options?.input);
|
|
478
472
|
}
|
|
479
473
|
|
|
480
474
|
// array of functions to defer
|
|
@@ -489,7 +483,6 @@ class Actor {
|
|
|
489
483
|
deferredFn();
|
|
490
484
|
}
|
|
491
485
|
for (const observer of this.observers) {
|
|
492
|
-
// TODO: should observers be notified in case of the error?
|
|
493
486
|
try {
|
|
494
487
|
observer.next?.(snapshot);
|
|
495
488
|
} catch (err) {
|
|
@@ -572,7 +565,7 @@ class Actor {
|
|
|
572
565
|
|
|
573
566
|
subscribe(nextListenerOrObserver, errorListener, completeListener) {
|
|
574
567
|
const observer = toObserver(nextListenerOrObserver, errorListener, completeListener);
|
|
575
|
-
if (this.
|
|
568
|
+
if (this._processingStatus !== ProcessingStatus.Stopped) {
|
|
576
569
|
this.observers.add(observer);
|
|
577
570
|
} else {
|
|
578
571
|
try {
|
|
@@ -592,7 +585,7 @@ class Actor {
|
|
|
592
585
|
* Starts the Actor from the initial state
|
|
593
586
|
*/
|
|
594
587
|
start() {
|
|
595
|
-
if (this.
|
|
588
|
+
if (this._processingStatus === ProcessingStatus.Running) {
|
|
596
589
|
// Do not restart the service if it is already started
|
|
597
590
|
return this;
|
|
598
591
|
}
|
|
@@ -600,7 +593,9 @@ class Actor {
|
|
|
600
593
|
if (this._systemId) {
|
|
601
594
|
this.system._set(this._systemId, this);
|
|
602
595
|
}
|
|
603
|
-
this.
|
|
596
|
+
this._processingStatus = ProcessingStatus.Running;
|
|
597
|
+
|
|
598
|
+
// TODO: this isn't correct when rehydrating
|
|
604
599
|
const initEvent = createInitEvent(this.options.input);
|
|
605
600
|
this.system._sendInspectionEvent({
|
|
606
601
|
type: '@xstate.event',
|
|
@@ -668,12 +663,12 @@ class Actor {
|
|
|
668
663
|
}
|
|
669
664
|
}
|
|
670
665
|
_stop() {
|
|
671
|
-
if (this.
|
|
666
|
+
if (this._processingStatus === ProcessingStatus.Stopped) {
|
|
672
667
|
return this;
|
|
673
668
|
}
|
|
674
669
|
this.mailbox.clear();
|
|
675
|
-
if (this.
|
|
676
|
-
this.
|
|
670
|
+
if (this._processingStatus === ProcessingStatus.NotStarted) {
|
|
671
|
+
this._processingStatus = ProcessingStatus.Stopped;
|
|
677
672
|
return this;
|
|
678
673
|
}
|
|
679
674
|
this.mailbox.enqueue({
|
|
@@ -724,7 +719,7 @@ class Actor {
|
|
|
724
719
|
}
|
|
725
720
|
}
|
|
726
721
|
_stopProcedure() {
|
|
727
|
-
if (this.
|
|
722
|
+
if (this._processingStatus !== ProcessingStatus.Running) {
|
|
728
723
|
// Actor already stopped; do nothing
|
|
729
724
|
return this;
|
|
730
725
|
}
|
|
@@ -741,7 +736,7 @@ class Actor {
|
|
|
741
736
|
// it seems like this should be the common behavior for all of our consumers
|
|
742
737
|
// so perhaps this should be unified somehow for all of them
|
|
743
738
|
this.mailbox = new Mailbox(this._process.bind(this));
|
|
744
|
-
this.
|
|
739
|
+
this._processingStatus = ProcessingStatus.Stopped;
|
|
745
740
|
this.system._unregister(this);
|
|
746
741
|
return this;
|
|
747
742
|
}
|
|
@@ -750,7 +745,7 @@ class Actor {
|
|
|
750
745
|
* @internal
|
|
751
746
|
*/
|
|
752
747
|
_send(event) {
|
|
753
|
-
if (this.
|
|
748
|
+
if (this._processingStatus === ProcessingStatus.Stopped) {
|
|
754
749
|
// do nothing
|
|
755
750
|
{
|
|
756
751
|
const eventString = JSON.stringify(event);
|
|
@@ -816,8 +811,22 @@ class Actor {
|
|
|
816
811
|
id: this.id
|
|
817
812
|
};
|
|
818
813
|
}
|
|
819
|
-
|
|
820
|
-
|
|
814
|
+
|
|
815
|
+
/**
|
|
816
|
+
* Obtain the internal state of the actor, which can be persisted.
|
|
817
|
+
*
|
|
818
|
+
* @remarks
|
|
819
|
+
* The internal state can be persisted from any actor, not only machines.
|
|
820
|
+
*
|
|
821
|
+
* 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.
|
|
822
|
+
*
|
|
823
|
+
* Can be restored with {@link ActorOptions.state}
|
|
824
|
+
*
|
|
825
|
+
* @see https://stately.ai/docs/persistence
|
|
826
|
+
*/
|
|
827
|
+
|
|
828
|
+
getPersistedState(options) {
|
|
829
|
+
return this.logic.getPersistedState(this._state, options);
|
|
821
830
|
}
|
|
822
831
|
[symbolObservable]() {
|
|
823
832
|
return this;
|
|
@@ -867,9 +876,8 @@ const interpret = createActor;
|
|
|
867
876
|
|
|
868
877
|
exports.$$ACTOR_TYPE = $$ACTOR_TYPE;
|
|
869
878
|
exports.Actor = Actor;
|
|
870
|
-
exports.ActorStatus = ActorStatus;
|
|
871
|
-
exports.InterpreterStatus = InterpreterStatus;
|
|
872
879
|
exports.NULL_EVENT = NULL_EVENT;
|
|
880
|
+
exports.ProcessingStatus = ProcessingStatus;
|
|
873
881
|
exports.STATE_DELIMITER = STATE_DELIMITER;
|
|
874
882
|
exports.STATE_IDENTIFIER = STATE_IDENTIFIER;
|
|
875
883
|
exports.WILDCARD = WILDCARD;
|
|
@@ -894,5 +902,4 @@ exports.resolveReferencedActor = resolveReferencedActor;
|
|
|
894
902
|
exports.toArray = toArray;
|
|
895
903
|
exports.toObserver = toObserver;
|
|
896
904
|
exports.toStatePath = toStatePath;
|
|
897
|
-
exports.toStateValue = toStateValue;
|
|
898
905
|
exports.toTransitionConfigArray = toTransitionConfigArray;
|