xstate 5.0.0-beta.52 → 5.0.0-beta.54
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 -3
- package/actions/dist/xstate-actions.cjs.mjs +0 -1
- package/actions/dist/xstate-actions.development.cjs.js +2 -3
- package/actions/dist/xstate-actions.development.cjs.mjs +0 -1
- 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 +4 -4
- package/dist/declarations/src/StateNode.d.ts +1 -1
- package/dist/declarations/src/actions/send.d.ts +1 -9
- package/dist/declarations/src/actions.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 +5 -5
- package/dist/declarations/src/stateUtils.d.ts +9 -9
- package/dist/declarations/src/types.d.ts +15 -11
- package/dist/{log-d160285c.development.cjs.js → log-516ee274.development.cjs.js} +23 -40
- package/dist/{log-3d815f5e.cjs.js → log-5b24d580.cjs.js} +23 -40
- package/dist/{log-826c9895.development.esm.js → log-5ebdc815.development.esm.js} +24 -40
- package/dist/{log-6bc0e1e7.esm.js → log-ee8cb6d6.esm.js} +24 -40
- package/dist/{raise-9dd3e757.development.cjs.js → raise-57f3c654.development.cjs.js} +130 -130
- package/dist/{raise-367eeb6f.cjs.js → raise-5f22d333.cjs.js} +130 -130
- package/dist/{raise-f71460d6.esm.js → raise-6f820d79.esm.js} +130 -130
- package/dist/{raise-1caefe80.development.esm.js → raise-a6c478f8.development.esm.js} +130 -130
- package/dist/xstate.cjs.js +17 -18
- package/dist/xstate.cjs.mjs +0 -1
- package/dist/xstate.development.cjs.js +17 -18
- package/dist/xstate.development.cjs.mjs +0 -1
- package/dist/xstate.development.esm.js +19 -19
- package/dist/xstate.esm.js +19 -19
- 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
|
@@ -484,7 +484,7 @@ export interface DoneActorEvent<TOutput = unknown> {
|
|
|
484
484
|
}
|
|
485
485
|
export interface ErrorActorEvent<TErrorData = unknown> extends EventObject {
|
|
486
486
|
type: `xstate.error.actor.${string}`;
|
|
487
|
-
|
|
487
|
+
error: TErrorData;
|
|
488
488
|
}
|
|
489
489
|
export interface SnapshotEvent<TSnapshot extends Snapshot<unknown> = Snapshot<unknown>> extends EventObject {
|
|
490
490
|
type: `xstate.snapshot.${string}`;
|
|
@@ -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.
|
|
@@ -738,7 +742,7 @@ export interface ActorRef<TSnapshot extends Snapshot<unknown>, TEvent extends Ev
|
|
|
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>;
|
|
@@ -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
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var guards_dist_xstateGuards = require('./raise-
|
|
3
|
+
var guards_dist_xstateGuards = require('./raise-57f3c654.development.cjs.js');
|
|
4
4
|
|
|
5
5
|
function createSpawner(actorScope, {
|
|
6
6
|
machine,
|
|
@@ -55,17 +55,17 @@ function createSpawner(actorScope, {
|
|
|
55
55
|
};
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
function resolveAssign(actorScope,
|
|
58
|
+
function resolveAssign(actorScope, snapshot, actionArgs, actionParams, {
|
|
59
59
|
assignment
|
|
60
60
|
}) {
|
|
61
|
-
if (!
|
|
61
|
+
if (!snapshot.context) {
|
|
62
62
|
throw new Error('Cannot assign to undefined `context`. Ensure that `context` is defined in the machine config.');
|
|
63
63
|
}
|
|
64
64
|
const spawnedChildren = {};
|
|
65
65
|
const assignArgs = {
|
|
66
|
-
context:
|
|
66
|
+
context: snapshot.context,
|
|
67
67
|
event: actionArgs.event,
|
|
68
|
-
spawn: createSpawner(actorScope,
|
|
68
|
+
spawn: createSpawner(actorScope, snapshot, actionArgs.event, spawnedChildren),
|
|
69
69
|
self: actorScope?.self,
|
|
70
70
|
system: actorScope?.system
|
|
71
71
|
};
|
|
@@ -78,13 +78,13 @@ function resolveAssign(actorScope, state, actionArgs, actionParams, {
|
|
|
78
78
|
partialUpdate[key] = typeof propAssignment === 'function' ? propAssignment(assignArgs, actionParams) : propAssignment;
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
|
-
const updatedContext = Object.assign({},
|
|
82
|
-
return [guards_dist_xstateGuards.cloneMachineSnapshot(
|
|
81
|
+
const updatedContext = Object.assign({}, snapshot.context, partialUpdate);
|
|
82
|
+
return [guards_dist_xstateGuards.cloneMachineSnapshot(snapshot, {
|
|
83
83
|
context: updatedContext,
|
|
84
84
|
children: Object.keys(spawnedChildren).length ? {
|
|
85
|
-
...
|
|
85
|
+
...snapshot.children,
|
|
86
86
|
...spawnedChildren
|
|
87
|
-
} :
|
|
87
|
+
} : snapshot.children
|
|
88
88
|
})];
|
|
89
89
|
}
|
|
90
90
|
/**
|
|
@@ -168,13 +168,13 @@ let SpecialTargets = /*#__PURE__*/function (SpecialTargets) {
|
|
|
168
168
|
* @template TSystem - The type of the actor system.
|
|
169
169
|
*/
|
|
170
170
|
|
|
171
|
-
function resolveSendTo(actorScope,
|
|
171
|
+
function resolveSendTo(actorScope, snapshot, args, actionParams, {
|
|
172
172
|
to,
|
|
173
173
|
event: eventOrExpr,
|
|
174
174
|
id,
|
|
175
175
|
delay
|
|
176
176
|
}, extra) {
|
|
177
|
-
const delaysMap =
|
|
177
|
+
const delaysMap = snapshot.machine.implementations.delays;
|
|
178
178
|
if (typeof eventOrExpr === 'string') {
|
|
179
179
|
throw new Error(`Only event objects may be used with sendTo; use sendTo({ type: "${eventOrExpr}" }) instead`);
|
|
180
180
|
}
|
|
@@ -196,26 +196,26 @@ function resolveSendTo(actorScope, state, args, actionParams, {
|
|
|
196
196
|
} else if (resolvedTarget.startsWith('#_')) {
|
|
197
197
|
// SCXML compatibility: https://www.w3.org/TR/scxml/#SCXMLEventProcessor
|
|
198
198
|
// #_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.
|
|
199
|
-
targetActorRef =
|
|
199
|
+
targetActorRef = snapshot.children[resolvedTarget.slice(2)];
|
|
200
200
|
} else {
|
|
201
|
-
targetActorRef = extra.deferredActorIds?.includes(resolvedTarget) ? resolvedTarget :
|
|
201
|
+
targetActorRef = extra.deferredActorIds?.includes(resolvedTarget) ? resolvedTarget : snapshot.children[resolvedTarget];
|
|
202
202
|
}
|
|
203
203
|
if (!targetActorRef) {
|
|
204
|
-
throw new Error(`Unable to send event to actor '${resolvedTarget}' from machine '${
|
|
204
|
+
throw new Error(`Unable to send event to actor '${resolvedTarget}' from machine '${snapshot.machine.id}'.`);
|
|
205
205
|
}
|
|
206
206
|
} else {
|
|
207
207
|
targetActorRef = resolvedTarget || actorScope?.self;
|
|
208
208
|
}
|
|
209
|
-
return [
|
|
209
|
+
return [snapshot, {
|
|
210
210
|
to: targetActorRef,
|
|
211
211
|
event: resolvedEvent,
|
|
212
212
|
id,
|
|
213
213
|
delay: resolvedDelay
|
|
214
214
|
}];
|
|
215
215
|
}
|
|
216
|
-
function retryResolveSendTo(_,
|
|
216
|
+
function retryResolveSendTo(_, snapshot, params) {
|
|
217
217
|
if (typeof params.to === 'string') {
|
|
218
|
-
params.to =
|
|
218
|
+
params.to = snapshot.children[params.to];
|
|
219
219
|
}
|
|
220
220
|
}
|
|
221
221
|
function executeSendTo(actorScope, params) {
|
|
@@ -249,7 +249,7 @@ function sendTo(to, eventOrExpr, options) {
|
|
|
249
249
|
throw new Error(`This isn't supposed to be called`);
|
|
250
250
|
}
|
|
251
251
|
}
|
|
252
|
-
sendTo.type = '
|
|
252
|
+
sendTo.type = 'xsnapshot.sendTo';
|
|
253
253
|
sendTo.to = to;
|
|
254
254
|
sendTo.event = eventOrExpr;
|
|
255
255
|
sendTo.id = options?.id;
|
|
@@ -291,23 +291,7 @@ function forwardTo(target, options) {
|
|
|
291
291
|
}) => event, options);
|
|
292
292
|
}
|
|
293
293
|
|
|
294
|
-
|
|
295
|
-
* Escalates an error by sending it as an event to this machine's parent.
|
|
296
|
-
*
|
|
297
|
-
* @param errorData The error data to send, or the expression function that
|
|
298
|
-
* takes in the `context`, `event`, and `meta`, and returns the error data to send.
|
|
299
|
-
* @param options Options to pass into the send action creator.
|
|
300
|
-
*/
|
|
301
|
-
function escalate(errorData, options) {
|
|
302
|
-
return sendParent(arg => {
|
|
303
|
-
return {
|
|
304
|
-
type: guards_dist_xstateGuards.XSTATE_ERROR,
|
|
305
|
-
data: typeof errorData === 'function' ? errorData(arg) : errorData
|
|
306
|
-
};
|
|
307
|
-
}, options);
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
function resolveEnqueueActions(_, state, args, _actionParams, {
|
|
294
|
+
function resolveEnqueueActions(_, snapshot, args, _actionParams, {
|
|
311
295
|
collect
|
|
312
296
|
}) {
|
|
313
297
|
const actions = [];
|
|
@@ -336,9 +320,9 @@ function resolveEnqueueActions(_, state, args, _actionParams, {
|
|
|
336
320
|
context: args.context,
|
|
337
321
|
event: args.event,
|
|
338
322
|
enqueue,
|
|
339
|
-
check: guard => guards_dist_xstateGuards.evaluateGuard(guard,
|
|
323
|
+
check: guard => guards_dist_xstateGuards.evaluateGuard(guard, snapshot.context, args.event, snapshot)
|
|
340
324
|
});
|
|
341
|
-
return [
|
|
325
|
+
return [snapshot, undefined, actions];
|
|
342
326
|
}
|
|
343
327
|
function enqueueActions(collect) {
|
|
344
328
|
function enqueueActions(args, params) {
|
|
@@ -352,11 +336,11 @@ function enqueueActions(collect) {
|
|
|
352
336
|
return enqueueActions;
|
|
353
337
|
}
|
|
354
338
|
|
|
355
|
-
function resolveLog(_,
|
|
339
|
+
function resolveLog(_, snapshot, actionArgs, actionParams, {
|
|
356
340
|
value,
|
|
357
341
|
label
|
|
358
342
|
}) {
|
|
359
|
-
return [
|
|
343
|
+
return [snapshot, {
|
|
360
344
|
value: typeof value === 'function' ? value(actionArgs, actionParams) : value,
|
|
361
345
|
label
|
|
362
346
|
}];
|
|
@@ -404,7 +388,6 @@ function log(value = ({
|
|
|
404
388
|
exports.SpecialTargets = SpecialTargets;
|
|
405
389
|
exports.assign = assign;
|
|
406
390
|
exports.enqueueActions = enqueueActions;
|
|
407
|
-
exports.escalate = escalate;
|
|
408
391
|
exports.forwardTo = forwardTo;
|
|
409
392
|
exports.log = log;
|
|
410
393
|
exports.sendParent = sendParent;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var guards_dist_xstateGuards = require('./raise-
|
|
3
|
+
var guards_dist_xstateGuards = require('./raise-5f22d333.cjs.js');
|
|
4
4
|
|
|
5
5
|
function createSpawner(actorScope, {
|
|
6
6
|
machine,
|
|
@@ -55,17 +55,17 @@ function createSpawner(actorScope, {
|
|
|
55
55
|
};
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
function resolveAssign(actorScope,
|
|
58
|
+
function resolveAssign(actorScope, snapshot, actionArgs, actionParams, {
|
|
59
59
|
assignment
|
|
60
60
|
}) {
|
|
61
|
-
if (!
|
|
61
|
+
if (!snapshot.context) {
|
|
62
62
|
throw new Error('Cannot assign to undefined `context`. Ensure that `context` is defined in the machine config.');
|
|
63
63
|
}
|
|
64
64
|
const spawnedChildren = {};
|
|
65
65
|
const assignArgs = {
|
|
66
|
-
context:
|
|
66
|
+
context: snapshot.context,
|
|
67
67
|
event: actionArgs.event,
|
|
68
|
-
spawn: createSpawner(actorScope,
|
|
68
|
+
spawn: createSpawner(actorScope, snapshot, actionArgs.event, spawnedChildren),
|
|
69
69
|
self: actorScope?.self,
|
|
70
70
|
system: actorScope?.system
|
|
71
71
|
};
|
|
@@ -78,13 +78,13 @@ function resolveAssign(actorScope, state, actionArgs, actionParams, {
|
|
|
78
78
|
partialUpdate[key] = typeof propAssignment === 'function' ? propAssignment(assignArgs, actionParams) : propAssignment;
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
|
-
const updatedContext = Object.assign({},
|
|
82
|
-
return [guards_dist_xstateGuards.cloneMachineSnapshot(
|
|
81
|
+
const updatedContext = Object.assign({}, snapshot.context, partialUpdate);
|
|
82
|
+
return [guards_dist_xstateGuards.cloneMachineSnapshot(snapshot, {
|
|
83
83
|
context: updatedContext,
|
|
84
84
|
children: Object.keys(spawnedChildren).length ? {
|
|
85
|
-
...
|
|
85
|
+
...snapshot.children,
|
|
86
86
|
...spawnedChildren
|
|
87
|
-
} :
|
|
87
|
+
} : snapshot.children
|
|
88
88
|
})];
|
|
89
89
|
}
|
|
90
90
|
/**
|
|
@@ -165,13 +165,13 @@ let SpecialTargets = /*#__PURE__*/function (SpecialTargets) {
|
|
|
165
165
|
* @template TSystem - The type of the actor system.
|
|
166
166
|
*/
|
|
167
167
|
|
|
168
|
-
function resolveSendTo(actorScope,
|
|
168
|
+
function resolveSendTo(actorScope, snapshot, args, actionParams, {
|
|
169
169
|
to,
|
|
170
170
|
event: eventOrExpr,
|
|
171
171
|
id,
|
|
172
172
|
delay
|
|
173
173
|
}, extra) {
|
|
174
|
-
const delaysMap =
|
|
174
|
+
const delaysMap = snapshot.machine.implementations.delays;
|
|
175
175
|
if (typeof eventOrExpr === 'string') {
|
|
176
176
|
throw new Error(`Only event objects may be used with sendTo; use sendTo({ type: "${eventOrExpr}" }) instead`);
|
|
177
177
|
}
|
|
@@ -193,26 +193,26 @@ function resolveSendTo(actorScope, state, args, actionParams, {
|
|
|
193
193
|
} else if (resolvedTarget.startsWith('#_')) {
|
|
194
194
|
// SCXML compatibility: https://www.w3.org/TR/scxml/#SCXMLEventProcessor
|
|
195
195
|
// #_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.
|
|
196
|
-
targetActorRef =
|
|
196
|
+
targetActorRef = snapshot.children[resolvedTarget.slice(2)];
|
|
197
197
|
} else {
|
|
198
|
-
targetActorRef = extra.deferredActorIds?.includes(resolvedTarget) ? resolvedTarget :
|
|
198
|
+
targetActorRef = extra.deferredActorIds?.includes(resolvedTarget) ? resolvedTarget : snapshot.children[resolvedTarget];
|
|
199
199
|
}
|
|
200
200
|
if (!targetActorRef) {
|
|
201
|
-
throw new Error(`Unable to send event to actor '${resolvedTarget}' from machine '${
|
|
201
|
+
throw new Error(`Unable to send event to actor '${resolvedTarget}' from machine '${snapshot.machine.id}'.`);
|
|
202
202
|
}
|
|
203
203
|
} else {
|
|
204
204
|
targetActorRef = resolvedTarget || actorScope?.self;
|
|
205
205
|
}
|
|
206
|
-
return [
|
|
206
|
+
return [snapshot, {
|
|
207
207
|
to: targetActorRef,
|
|
208
208
|
event: resolvedEvent,
|
|
209
209
|
id,
|
|
210
210
|
delay: resolvedDelay
|
|
211
211
|
}];
|
|
212
212
|
}
|
|
213
|
-
function retryResolveSendTo(_,
|
|
213
|
+
function retryResolveSendTo(_, snapshot, params) {
|
|
214
214
|
if (typeof params.to === 'string') {
|
|
215
|
-
params.to =
|
|
215
|
+
params.to = snapshot.children[params.to];
|
|
216
216
|
}
|
|
217
217
|
}
|
|
218
218
|
function executeSendTo(actorScope, params) {
|
|
@@ -243,7 +243,7 @@ function executeSendTo(actorScope, params) {
|
|
|
243
243
|
function sendTo(to, eventOrExpr, options) {
|
|
244
244
|
function sendTo(args, params) {
|
|
245
245
|
}
|
|
246
|
-
sendTo.type = '
|
|
246
|
+
sendTo.type = 'xsnapshot.sendTo';
|
|
247
247
|
sendTo.to = to;
|
|
248
248
|
sendTo.event = eventOrExpr;
|
|
249
249
|
sendTo.id = options?.id;
|
|
@@ -275,23 +275,7 @@ function forwardTo(target, options) {
|
|
|
275
275
|
}) => event, options);
|
|
276
276
|
}
|
|
277
277
|
|
|
278
|
-
|
|
279
|
-
* Escalates an error by sending it as an event to this machine's parent.
|
|
280
|
-
*
|
|
281
|
-
* @param errorData The error data to send, or the expression function that
|
|
282
|
-
* takes in the `context`, `event`, and `meta`, and returns the error data to send.
|
|
283
|
-
* @param options Options to pass into the send action creator.
|
|
284
|
-
*/
|
|
285
|
-
function escalate(errorData, options) {
|
|
286
|
-
return sendParent(arg => {
|
|
287
|
-
return {
|
|
288
|
-
type: guards_dist_xstateGuards.XSTATE_ERROR,
|
|
289
|
-
data: typeof errorData === 'function' ? errorData(arg) : errorData
|
|
290
|
-
};
|
|
291
|
-
}, options);
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
function resolveEnqueueActions(_, state, args, _actionParams, {
|
|
278
|
+
function resolveEnqueueActions(_, snapshot, args, _actionParams, {
|
|
295
279
|
collect
|
|
296
280
|
}) {
|
|
297
281
|
const actions = [];
|
|
@@ -320,9 +304,9 @@ function resolveEnqueueActions(_, state, args, _actionParams, {
|
|
|
320
304
|
context: args.context,
|
|
321
305
|
event: args.event,
|
|
322
306
|
enqueue,
|
|
323
|
-
check: guard => guards_dist_xstateGuards.evaluateGuard(guard,
|
|
307
|
+
check: guard => guards_dist_xstateGuards.evaluateGuard(guard, snapshot.context, args.event, snapshot)
|
|
324
308
|
});
|
|
325
|
-
return [
|
|
309
|
+
return [snapshot, undefined, actions];
|
|
326
310
|
}
|
|
327
311
|
function enqueueActions(collect) {
|
|
328
312
|
function enqueueActions(args, params) {
|
|
@@ -333,11 +317,11 @@ function enqueueActions(collect) {
|
|
|
333
317
|
return enqueueActions;
|
|
334
318
|
}
|
|
335
319
|
|
|
336
|
-
function resolveLog(_,
|
|
320
|
+
function resolveLog(_, snapshot, actionArgs, actionParams, {
|
|
337
321
|
value,
|
|
338
322
|
label
|
|
339
323
|
}) {
|
|
340
|
-
return [
|
|
324
|
+
return [snapshot, {
|
|
341
325
|
value: typeof value === 'function' ? value(actionArgs, actionParams) : value,
|
|
342
326
|
label
|
|
343
327
|
}];
|
|
@@ -382,7 +366,6 @@ function log(value = ({
|
|
|
382
366
|
exports.SpecialTargets = SpecialTargets;
|
|
383
367
|
exports.assign = assign;
|
|
384
368
|
exports.enqueueActions = enqueueActions;
|
|
385
|
-
exports.escalate = escalate;
|
|
386
369
|
exports.forwardTo = forwardTo;
|
|
387
370
|
exports.log = log;
|
|
388
371
|
exports.sendParent = sendParent;
|
|
@@ -1,4 +1,4 @@
|
|
|
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-
|
|
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-a6c478f8.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
|
/**
|
|
@@ -166,13 +166,13 @@ let SpecialTargets = /*#__PURE__*/function (SpecialTargets) {
|
|
|
166
166
|
* @template TSystem - The type of the actor system.
|
|
167
167
|
*/
|
|
168
168
|
|
|
169
|
-
function resolveSendTo(actorScope,
|
|
169
|
+
function resolveSendTo(actorScope, snapshot, args, actionParams, {
|
|
170
170
|
to,
|
|
171
171
|
event: eventOrExpr,
|
|
172
172
|
id,
|
|
173
173
|
delay
|
|
174
174
|
}, extra) {
|
|
175
|
-
const delaysMap =
|
|
175
|
+
const delaysMap = snapshot.machine.implementations.delays;
|
|
176
176
|
if (typeof eventOrExpr === 'string') {
|
|
177
177
|
throw new Error(`Only event objects may be used with sendTo; use sendTo({ type: "${eventOrExpr}" }) instead`);
|
|
178
178
|
}
|
|
@@ -194,26 +194,26 @@ function resolveSendTo(actorScope, state, args, actionParams, {
|
|
|
194
194
|
} else if (resolvedTarget.startsWith('#_')) {
|
|
195
195
|
// SCXML compatibility: https://www.w3.org/TR/scxml/#SCXMLEventProcessor
|
|
196
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.
|
|
197
|
-
targetActorRef =
|
|
197
|
+
targetActorRef = snapshot.children[resolvedTarget.slice(2)];
|
|
198
198
|
} else {
|
|
199
|
-
targetActorRef = extra.deferredActorIds?.includes(resolvedTarget) ? resolvedTarget :
|
|
199
|
+
targetActorRef = extra.deferredActorIds?.includes(resolvedTarget) ? resolvedTarget : snapshot.children[resolvedTarget];
|
|
200
200
|
}
|
|
201
201
|
if (!targetActorRef) {
|
|
202
|
-
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}'.`);
|
|
203
203
|
}
|
|
204
204
|
} else {
|
|
205
205
|
targetActorRef = resolvedTarget || actorScope?.self;
|
|
206
206
|
}
|
|
207
|
-
return [
|
|
207
|
+
return [snapshot, {
|
|
208
208
|
to: targetActorRef,
|
|
209
209
|
event: resolvedEvent,
|
|
210
210
|
id,
|
|
211
211
|
delay: resolvedDelay
|
|
212
212
|
}];
|
|
213
213
|
}
|
|
214
|
-
function retryResolveSendTo(_,
|
|
214
|
+
function retryResolveSendTo(_, snapshot, params) {
|
|
215
215
|
if (typeof params.to === 'string') {
|
|
216
|
-
params.to =
|
|
216
|
+
params.to = snapshot.children[params.to];
|
|
217
217
|
}
|
|
218
218
|
}
|
|
219
219
|
function executeSendTo(actorScope, params) {
|
|
@@ -247,7 +247,7 @@ function sendTo(to, eventOrExpr, options) {
|
|
|
247
247
|
throw new Error(`This isn't supposed to be called`);
|
|
248
248
|
}
|
|
249
249
|
}
|
|
250
|
-
sendTo.type = '
|
|
250
|
+
sendTo.type = 'xsnapshot.sendTo';
|
|
251
251
|
sendTo.to = to;
|
|
252
252
|
sendTo.event = eventOrExpr;
|
|
253
253
|
sendTo.id = options?.id;
|
|
@@ -289,23 +289,7 @@ function forwardTo(target, options) {
|
|
|
289
289
|
}) => event, options);
|
|
290
290
|
}
|
|
291
291
|
|
|
292
|
-
|
|
293
|
-
* Escalates an error by sending it as an event to this machine's parent.
|
|
294
|
-
*
|
|
295
|
-
* @param errorData The error data to send, or the expression function that
|
|
296
|
-
* takes in the `context`, `event`, and `meta`, and returns the error data to send.
|
|
297
|
-
* @param options Options to pass into the send action creator.
|
|
298
|
-
*/
|
|
299
|
-
function escalate(errorData, options) {
|
|
300
|
-
return sendParent(arg => {
|
|
301
|
-
return {
|
|
302
|
-
type: XSTATE_ERROR,
|
|
303
|
-
data: typeof errorData === 'function' ? errorData(arg) : errorData
|
|
304
|
-
};
|
|
305
|
-
}, options);
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
function resolveEnqueueActions(_, state, args, _actionParams, {
|
|
292
|
+
function resolveEnqueueActions(_, snapshot, args, _actionParams, {
|
|
309
293
|
collect
|
|
310
294
|
}) {
|
|
311
295
|
const actions = [];
|
|
@@ -334,9 +318,9 @@ function resolveEnqueueActions(_, state, args, _actionParams, {
|
|
|
334
318
|
context: args.context,
|
|
335
319
|
event: args.event,
|
|
336
320
|
enqueue,
|
|
337
|
-
check: guard => evaluateGuard(guard,
|
|
321
|
+
check: guard => evaluateGuard(guard, snapshot.context, args.event, snapshot)
|
|
338
322
|
});
|
|
339
|
-
return [
|
|
323
|
+
return [snapshot, undefined, actions];
|
|
340
324
|
}
|
|
341
325
|
function enqueueActions(collect) {
|
|
342
326
|
function enqueueActions(args, params) {
|
|
@@ -350,11 +334,11 @@ function enqueueActions(collect) {
|
|
|
350
334
|
return enqueueActions;
|
|
351
335
|
}
|
|
352
336
|
|
|
353
|
-
function resolveLog(_,
|
|
337
|
+
function resolveLog(_, snapshot, actionArgs, actionParams, {
|
|
354
338
|
value,
|
|
355
339
|
label
|
|
356
340
|
}) {
|
|
357
|
-
return [
|
|
341
|
+
return [snapshot, {
|
|
358
342
|
value: typeof value === 'function' ? value(actionArgs, actionParams) : value,
|
|
359
343
|
label
|
|
360
344
|
}];
|
|
@@ -399,4 +383,4 @@ function log(value = ({
|
|
|
399
383
|
return log;
|
|
400
384
|
}
|
|
401
385
|
|
|
402
|
-
export { SpecialTargets as S, assign as a,
|
|
386
|
+
export { SpecialTargets as S, assign as a, sendTo as b, enqueueActions as e, forwardTo as f, log as l, sendParent as s };
|