xstate 5.0.0-beta.51 → 5.0.0-beta.53
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 +9 -11
- package/actions/dist/xstate-actions.cjs.mjs +0 -2
- package/actions/dist/xstate-actions.development.cjs.js +9 -11
- package/actions/dist/xstate-actions.development.cjs.mjs +0 -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 +17 -17
- package/actors/dist/xstate-actors.development.cjs.js +17 -17
- package/actors/dist/xstate-actors.development.esm.js +17 -17
- package/actors/dist/xstate-actors.esm.js +17 -17
- 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 +2 -2
- package/dist/declarations/src/StateMachine.d.ts +6 -6
- package/dist/declarations/src/StateNode.d.ts +4 -4
- package/dist/declarations/src/actions.d.ts +0 -2
- package/dist/declarations/src/actors/index.d.ts +1 -1
- package/dist/declarations/src/actors/transition.d.ts +1 -1
- package/dist/declarations/src/guards.d.ts +1 -1
- package/dist/declarations/src/interpreter.d.ts +7 -7
- package/dist/declarations/src/stateUtils.d.ts +9 -9
- package/dist/declarations/src/types.d.ts +23 -19
- package/dist/{pure-296f8ebd.development.esm.js → log-1fd7d00a.development.esm.js} +24 -61
- package/dist/{pure-aefddc19.esm.js → log-60ab9eaf.esm.js} +24 -58
- package/dist/{pure-c5f1b46c.cjs.js → log-717bb5a1.cjs.js} +23 -59
- package/dist/{pure-a0f16134.development.cjs.js → log-c8797128.development.cjs.js} +23 -62
- package/dist/{raise-acaa3884.development.esm.js → raise-953b1eb5.development.esm.js} +136 -136
- package/dist/{raise-d5633a02.cjs.js → raise-a8367773.cjs.js} +136 -136
- package/dist/{raise-4742bf04.esm.js → raise-be2f20bc.esm.js} +136 -136
- package/dist/{raise-528386de.development.cjs.js → raise-d9fd8932.development.cjs.js} +136 -136
- package/dist/xstate.cjs.js +28 -30
- package/dist/xstate.cjs.mjs +0 -2
- package/dist/xstate.development.cjs.js +28 -30
- package/dist/xstate.development.cjs.mjs +0 -2
- package/dist/xstate.development.esm.js +21 -21
- package/dist/xstate.esm.js +21 -21
- 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/actions/choose.d.ts +0 -9
- package/dist/declarations/src/actions/pure.d.ts +0 -10
|
@@ -37,19 +37,19 @@ export declare function getStateNodeByPath(stateNode: AnyStateNode, statePath: s
|
|
|
37
37
|
* @param stateValue The state value or State instance
|
|
38
38
|
*/
|
|
39
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,
|
|
41
|
-
export declare function transitionCompoundNode<TContext extends MachineContext, TEvent extends EventObject>(stateNode: AnyStateNode, stateValue: StateValueMap,
|
|
42
|
-
export declare function transitionParallelNode<TContext extends MachineContext, TEvent extends EventObject>(stateNode: AnyStateNode, stateValue: StateValueMap,
|
|
43
|
-
export declare function transitionNode<TContext extends MachineContext, TEvent extends EventObject>(stateNode: AnyStateNode, stateValue: StateValue,
|
|
40
|
+
export declare function transitionAtomicNode<TContext extends MachineContext, TEvent extends EventObject>(stateNode: AnyStateNode, stateValue: string, snapshot: 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, snapshot: 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, snapshot: 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, snapshot: MachineSnapshot<TContext, TEvent, any, any, any, any, any>, event: TEvent): Array<TransitionDefinition<TContext, TEvent>> | undefined;
|
|
44
44
|
export declare function removeConflictingTransitions(enabledTransitions: Array<AnyTransitionDefinition>, stateNodeSet: Set<AnyStateNode>, historyValue: AnyHistoryValue): Array<AnyTransitionDefinition>;
|
|
45
45
|
/**
|
|
46
46
|
* https://www.w3.org/TR/scxml/#microstepProcedure
|
|
47
47
|
*/
|
|
48
|
-
export declare function microstep<TContext extends MachineContext, TEvent extends EventObject>(transitions: Array<AnyTransitionDefinition>,
|
|
49
|
-
export declare function resolveActionsAndContext(
|
|
50
|
-
export declare function macrostep(
|
|
51
|
-
|
|
52
|
-
microstates: Array<typeof
|
|
48
|
+
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
|
+
export declare function resolveActionsAndContext(currentSnapshot: AnyMachineSnapshot, event: AnyEventObject, actorScope: AnyActorScope, actions: UnknownAction[], internalQueue: AnyEventObject[], deferredActorIds?: string[]): AnyMachineSnapshot;
|
|
50
|
+
export declare function macrostep(snapshot: AnyMachineSnapshot, event: EventObject, actorScope: AnyActorScope, internalQueue?: AnyEventObject[]): {
|
|
51
|
+
snapshot: typeof snapshot;
|
|
52
|
+
microstates: Array<typeof snapshot>;
|
|
53
53
|
};
|
|
54
54
|
/**
|
|
55
55
|
* Resolves a partial state value with its full representation in the state node's machine.
|
|
@@ -80,8 +80,8 @@ export interface ParameterizedObject {
|
|
|
80
80
|
export interface UnifiedArg<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject> {
|
|
81
81
|
context: TContext;
|
|
82
82
|
event: TExpressionEvent;
|
|
83
|
-
self: ActorRef<
|
|
84
|
-
StateValue, string, unknown
|
|
83
|
+
self: ActorRef<MachineSnapshot<TContext, TEvent, Record<string, AnyActorRef | undefined>, // TODO: this should be replaced with `TChildren`
|
|
84
|
+
StateValue, string, unknown>, TEvent>;
|
|
85
85
|
system: ActorSystem<any>;
|
|
86
86
|
}
|
|
87
87
|
export type MachineContext = Record<string, any>;
|
|
@@ -521,8 +521,8 @@ export type PropertyAssigner<TContext extends MachineContext, TExpressionEvent e
|
|
|
521
521
|
export type Mapper<TContext extends MachineContext, TExpressionEvent extends EventObject, TResult, TEvent extends EventObject> = (args: {
|
|
522
522
|
context: TContext;
|
|
523
523
|
event: TExpressionEvent;
|
|
524
|
-
self: ActorRef<
|
|
525
|
-
StateValue, string, unknown
|
|
524
|
+
self: ActorRef<MachineSnapshot<TContext, TEvent, Record<string, AnyActorRef>, // TODO: this should be replaced with `TChildren`
|
|
525
|
+
StateValue, string, unknown>, TEvent>;
|
|
526
526
|
}) => TResult;
|
|
527
527
|
export interface TransitionDefinition<TContext extends MachineContext, TEvent extends EventObject> extends Omit<TransitionConfig<TContext, TEvent, TEvent, TODO, TODO, TODO, TODO>, 'target' | 'guard'> {
|
|
528
528
|
target: ReadonlyArray<StateNode<TContext, TEvent>> | undefined;
|
|
@@ -614,10 +614,14 @@ export interface ActorOptions<TLogic extends AnyActorLogic> {
|
|
|
614
614
|
* Actions from machine actors will not be re-executed, because they are assumed to have been already executed.
|
|
615
615
|
* However, invocations will be restarted, and spawned actors will be restored recursively.
|
|
616
616
|
*
|
|
617
|
-
* Can be generated with {@link Actor.
|
|
617
|
+
* Can be generated with {@link Actor.getPersistedSnapshot}.
|
|
618
618
|
*
|
|
619
619
|
* @see https://stately.ai/docs/persistence
|
|
620
620
|
*/
|
|
621
|
+
snapshot?: Snapshot<unknown>;
|
|
622
|
+
/**
|
|
623
|
+
* @deprecated Use `snapshot` instead.
|
|
624
|
+
*/
|
|
621
625
|
state?: Snapshot<unknown>;
|
|
622
626
|
/**
|
|
623
627
|
* The source definition.
|
|
@@ -729,7 +733,7 @@ export interface BaseActorRef<TEvent extends EventObject> {
|
|
|
729
733
|
export interface ActorLike<TCurrent, TEvent extends EventObject> extends Subscribable<TCurrent> {
|
|
730
734
|
send: (event: TEvent) => void;
|
|
731
735
|
}
|
|
732
|
-
export interface ActorRef<
|
|
736
|
+
export interface ActorRef<TSnapshot extends Snapshot<unknown>, TEvent extends EventObject> extends Subscribable<TSnapshot>, InteropObservable<TSnapshot> {
|
|
733
737
|
/**
|
|
734
738
|
* The unique identifier for this actor relative to its parent.
|
|
735
739
|
*/
|
|
@@ -738,7 +742,7 @@ export interface ActorRef<TEvent extends EventObject, TSnapshot extends Snapshot
|
|
|
738
742
|
send: (event: TEvent) => void;
|
|
739
743
|
start: () => void;
|
|
740
744
|
getSnapshot: () => TSnapshot;
|
|
741
|
-
|
|
745
|
+
getPersistedSnapshot: () => Snapshot<unknown>;
|
|
742
746
|
stop: () => void;
|
|
743
747
|
toJSON?: () => any;
|
|
744
748
|
_parent?: ActorRef<any, any>;
|
|
@@ -747,7 +751,7 @@ export interface ActorRef<TEvent extends EventObject, TSnapshot extends Snapshot
|
|
|
747
751
|
}
|
|
748
752
|
export type AnyActorRef = ActorRef<any, any>;
|
|
749
753
|
export type ActorLogicFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<any, any, any, any, any, any, any, any, any, any, any> ? R : R extends Promise<infer U> ? PromiseActorLogic<U> : never : never;
|
|
750
|
-
export type ActorRefFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<infer TContext, infer TEvent, infer TChildren, infer _TActor, infer _TAction, infer _TGuard, infer _TDelay, infer TStateValue, infer TTag, infer _TInput, infer TOutput, infer TResolvedTypesMeta> ? ActorRef<
|
|
754
|
+
export type ActorRefFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<infer TContext, infer TEvent, infer TChildren, infer _TActor, infer _TAction, infer _TGuard, infer _TDelay, infer TStateValue, infer TTag, infer _TInput, infer TOutput, infer TResolvedTypesMeta> ? ActorRef<MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, AreAllImplementationsAssumedToBeProvided<TResolvedTypesMeta> extends false ? MarkAllImplementationsAsProvided<TResolvedTypesMeta> : TResolvedTypesMeta>, TEvent> : R extends Promise<infer U> ? ActorRefFrom<PromiseActorLogic<U>> : R extends ActorLogic<infer TSnapshot, infer TEvent, infer _TInput, infer _TSystem> ? ActorRef<TSnapshot, TEvent> : never : never;
|
|
751
755
|
export type DevToolsAdapter = (service: AnyActor) => void;
|
|
752
756
|
/**
|
|
753
757
|
* @deprecated Use `Actor<T>` instead.
|
|
@@ -766,7 +770,7 @@ any, // input
|
|
|
766
770
|
any, // output
|
|
767
771
|
infer TResolvedTypesMeta> ? TResolvedTypesMeta : never;
|
|
768
772
|
export interface ActorScope<TSnapshot extends Snapshot<unknown>, TEvent extends EventObject, TSystem extends ActorSystem<any> = ActorSystem<any>> {
|
|
769
|
-
self: ActorRef<
|
|
773
|
+
self: ActorRef<TSnapshot, TEvent>;
|
|
770
774
|
id: string;
|
|
771
775
|
sessionId: string;
|
|
772
776
|
logger: (...args: any[]) => void;
|
|
@@ -806,7 +810,7 @@ export interface ActorLogic<TSnapshot extends Snapshot<unknown>, TEvent extends
|
|
|
806
810
|
/**
|
|
807
811
|
* Transition function that processes the current state and an incoming message
|
|
808
812
|
* to produce a new state.
|
|
809
|
-
* @param
|
|
813
|
+
* @param snapshot - The current state.
|
|
810
814
|
* @param message - The incoming message.
|
|
811
815
|
* @param ctx - The actor scope.
|
|
812
816
|
* @returns The new state.
|
|
@@ -821,25 +825,25 @@ export interface ActorLogic<TSnapshot extends Snapshot<unknown>, TEvent extends
|
|
|
821
825
|
getInitialState: (actorScope: ActorScope<TSnapshot, TEvent, TSystem>, input: TInput) => TSnapshot;
|
|
822
826
|
/**
|
|
823
827
|
* Called when Actor is created to restore the internal state of the actor given a persisted state.
|
|
824
|
-
* The persisted state can be created by `
|
|
828
|
+
* The persisted state can be created by `getPersistedSnapshot`.
|
|
825
829
|
* @param persistedState - The persisted state to restore from.
|
|
826
830
|
* @param actorScope - The actor scope.
|
|
827
831
|
* @returns The restored state.
|
|
828
832
|
*/
|
|
829
|
-
|
|
833
|
+
restoreSnapshot?: (persistedState: Snapshot<unknown>, actorScope: ActorScope<TSnapshot, TEvent>) => TSnapshot;
|
|
830
834
|
/**
|
|
831
835
|
* Called when the actor is started.
|
|
832
|
-
* @param
|
|
836
|
+
* @param snapshot - The starting state.
|
|
833
837
|
* @param actorScope - The actor scope.
|
|
834
838
|
*/
|
|
835
|
-
start?: (
|
|
839
|
+
start?: (snapshot: TSnapshot, actorScope: ActorScope<TSnapshot, TEvent>) => void;
|
|
836
840
|
/**
|
|
837
841
|
* Obtains the internal state of the actor in a representation which can be be persisted.
|
|
838
|
-
* The persisted state can be restored by `
|
|
839
|
-
* @param
|
|
842
|
+
* The persisted state can be restored by `restoreSnapshot`.
|
|
843
|
+
* @param snapshot - The current state.
|
|
840
844
|
* @returns The a representation of the internal state to be persisted.
|
|
841
845
|
*/
|
|
842
|
-
|
|
846
|
+
getPersistedSnapshot: (snapshot: TSnapshot, options?: unknown) => Snapshot<unknown>;
|
|
843
847
|
}
|
|
844
848
|
export type AnyActorLogic = ActorLogic<any, // snapshot
|
|
845
849
|
any, // event
|
|
@@ -847,9 +851,9 @@ any, // input
|
|
|
847
851
|
any>;
|
|
848
852
|
export type UnknownActorLogic = ActorLogic<any, // this is invariant and it's hard to figure out a better default than `any`
|
|
849
853
|
EventObject, NonReducibleUnknown, ActorSystem<any>>;
|
|
850
|
-
export type SnapshotFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends ActorRef<infer
|
|
854
|
+
export type SnapshotFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends ActorRef<infer TSnapshot, infer _> ? TSnapshot : R extends Actor<infer TLogic> ? SnapshotFrom<TLogic> : R extends ActorLogic<infer _, infer __, infer ___, infer ____> ? ReturnType<R['transition']> : R extends ActorScope<infer TSnapshot, infer _, infer __> ? TSnapshot : never : never;
|
|
851
855
|
export type EventFromLogic<TLogic extends ActorLogic<any, any, any, any>> = TLogic extends ActorLogic<infer _, infer TEvent, infer __, infer _____> ? TEvent : never;
|
|
852
|
-
type ResolveEventType<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<infer _TContext, infer TEvent, infer _TChildren, infer _TActor, infer _TAction, infer _TGuard, infer _TDelay, infer _TStateValue, infer _TTag, infer _TInput, infer _TOutput, infer _TResolvedTypesMeta> ? TEvent : R extends MachineSnapshot<infer _TContext, infer TEvent, infer _TChildren, infer _TTag, infer _TOutput, infer _TResolvedTypesMeta> ? TEvent : R extends ActorRef<infer
|
|
856
|
+
type ResolveEventType<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<infer _TContext, infer TEvent, infer _TChildren, infer _TActor, infer _TAction, infer _TGuard, infer _TDelay, infer _TStateValue, infer _TTag, infer _TInput, infer _TOutput, infer _TResolvedTypesMeta> ? TEvent : R extends MachineSnapshot<infer _TContext, infer TEvent, infer _TChildren, infer _TTag, infer _TOutput, infer _TResolvedTypesMeta> ? TEvent : R extends ActorRef<infer _, infer TEvent> ? TEvent : never : never;
|
|
853
857
|
export type EventFrom<T, K extends Prop<TEvent, 'type'> = never, TEvent extends EventObject = ResolveEventType<T>> = IsNever<K> extends true ? TEvent : ExtractEvent<TEvent, K>;
|
|
854
858
|
export type ContextFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<infer TContext, infer _TEvent, infer _TChildren, infer _TActor, infer _TAction, infer _TGuard, infer _TDelay, infer _TStateValue, infer _TTag, infer _TInput, infer _TOutput, infer _TTypesMeta> ? TContext : R extends MachineSnapshot<infer TContext, infer _TEvent, infer _TChildren, infer _TTag, infer _TOutput, infer _TResolvedTypesMeta> ? TContext : R extends Actor<infer TActorLogic> ? TActorLogic extends StateMachine<infer TContext, infer _TEvent, infer _TChildren, infer _TActor, infer _TAction, infer _TGuard, infer _TDelay, infer _TTag, infer _TInput, infer _TOutput, infer _TTypesMeta> ? TContext : never : never : never;
|
|
855
859
|
export type InferEvent<E extends EventObject> = {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { R as ProcessingStatus, y as resolveReferencedActor, z as createActor, T as cloneMachineSnapshot,
|
|
1
|
+
import { R as ProcessingStatus, y as resolveReferencedActor, z as createActor, T as cloneMachineSnapshot, U as XSTATE_ERROR, V as createErrorActorEvent, e as evaluateGuard, L as cancel, M as raise, O as spawnChild, Q as stopChild } from './raise-953b1eb5.development.esm.js';
|
|
2
2
|
|
|
3
3
|
function createSpawner(actorScope, {
|
|
4
4
|
machine,
|
|
@@ -53,17 +53,17 @@ function createSpawner(actorScope, {
|
|
|
53
53
|
};
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
function resolveAssign(actorScope,
|
|
56
|
+
function resolveAssign(actorScope, snapshot, actionArgs, actionParams, {
|
|
57
57
|
assignment
|
|
58
58
|
}) {
|
|
59
|
-
if (!
|
|
59
|
+
if (!snapshot.context) {
|
|
60
60
|
throw new Error('Cannot assign to undefined `context`. Ensure that `context` is defined in the machine config.');
|
|
61
61
|
}
|
|
62
62
|
const spawnedChildren = {};
|
|
63
63
|
const assignArgs = {
|
|
64
|
-
context:
|
|
64
|
+
context: snapshot.context,
|
|
65
65
|
event: actionArgs.event,
|
|
66
|
-
spawn: createSpawner(actorScope,
|
|
66
|
+
spawn: createSpawner(actorScope, snapshot, actionArgs.event, spawnedChildren),
|
|
67
67
|
self: actorScope?.self,
|
|
68
68
|
system: actorScope?.system
|
|
69
69
|
};
|
|
@@ -76,13 +76,13 @@ function resolveAssign(actorScope, state, actionArgs, actionParams, {
|
|
|
76
76
|
partialUpdate[key] = typeof propAssignment === 'function' ? propAssignment(assignArgs, actionParams) : propAssignment;
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
|
-
const updatedContext = Object.assign({},
|
|
80
|
-
return [cloneMachineSnapshot(
|
|
79
|
+
const updatedContext = Object.assign({}, snapshot.context, partialUpdate);
|
|
80
|
+
return [cloneMachineSnapshot(snapshot, {
|
|
81
81
|
context: updatedContext,
|
|
82
82
|
children: Object.keys(spawnedChildren).length ? {
|
|
83
|
-
...
|
|
83
|
+
...snapshot.children,
|
|
84
84
|
...spawnedChildren
|
|
85
|
-
} :
|
|
85
|
+
} : snapshot.children
|
|
86
86
|
})];
|
|
87
87
|
}
|
|
88
88
|
/**
|
|
@@ -102,26 +102,6 @@ function assign(assignment) {
|
|
|
102
102
|
return assign;
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
-
function resolveChoose(_, state, actionArgs, _actionParams, {
|
|
106
|
-
branches
|
|
107
|
-
}) {
|
|
108
|
-
const matchedActions = branches.find(condition => {
|
|
109
|
-
return !condition.guard || evaluateGuard(condition.guard, state.context, actionArgs.event, state);
|
|
110
|
-
})?.actions;
|
|
111
|
-
return [state, undefined, toArray(matchedActions)];
|
|
112
|
-
}
|
|
113
|
-
function choose(branches) {
|
|
114
|
-
function choose(args, params) {
|
|
115
|
-
{
|
|
116
|
-
throw new Error(`This isn't supposed to be called`);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
choose.type = 'xstate.choose';
|
|
120
|
-
choose.branches = branches;
|
|
121
|
-
choose.resolve = resolveChoose;
|
|
122
|
-
return choose;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
105
|
/**
|
|
126
106
|
*
|
|
127
107
|
* @remarks
|
|
@@ -186,13 +166,13 @@ let SpecialTargets = /*#__PURE__*/function (SpecialTargets) {
|
|
|
186
166
|
* @template TSystem - The type of the actor system.
|
|
187
167
|
*/
|
|
188
168
|
|
|
189
|
-
function resolveSendTo(actorScope,
|
|
169
|
+
function resolveSendTo(actorScope, snapshot, args, actionParams, {
|
|
190
170
|
to,
|
|
191
171
|
event: eventOrExpr,
|
|
192
172
|
id,
|
|
193
173
|
delay
|
|
194
174
|
}, extra) {
|
|
195
|
-
const delaysMap =
|
|
175
|
+
const delaysMap = snapshot.machine.implementations.delays;
|
|
196
176
|
if (typeof eventOrExpr === 'string') {
|
|
197
177
|
throw new Error(`Only event objects may be used with sendTo; use sendTo({ type: "${eventOrExpr}" }) instead`);
|
|
198
178
|
}
|
|
@@ -214,26 +194,26 @@ function resolveSendTo(actorScope, state, args, actionParams, {
|
|
|
214
194
|
} else if (resolvedTarget.startsWith('#_')) {
|
|
215
195
|
// SCXML compatibility: https://www.w3.org/TR/scxml/#SCXMLEventProcessor
|
|
216
196
|
// #_invokeid. If the target is the special term '#_invokeid', where invokeid is the invokeid of an SCXML session that the sending session has created by <invoke>, the Processor must add the event to the external queue of that session.
|
|
217
|
-
targetActorRef =
|
|
197
|
+
targetActorRef = snapshot.children[resolvedTarget.slice(2)];
|
|
218
198
|
} else {
|
|
219
|
-
targetActorRef = extra.deferredActorIds?.includes(resolvedTarget) ? resolvedTarget :
|
|
199
|
+
targetActorRef = extra.deferredActorIds?.includes(resolvedTarget) ? resolvedTarget : snapshot.children[resolvedTarget];
|
|
220
200
|
}
|
|
221
201
|
if (!targetActorRef) {
|
|
222
|
-
throw new Error(`Unable to send event to actor '${resolvedTarget}' from machine '${
|
|
202
|
+
throw new Error(`Unable to send event to actor '${resolvedTarget}' from machine '${snapshot.machine.id}'.`);
|
|
223
203
|
}
|
|
224
204
|
} else {
|
|
225
205
|
targetActorRef = resolvedTarget || actorScope?.self;
|
|
226
206
|
}
|
|
227
|
-
return [
|
|
207
|
+
return [snapshot, {
|
|
228
208
|
to: targetActorRef,
|
|
229
209
|
event: resolvedEvent,
|
|
230
210
|
id,
|
|
231
211
|
delay: resolvedDelay
|
|
232
212
|
}];
|
|
233
213
|
}
|
|
234
|
-
function retryResolveSendTo(_,
|
|
214
|
+
function retryResolveSendTo(_, snapshot, params) {
|
|
235
215
|
if (typeof params.to === 'string') {
|
|
236
|
-
params.to =
|
|
216
|
+
params.to = snapshot.children[params.to];
|
|
237
217
|
}
|
|
238
218
|
}
|
|
239
219
|
function executeSendTo(actorScope, params) {
|
|
@@ -267,7 +247,7 @@ function sendTo(to, eventOrExpr, options) {
|
|
|
267
247
|
throw new Error(`This isn't supposed to be called`);
|
|
268
248
|
}
|
|
269
249
|
}
|
|
270
|
-
sendTo.type = '
|
|
250
|
+
sendTo.type = 'xsnapshot.sendTo';
|
|
271
251
|
sendTo.to = to;
|
|
272
252
|
sendTo.event = eventOrExpr;
|
|
273
253
|
sendTo.id = options?.id;
|
|
@@ -325,7 +305,7 @@ function escalate(errorData, options) {
|
|
|
325
305
|
}, options);
|
|
326
306
|
}
|
|
327
307
|
|
|
328
|
-
function resolveEnqueueActions(_,
|
|
308
|
+
function resolveEnqueueActions(_, snapshot, args, _actionParams, {
|
|
329
309
|
collect
|
|
330
310
|
}) {
|
|
331
311
|
const actions = [];
|
|
@@ -354,9 +334,9 @@ function resolveEnqueueActions(_, state, args, _actionParams, {
|
|
|
354
334
|
context: args.context,
|
|
355
335
|
event: args.event,
|
|
356
336
|
enqueue,
|
|
357
|
-
check: guard => evaluateGuard(guard,
|
|
337
|
+
check: guard => evaluateGuard(guard, snapshot.context, args.event, snapshot)
|
|
358
338
|
});
|
|
359
|
-
return [
|
|
339
|
+
return [snapshot, undefined, actions];
|
|
360
340
|
}
|
|
361
341
|
function enqueueActions(collect) {
|
|
362
342
|
function enqueueActions(args, params) {
|
|
@@ -370,11 +350,11 @@ function enqueueActions(collect) {
|
|
|
370
350
|
return enqueueActions;
|
|
371
351
|
}
|
|
372
352
|
|
|
373
|
-
function resolveLog(_,
|
|
353
|
+
function resolveLog(_, snapshot, actionArgs, actionParams, {
|
|
374
354
|
value,
|
|
375
355
|
label
|
|
376
356
|
}) {
|
|
377
|
-
return [
|
|
357
|
+
return [snapshot, {
|
|
378
358
|
value: typeof value === 'function' ? value(actionArgs, actionParams) : value,
|
|
379
359
|
label
|
|
380
360
|
}];
|
|
@@ -419,21 +399,4 @@ function log(value = ({
|
|
|
419
399
|
return log;
|
|
420
400
|
}
|
|
421
401
|
|
|
422
|
-
|
|
423
|
-
*
|
|
424
|
-
* @deprecated Use `enqueueActions(...)` instead
|
|
425
|
-
*/
|
|
426
|
-
function pure(getActions) {
|
|
427
|
-
return enqueueActions(({
|
|
428
|
-
context,
|
|
429
|
-
event,
|
|
430
|
-
enqueue
|
|
431
|
-
}) => {
|
|
432
|
-
toArray(getActions({
|
|
433
|
-
context,
|
|
434
|
-
event
|
|
435
|
-
})).forEach(enqueue);
|
|
436
|
-
});
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
export { SpecialTargets as S, assign as a, escalate as b, choose as c, sendTo as d, enqueueActions as e, forwardTo as f, log as l, pure as p, sendParent as s };
|
|
402
|
+
export { SpecialTargets as S, assign as a, escalate as b, sendTo as c, enqueueActions as e, forwardTo as f, log as l, sendParent as s };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { R as ProcessingStatus, y as resolveReferencedActor, z as createActor, T as cloneMachineSnapshot,
|
|
1
|
+
import { R as ProcessingStatus, y as resolveReferencedActor, z as createActor, T as cloneMachineSnapshot, U as XSTATE_ERROR, V as createErrorActorEvent, e as evaluateGuard, L as cancel, M as raise, O as spawnChild, Q as stopChild } from './raise-be2f20bc.esm.js';
|
|
2
2
|
|
|
3
3
|
function createSpawner(actorScope, {
|
|
4
4
|
machine,
|
|
@@ -53,17 +53,17 @@ function createSpawner(actorScope, {
|
|
|
53
53
|
};
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
function resolveAssign(actorScope,
|
|
56
|
+
function resolveAssign(actorScope, snapshot, actionArgs, actionParams, {
|
|
57
57
|
assignment
|
|
58
58
|
}) {
|
|
59
|
-
if (!
|
|
59
|
+
if (!snapshot.context) {
|
|
60
60
|
throw new Error('Cannot assign to undefined `context`. Ensure that `context` is defined in the machine config.');
|
|
61
61
|
}
|
|
62
62
|
const spawnedChildren = {};
|
|
63
63
|
const assignArgs = {
|
|
64
|
-
context:
|
|
64
|
+
context: snapshot.context,
|
|
65
65
|
event: actionArgs.event,
|
|
66
|
-
spawn: createSpawner(actorScope,
|
|
66
|
+
spawn: createSpawner(actorScope, snapshot, actionArgs.event, spawnedChildren),
|
|
67
67
|
self: actorScope?.self,
|
|
68
68
|
system: actorScope?.system
|
|
69
69
|
};
|
|
@@ -76,13 +76,13 @@ function resolveAssign(actorScope, state, actionArgs, actionParams, {
|
|
|
76
76
|
partialUpdate[key] = typeof propAssignment === 'function' ? propAssignment(assignArgs, actionParams) : propAssignment;
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
|
-
const updatedContext = Object.assign({},
|
|
80
|
-
return [cloneMachineSnapshot(
|
|
79
|
+
const updatedContext = Object.assign({}, snapshot.context, partialUpdate);
|
|
80
|
+
return [cloneMachineSnapshot(snapshot, {
|
|
81
81
|
context: updatedContext,
|
|
82
82
|
children: Object.keys(spawnedChildren).length ? {
|
|
83
|
-
...
|
|
83
|
+
...snapshot.children,
|
|
84
84
|
...spawnedChildren
|
|
85
|
-
} :
|
|
85
|
+
} : snapshot.children
|
|
86
86
|
})];
|
|
87
87
|
}
|
|
88
88
|
/**
|
|
@@ -99,23 +99,6 @@ function assign(assignment) {
|
|
|
99
99
|
return assign;
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
-
function resolveChoose(_, state, actionArgs, _actionParams, {
|
|
103
|
-
branches
|
|
104
|
-
}) {
|
|
105
|
-
const matchedActions = branches.find(condition => {
|
|
106
|
-
return !condition.guard || evaluateGuard(condition.guard, state.context, actionArgs.event, state);
|
|
107
|
-
})?.actions;
|
|
108
|
-
return [state, undefined, toArray(matchedActions)];
|
|
109
|
-
}
|
|
110
|
-
function choose(branches) {
|
|
111
|
-
function choose(args, params) {
|
|
112
|
-
}
|
|
113
|
-
choose.type = 'xstate.choose';
|
|
114
|
-
choose.branches = branches;
|
|
115
|
-
choose.resolve = resolveChoose;
|
|
116
|
-
return choose;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
102
|
/**
|
|
120
103
|
*
|
|
121
104
|
* @remarks
|
|
@@ -180,13 +163,13 @@ let SpecialTargets = /*#__PURE__*/function (SpecialTargets) {
|
|
|
180
163
|
* @template TSystem - The type of the actor system.
|
|
181
164
|
*/
|
|
182
165
|
|
|
183
|
-
function resolveSendTo(actorScope,
|
|
166
|
+
function resolveSendTo(actorScope, snapshot, args, actionParams, {
|
|
184
167
|
to,
|
|
185
168
|
event: eventOrExpr,
|
|
186
169
|
id,
|
|
187
170
|
delay
|
|
188
171
|
}, extra) {
|
|
189
|
-
const delaysMap =
|
|
172
|
+
const delaysMap = snapshot.machine.implementations.delays;
|
|
190
173
|
if (typeof eventOrExpr === 'string') {
|
|
191
174
|
throw new Error(`Only event objects may be used with sendTo; use sendTo({ type: "${eventOrExpr}" }) instead`);
|
|
192
175
|
}
|
|
@@ -208,26 +191,26 @@ function resolveSendTo(actorScope, state, args, actionParams, {
|
|
|
208
191
|
} else if (resolvedTarget.startsWith('#_')) {
|
|
209
192
|
// SCXML compatibility: https://www.w3.org/TR/scxml/#SCXMLEventProcessor
|
|
210
193
|
// #_invokeid. If the target is the special term '#_invokeid', where invokeid is the invokeid of an SCXML session that the sending session has created by <invoke>, the Processor must add the event to the external queue of that session.
|
|
211
|
-
targetActorRef =
|
|
194
|
+
targetActorRef = snapshot.children[resolvedTarget.slice(2)];
|
|
212
195
|
} else {
|
|
213
|
-
targetActorRef = extra.deferredActorIds?.includes(resolvedTarget) ? resolvedTarget :
|
|
196
|
+
targetActorRef = extra.deferredActorIds?.includes(resolvedTarget) ? resolvedTarget : snapshot.children[resolvedTarget];
|
|
214
197
|
}
|
|
215
198
|
if (!targetActorRef) {
|
|
216
|
-
throw new Error(`Unable to send event to actor '${resolvedTarget}' from machine '${
|
|
199
|
+
throw new Error(`Unable to send event to actor '${resolvedTarget}' from machine '${snapshot.machine.id}'.`);
|
|
217
200
|
}
|
|
218
201
|
} else {
|
|
219
202
|
targetActorRef = resolvedTarget || actorScope?.self;
|
|
220
203
|
}
|
|
221
|
-
return [
|
|
204
|
+
return [snapshot, {
|
|
222
205
|
to: targetActorRef,
|
|
223
206
|
event: resolvedEvent,
|
|
224
207
|
id,
|
|
225
208
|
delay: resolvedDelay
|
|
226
209
|
}];
|
|
227
210
|
}
|
|
228
|
-
function retryResolveSendTo(_,
|
|
211
|
+
function retryResolveSendTo(_, snapshot, params) {
|
|
229
212
|
if (typeof params.to === 'string') {
|
|
230
|
-
params.to =
|
|
213
|
+
params.to = snapshot.children[params.to];
|
|
231
214
|
}
|
|
232
215
|
}
|
|
233
216
|
function executeSendTo(actorScope, params) {
|
|
@@ -258,7 +241,7 @@ function executeSendTo(actorScope, params) {
|
|
|
258
241
|
function sendTo(to, eventOrExpr, options) {
|
|
259
242
|
function sendTo(args, params) {
|
|
260
243
|
}
|
|
261
|
-
sendTo.type = '
|
|
244
|
+
sendTo.type = 'xsnapshot.sendTo';
|
|
262
245
|
sendTo.to = to;
|
|
263
246
|
sendTo.event = eventOrExpr;
|
|
264
247
|
sendTo.id = options?.id;
|
|
@@ -306,7 +289,7 @@ function escalate(errorData, options) {
|
|
|
306
289
|
}, options);
|
|
307
290
|
}
|
|
308
291
|
|
|
309
|
-
function resolveEnqueueActions(_,
|
|
292
|
+
function resolveEnqueueActions(_, snapshot, args, _actionParams, {
|
|
310
293
|
collect
|
|
311
294
|
}) {
|
|
312
295
|
const actions = [];
|
|
@@ -335,9 +318,9 @@ function resolveEnqueueActions(_, state, args, _actionParams, {
|
|
|
335
318
|
context: args.context,
|
|
336
319
|
event: args.event,
|
|
337
320
|
enqueue,
|
|
338
|
-
check: guard => evaluateGuard(guard,
|
|
321
|
+
check: guard => evaluateGuard(guard, snapshot.context, args.event, snapshot)
|
|
339
322
|
});
|
|
340
|
-
return [
|
|
323
|
+
return [snapshot, undefined, actions];
|
|
341
324
|
}
|
|
342
325
|
function enqueueActions(collect) {
|
|
343
326
|
function enqueueActions(args, params) {
|
|
@@ -348,11 +331,11 @@ function enqueueActions(collect) {
|
|
|
348
331
|
return enqueueActions;
|
|
349
332
|
}
|
|
350
333
|
|
|
351
|
-
function resolveLog(_,
|
|
334
|
+
function resolveLog(_, snapshot, actionArgs, actionParams, {
|
|
352
335
|
value,
|
|
353
336
|
label
|
|
354
337
|
}) {
|
|
355
|
-
return [
|
|
338
|
+
return [snapshot, {
|
|
356
339
|
value: typeof value === 'function' ? value(actionArgs, actionParams) : value,
|
|
357
340
|
label
|
|
358
341
|
}];
|
|
@@ -394,21 +377,4 @@ function log(value = ({
|
|
|
394
377
|
return log;
|
|
395
378
|
}
|
|
396
379
|
|
|
397
|
-
|
|
398
|
-
*
|
|
399
|
-
* @deprecated Use `enqueueActions(...)` instead
|
|
400
|
-
*/
|
|
401
|
-
function pure(getActions) {
|
|
402
|
-
return enqueueActions(({
|
|
403
|
-
context,
|
|
404
|
-
event,
|
|
405
|
-
enqueue
|
|
406
|
-
}) => {
|
|
407
|
-
toArray(getActions({
|
|
408
|
-
context,
|
|
409
|
-
event
|
|
410
|
-
})).forEach(enqueue);
|
|
411
|
-
});
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
export { SpecialTargets as S, assign as a, escalate as b, choose as c, sendTo as d, enqueueActions as e, forwardTo as f, log as l, pure as p, sendParent as s };
|
|
380
|
+
export { SpecialTargets as S, assign as a, escalate as b, sendTo as c, enqueueActions as e, forwardTo as f, log as l, sendParent as s };
|