xstate 5.0.0-beta.37 → 5.0.0-beta.39
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 +4 -3
- package/actions/dist/xstate-actions.cjs.mjs +1 -0
- package/actions/dist/xstate-actions.development.cjs.js +4 -3
- package/actions/dist/xstate-actions.development.cjs.mjs +1 -0
- 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 +60 -3
- package/actors/dist/xstate-actors.development.cjs.js +60 -3
- package/actors/dist/xstate-actors.development.esm.js +60 -3
- package/actors/dist/xstate-actors.esm.js +60 -3
- 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 +7 -7
- package/dist/declarations/src/actions/assign.d.ts +4 -4
- package/dist/declarations/src/actions/cancel.d.ts +4 -4
- package/dist/declarations/src/actions/choose.d.ts +3 -3
- package/dist/declarations/src/actions/log.d.ts +4 -4
- package/dist/declarations/src/actions/pure.d.ts +4 -4
- package/dist/declarations/src/actions/raise.d.ts +3 -3
- package/dist/declarations/src/actions/send.d.ts +7 -7
- package/dist/declarations/src/actions/spawn.d.ts +34 -0
- package/dist/declarations/src/actions/stop.d.ts +4 -4
- package/dist/declarations/src/actions.d.ts +1 -0
- package/dist/declarations/src/actors/callback.d.ts +76 -2
- package/dist/declarations/src/actors/observable.d.ts +2 -3
- package/dist/declarations/src/actors/promise.d.ts +0 -1
- package/dist/declarations/src/actors/transition.d.ts +3 -3
- package/dist/declarations/src/guards.d.ts +9 -10
- package/dist/declarations/src/interpreter.d.ts +71 -10
- package/dist/declarations/src/spawn.d.ts +3 -4
- package/dist/declarations/src/stateUtils.d.ts +4 -9
- package/dist/declarations/src/types.d.ts +51 -62
- package/dist/{interpreter-e58ca48d.development.cjs.js → interpreter-03a5c3f5.development.cjs.js} +91 -12
- package/dist/{interpreter-8def682e.esm.js → interpreter-1e8c1c0c.esm.js} +91 -12
- package/dist/{interpreter-97aff8d2.cjs.js → interpreter-5dfcd203.cjs.js} +91 -12
- package/dist/{interpreter-1c52b23c.development.esm.js → interpreter-70cd9217.development.esm.js} +91 -12
- package/dist/{raise-1fd59c65.development.cjs.js → raise-17cb3d9d.development.cjs.js} +145 -152
- package/dist/{raise-800296d7.cjs.js → raise-291d2181.cjs.js} +145 -152
- package/dist/{raise-21c417c1.esm.js → raise-62de3670.esm.js} +145 -153
- package/dist/{raise-e342a840.development.esm.js → raise-e044f460.development.esm.js} +145 -153
- package/dist/{send-92854675.esm.js → send-1249d4ac.esm.js} +45 -44
- package/dist/{send-b309ef4e.development.cjs.js → send-33433787.development.cjs.js} +45 -44
- package/dist/{send-4cc29786.cjs.js → send-af152aca.cjs.js} +45 -44
- package/dist/{send-83ccc98b.development.esm.js → send-f1a2a827.development.esm.js} +45 -44
- package/dist/xstate.cjs.js +23 -20
- package/dist/xstate.cjs.mjs +1 -0
- package/dist/xstate.development.cjs.js +23 -20
- package/dist/xstate.development.cjs.mjs +1 -0
- package/dist/xstate.development.esm.js +25 -23
- package/dist/xstate.esm.js +25 -23
- 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 +1 -1
- package/guards/dist/xstate-guards.umd.min.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var guards_dist_xstateGuards = require('./raise-
|
|
4
|
-
var interpreter = require('./interpreter-
|
|
3
|
+
var guards_dist_xstateGuards = require('./raise-291d2181.cjs.js');
|
|
4
|
+
var interpreter = require('./interpreter-5dfcd203.cjs.js');
|
|
5
5
|
|
|
6
|
-
function createSpawner(
|
|
6
|
+
function createSpawner(actorScope, {
|
|
7
7
|
machine,
|
|
8
8
|
context
|
|
9
9
|
}, event, spawnedChildren) {
|
|
@@ -21,11 +21,11 @@ function createSpawner(actorContext, {
|
|
|
21
21
|
// TODO: this should also receive `src`
|
|
22
22
|
const actorRef = interpreter.createActor(referenced.src, {
|
|
23
23
|
id: options.id,
|
|
24
|
-
parent:
|
|
24
|
+
parent: actorScope.self,
|
|
25
25
|
input: typeof input === 'function' ? input({
|
|
26
26
|
context,
|
|
27
27
|
event,
|
|
28
|
-
self:
|
|
28
|
+
self: actorScope.self
|
|
29
29
|
}) : input,
|
|
30
30
|
src,
|
|
31
31
|
systemId
|
|
@@ -35,15 +35,13 @@ function createSpawner(actorContext, {
|
|
|
35
35
|
actorRef.subscribe({
|
|
36
36
|
next: snapshot => {
|
|
37
37
|
if (snapshot.status === 'active') {
|
|
38
|
-
|
|
38
|
+
actorScope.self.send({
|
|
39
39
|
type: `xstate.snapshot.${actorRef.id}`,
|
|
40
40
|
snapshot
|
|
41
41
|
});
|
|
42
42
|
}
|
|
43
43
|
},
|
|
44
|
-
error: () => {
|
|
45
|
-
/* TODO */
|
|
46
|
-
}
|
|
44
|
+
error: () => {}
|
|
47
45
|
});
|
|
48
46
|
}
|
|
49
47
|
return actorRef;
|
|
@@ -51,7 +49,7 @@ function createSpawner(actorContext, {
|
|
|
51
49
|
// TODO: this should also receive `src`
|
|
52
50
|
const actorRef = interpreter.createActor(src, {
|
|
53
51
|
id: options.id,
|
|
54
|
-
parent:
|
|
52
|
+
parent: actorScope.self,
|
|
55
53
|
input: options.input,
|
|
56
54
|
src: undefined,
|
|
57
55
|
systemId
|
|
@@ -60,16 +58,14 @@ function createSpawner(actorContext, {
|
|
|
60
58
|
actorRef.subscribe({
|
|
61
59
|
next: snapshot => {
|
|
62
60
|
if (snapshot.status === 'active') {
|
|
63
|
-
|
|
61
|
+
actorScope.self.send({
|
|
64
62
|
type: `xstate.snapshot.${actorRef.id}`,
|
|
65
63
|
snapshot,
|
|
66
64
|
id: actorRef.id
|
|
67
65
|
});
|
|
68
66
|
}
|
|
69
67
|
},
|
|
70
|
-
error: () => {
|
|
71
|
-
/* TODO */
|
|
72
|
-
}
|
|
68
|
+
error: () => {}
|
|
73
69
|
});
|
|
74
70
|
}
|
|
75
71
|
return actorRef;
|
|
@@ -78,14 +74,14 @@ function createSpawner(actorContext, {
|
|
|
78
74
|
return (src, options) => {
|
|
79
75
|
const actorRef = spawn(src, options); // TODO: fix types
|
|
80
76
|
spawnedChildren[actorRef.id] = actorRef;
|
|
81
|
-
|
|
77
|
+
actorScope.defer(() => {
|
|
82
78
|
if (actorRef.status === interpreter.ActorStatus.Stopped) {
|
|
83
79
|
return;
|
|
84
80
|
}
|
|
85
81
|
try {
|
|
86
82
|
actorRef.start?.();
|
|
87
83
|
} catch (err) {
|
|
88
|
-
|
|
84
|
+
actorScope.self.send(interpreter.createErrorActorEvent(actorRef.id, err));
|
|
89
85
|
return;
|
|
90
86
|
}
|
|
91
87
|
});
|
|
@@ -93,7 +89,7 @@ function createSpawner(actorContext, {
|
|
|
93
89
|
};
|
|
94
90
|
}
|
|
95
91
|
|
|
96
|
-
function resolveAssign(
|
|
92
|
+
function resolveAssign(actorScope, state, actionArgs, actionParams, {
|
|
97
93
|
assignment
|
|
98
94
|
}) {
|
|
99
95
|
if (!state.context) {
|
|
@@ -103,18 +99,17 @@ function resolveAssign(actorContext, state, actionArgs, {
|
|
|
103
99
|
const assignArgs = {
|
|
104
100
|
context: state.context,
|
|
105
101
|
event: actionArgs.event,
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
system: actorContext?.system
|
|
102
|
+
spawn: createSpawner(actorScope, state, actionArgs.event, spawnedChildren),
|
|
103
|
+
self: actorScope?.self,
|
|
104
|
+
system: actorScope?.system
|
|
110
105
|
};
|
|
111
106
|
let partialUpdate = {};
|
|
112
107
|
if (typeof assignment === 'function') {
|
|
113
|
-
partialUpdate = assignment(assignArgs);
|
|
108
|
+
partialUpdate = assignment(assignArgs, actionParams);
|
|
114
109
|
} else {
|
|
115
110
|
for (const key of Object.keys(assignment)) {
|
|
116
111
|
const propAssignment = assignment[key];
|
|
117
|
-
partialUpdate[key] = typeof propAssignment === 'function' ? propAssignment(assignArgs) : propAssignment;
|
|
112
|
+
partialUpdate[key] = typeof propAssignment === 'function' ? propAssignment(assignArgs, actionParams) : propAssignment;
|
|
118
113
|
}
|
|
119
114
|
}
|
|
120
115
|
const updatedContext = Object.assign({}, state.context, partialUpdate);
|
|
@@ -132,7 +127,7 @@ function resolveAssign(actorContext, state, actionArgs, {
|
|
|
132
127
|
* @param assignment An object that represents the partial context to update.
|
|
133
128
|
*/
|
|
134
129
|
function assign(assignment) {
|
|
135
|
-
function assign(
|
|
130
|
+
function assign(args, params) {
|
|
136
131
|
}
|
|
137
132
|
assign.type = 'xstate.assign';
|
|
138
133
|
assign.assignment = assignment;
|
|
@@ -140,7 +135,7 @@ function assign(assignment) {
|
|
|
140
135
|
return assign;
|
|
141
136
|
}
|
|
142
137
|
|
|
143
|
-
function resolveChoose(_, state, actionArgs, {
|
|
138
|
+
function resolveChoose(_, state, actionArgs, _actionParams, {
|
|
144
139
|
branches
|
|
145
140
|
}) {
|
|
146
141
|
const matchedActions = branches.find(condition => {
|
|
@@ -149,7 +144,7 @@ function resolveChoose(_, state, actionArgs, {
|
|
|
149
144
|
return [state, undefined, interpreter.toArray(matchedActions)];
|
|
150
145
|
}
|
|
151
146
|
function choose(branches) {
|
|
152
|
-
function choose(
|
|
147
|
+
function choose(args, params) {
|
|
153
148
|
}
|
|
154
149
|
choose.type = 'xstate.choose';
|
|
155
150
|
choose.branches = branches;
|
|
@@ -157,12 +152,12 @@ function choose(branches) {
|
|
|
157
152
|
return choose;
|
|
158
153
|
}
|
|
159
154
|
|
|
160
|
-
function resolveLog(_, state, actionArgs, {
|
|
155
|
+
function resolveLog(_, state, actionArgs, actionParams, {
|
|
161
156
|
value,
|
|
162
157
|
label
|
|
163
158
|
}) {
|
|
164
159
|
return [state, {
|
|
165
|
-
value: typeof value === 'function' ? value(actionArgs) : value,
|
|
160
|
+
value: typeof value === 'function' ? value(actionArgs, actionParams) : value,
|
|
166
161
|
label
|
|
167
162
|
}];
|
|
168
163
|
}
|
|
@@ -193,7 +188,7 @@ function log(value = ({
|
|
|
193
188
|
context,
|
|
194
189
|
event
|
|
195
190
|
}), label) {
|
|
196
|
-
function log(
|
|
191
|
+
function log(args, params) {
|
|
197
192
|
}
|
|
198
193
|
log.type = 'xstate.log';
|
|
199
194
|
log.value = value;
|
|
@@ -203,7 +198,7 @@ function log(value = ({
|
|
|
203
198
|
return log;
|
|
204
199
|
}
|
|
205
200
|
|
|
206
|
-
function resolvePure(_, state, args, {
|
|
201
|
+
function resolvePure(_, state, args, _actionParams, {
|
|
207
202
|
get
|
|
208
203
|
}) {
|
|
209
204
|
return [state, undefined, interpreter.toArray(get({
|
|
@@ -212,7 +207,7 @@ function resolvePure(_, state, args, {
|
|
|
212
207
|
}))];
|
|
213
208
|
}
|
|
214
209
|
function pure(getActions) {
|
|
215
|
-
function pure(
|
|
210
|
+
function pure(args, params) {
|
|
216
211
|
}
|
|
217
212
|
pure.type = 'xstate.pure';
|
|
218
213
|
pure.get = getActions;
|
|
@@ -221,6 +216,9 @@ function pure(getActions) {
|
|
|
221
216
|
}
|
|
222
217
|
|
|
223
218
|
/**
|
|
219
|
+
*
|
|
220
|
+
* @remarks
|
|
221
|
+
*
|
|
224
222
|
* `T | unknown` reduces to `unknown` and that can be problematic when it comes to contextual typing.
|
|
225
223
|
* It especially is a problem when the union has a function member, like here:
|
|
226
224
|
*
|
|
@@ -241,7 +239,10 @@ function pure(getActions) {
|
|
|
241
239
|
/**
|
|
242
240
|
* The string or object representing the state value relative to the parent state node.
|
|
243
241
|
*
|
|
242
|
+
* @remarks
|
|
243
|
+
*
|
|
244
244
|
* - For a child atomic state node, this is a string, e.g., `"pending"`.
|
|
245
|
+
*
|
|
245
246
|
* - For complex state nodes, this is an object, e.g., `{ success: "someChildState" }`.
|
|
246
247
|
*/
|
|
247
248
|
|
|
@@ -255,7 +256,7 @@ let SpecialTargets = /*#__PURE__*/function (SpecialTargets) {
|
|
|
255
256
|
return SpecialTargets;
|
|
256
257
|
}({});
|
|
257
258
|
|
|
258
|
-
function resolveSendTo(
|
|
259
|
+
function resolveSendTo(actorScope, state, args, actionParams, {
|
|
259
260
|
to,
|
|
260
261
|
event: eventOrExpr,
|
|
261
262
|
id,
|
|
@@ -265,21 +266,21 @@ function resolveSendTo(actorContext, state, args, {
|
|
|
265
266
|
if (typeof eventOrExpr === 'string') {
|
|
266
267
|
throw new Error(`Only event objects may be used with sendTo; use sendTo({ type: "${eventOrExpr}" }) instead`);
|
|
267
268
|
}
|
|
268
|
-
const resolvedEvent = typeof eventOrExpr === 'function' ? eventOrExpr(args) : eventOrExpr;
|
|
269
|
+
const resolvedEvent = typeof eventOrExpr === 'function' ? eventOrExpr(args, actionParams) : eventOrExpr;
|
|
269
270
|
let resolvedDelay;
|
|
270
271
|
if (typeof delay === 'string') {
|
|
271
272
|
const configDelay = delaysMap && delaysMap[delay];
|
|
272
|
-
resolvedDelay = typeof configDelay === 'function' ? configDelay(args) : configDelay;
|
|
273
|
+
resolvedDelay = typeof configDelay === 'function' ? configDelay(args, actionParams) : configDelay;
|
|
273
274
|
} else {
|
|
274
|
-
resolvedDelay = typeof delay === 'function' ? delay(args) : delay;
|
|
275
|
+
resolvedDelay = typeof delay === 'function' ? delay(args, actionParams) : delay;
|
|
275
276
|
}
|
|
276
|
-
const resolvedTarget = typeof to === 'function' ? to(args) : to;
|
|
277
|
+
const resolvedTarget = typeof to === 'function' ? to(args, actionParams) : to;
|
|
277
278
|
let targetActorRef;
|
|
278
279
|
if (typeof resolvedTarget === 'string') {
|
|
279
280
|
if (resolvedTarget === SpecialTargets.Parent) {
|
|
280
|
-
targetActorRef =
|
|
281
|
+
targetActorRef = actorScope?.self._parent;
|
|
281
282
|
} else if (resolvedTarget === SpecialTargets.Internal) {
|
|
282
|
-
targetActorRef =
|
|
283
|
+
targetActorRef = actorScope?.self;
|
|
283
284
|
} else if (resolvedTarget.startsWith('#_')) {
|
|
284
285
|
// SCXML compatibility: https://www.w3.org/TR/scxml/#SCXMLEventProcessor
|
|
285
286
|
// #_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.
|
|
@@ -291,7 +292,7 @@ function resolveSendTo(actorContext, state, args, {
|
|
|
291
292
|
throw new Error(`Unable to send event to actor '${resolvedTarget}' from machine '${state.machine.id}'.`);
|
|
292
293
|
}
|
|
293
294
|
} else {
|
|
294
|
-
targetActorRef = resolvedTarget ||
|
|
295
|
+
targetActorRef = resolvedTarget || actorScope?.self;
|
|
295
296
|
}
|
|
296
297
|
return [state, {
|
|
297
298
|
to: targetActorRef,
|
|
@@ -305,20 +306,20 @@ function retryResolveSendTo(_, state, params) {
|
|
|
305
306
|
params.to = state.children[params.to];
|
|
306
307
|
}
|
|
307
308
|
}
|
|
308
|
-
function executeSendTo(
|
|
309
|
+
function executeSendTo(actorScope, params) {
|
|
309
310
|
if (typeof params.delay === 'number') {
|
|
310
|
-
|
|
311
|
+
actorScope.self.delaySend(params);
|
|
311
312
|
return;
|
|
312
313
|
}
|
|
313
314
|
|
|
314
315
|
// this forms an outgoing events queue
|
|
315
316
|
// thanks to that the recipient actors are able to read the *updated* snapshot value of the sender
|
|
316
|
-
|
|
317
|
+
actorScope.defer(() => {
|
|
317
318
|
const {
|
|
318
319
|
to,
|
|
319
320
|
event
|
|
320
321
|
} = params;
|
|
321
|
-
|
|
322
|
+
actorScope?.system._relay(actorScope.self, to, event.type === interpreter.XSTATE_ERROR ? interpreter.createErrorActorEvent(actorScope.self.id, event.data) : event);
|
|
322
323
|
});
|
|
323
324
|
}
|
|
324
325
|
/**
|
|
@@ -331,7 +332,7 @@ function executeSendTo(actorContext, params) {
|
|
|
331
332
|
* - `delay` - The number of milliseconds to delay the sending of the event.
|
|
332
333
|
*/
|
|
333
334
|
function sendTo(to, eventOrExpr, options) {
|
|
334
|
-
function sendTo(
|
|
335
|
+
function sendTo(args, params) {
|
|
335
336
|
}
|
|
336
337
|
sendTo.type = 'xstate.sendTo';
|
|
337
338
|
sendTo.to = to;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { j as cloneState, e as evaluateGuard } from './raise-
|
|
2
|
-
import { f as ActorStatus, j as createErrorActorEvent, r as resolveReferencedActor, d as createActor, t as toArray, x as XSTATE_ERROR } from './interpreter-
|
|
1
|
+
import { j as cloneState, e as evaluateGuard } from './raise-e044f460.development.esm.js';
|
|
2
|
+
import { f as ActorStatus, j as createErrorActorEvent, r as resolveReferencedActor, d as createActor, t as toArray, x as XSTATE_ERROR } from './interpreter-70cd9217.development.esm.js';
|
|
3
3
|
|
|
4
|
-
function createSpawner(
|
|
4
|
+
function createSpawner(actorScope, {
|
|
5
5
|
machine,
|
|
6
6
|
context
|
|
7
7
|
}, event, spawnedChildren) {
|
|
@@ -19,11 +19,11 @@ function createSpawner(actorContext, {
|
|
|
19
19
|
// TODO: this should also receive `src`
|
|
20
20
|
const actorRef = createActor(referenced.src, {
|
|
21
21
|
id: options.id,
|
|
22
|
-
parent:
|
|
22
|
+
parent: actorScope.self,
|
|
23
23
|
input: typeof input === 'function' ? input({
|
|
24
24
|
context,
|
|
25
25
|
event,
|
|
26
|
-
self:
|
|
26
|
+
self: actorScope.self
|
|
27
27
|
}) : input,
|
|
28
28
|
src,
|
|
29
29
|
systemId
|
|
@@ -33,15 +33,13 @@ function createSpawner(actorContext, {
|
|
|
33
33
|
actorRef.subscribe({
|
|
34
34
|
next: snapshot => {
|
|
35
35
|
if (snapshot.status === 'active') {
|
|
36
|
-
|
|
36
|
+
actorScope.self.send({
|
|
37
37
|
type: `xstate.snapshot.${actorRef.id}`,
|
|
38
38
|
snapshot
|
|
39
39
|
});
|
|
40
40
|
}
|
|
41
41
|
},
|
|
42
|
-
error: () => {
|
|
43
|
-
/* TODO */
|
|
44
|
-
}
|
|
42
|
+
error: () => {}
|
|
45
43
|
});
|
|
46
44
|
}
|
|
47
45
|
return actorRef;
|
|
@@ -49,7 +47,7 @@ function createSpawner(actorContext, {
|
|
|
49
47
|
// TODO: this should also receive `src`
|
|
50
48
|
const actorRef = createActor(src, {
|
|
51
49
|
id: options.id,
|
|
52
|
-
parent:
|
|
50
|
+
parent: actorScope.self,
|
|
53
51
|
input: options.input,
|
|
54
52
|
src: undefined,
|
|
55
53
|
systemId
|
|
@@ -58,16 +56,14 @@ function createSpawner(actorContext, {
|
|
|
58
56
|
actorRef.subscribe({
|
|
59
57
|
next: snapshot => {
|
|
60
58
|
if (snapshot.status === 'active') {
|
|
61
|
-
|
|
59
|
+
actorScope.self.send({
|
|
62
60
|
type: `xstate.snapshot.${actorRef.id}`,
|
|
63
61
|
snapshot,
|
|
64
62
|
id: actorRef.id
|
|
65
63
|
});
|
|
66
64
|
}
|
|
67
65
|
},
|
|
68
|
-
error: () => {
|
|
69
|
-
/* TODO */
|
|
70
|
-
}
|
|
66
|
+
error: () => {}
|
|
71
67
|
});
|
|
72
68
|
}
|
|
73
69
|
return actorRef;
|
|
@@ -76,14 +72,14 @@ function createSpawner(actorContext, {
|
|
|
76
72
|
return (src, options) => {
|
|
77
73
|
const actorRef = spawn(src, options); // TODO: fix types
|
|
78
74
|
spawnedChildren[actorRef.id] = actorRef;
|
|
79
|
-
|
|
75
|
+
actorScope.defer(() => {
|
|
80
76
|
if (actorRef.status === ActorStatus.Stopped) {
|
|
81
77
|
return;
|
|
82
78
|
}
|
|
83
79
|
try {
|
|
84
80
|
actorRef.start?.();
|
|
85
81
|
} catch (err) {
|
|
86
|
-
|
|
82
|
+
actorScope.self.send(createErrorActorEvent(actorRef.id, err));
|
|
87
83
|
return;
|
|
88
84
|
}
|
|
89
85
|
});
|
|
@@ -91,7 +87,7 @@ function createSpawner(actorContext, {
|
|
|
91
87
|
};
|
|
92
88
|
}
|
|
93
89
|
|
|
94
|
-
function resolveAssign(
|
|
90
|
+
function resolveAssign(actorScope, state, actionArgs, actionParams, {
|
|
95
91
|
assignment
|
|
96
92
|
}) {
|
|
97
93
|
if (!state.context) {
|
|
@@ -101,18 +97,17 @@ function resolveAssign(actorContext, state, actionArgs, {
|
|
|
101
97
|
const assignArgs = {
|
|
102
98
|
context: state.context,
|
|
103
99
|
event: actionArgs.event,
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
system: actorContext?.system
|
|
100
|
+
spawn: createSpawner(actorScope, state, actionArgs.event, spawnedChildren),
|
|
101
|
+
self: actorScope?.self,
|
|
102
|
+
system: actorScope?.system
|
|
108
103
|
};
|
|
109
104
|
let partialUpdate = {};
|
|
110
105
|
if (typeof assignment === 'function') {
|
|
111
|
-
partialUpdate = assignment(assignArgs);
|
|
106
|
+
partialUpdate = assignment(assignArgs, actionParams);
|
|
112
107
|
} else {
|
|
113
108
|
for (const key of Object.keys(assignment)) {
|
|
114
109
|
const propAssignment = assignment[key];
|
|
115
|
-
partialUpdate[key] = typeof propAssignment === 'function' ? propAssignment(assignArgs) : propAssignment;
|
|
110
|
+
partialUpdate[key] = typeof propAssignment === 'function' ? propAssignment(assignArgs, actionParams) : propAssignment;
|
|
116
111
|
}
|
|
117
112
|
}
|
|
118
113
|
const updatedContext = Object.assign({}, state.context, partialUpdate);
|
|
@@ -130,7 +125,7 @@ function resolveAssign(actorContext, state, actionArgs, {
|
|
|
130
125
|
* @param assignment An object that represents the partial context to update.
|
|
131
126
|
*/
|
|
132
127
|
function assign(assignment) {
|
|
133
|
-
function assign(
|
|
128
|
+
function assign(args, params) {
|
|
134
129
|
{
|
|
135
130
|
throw new Error(`This isn't supposed to be called`);
|
|
136
131
|
}
|
|
@@ -141,7 +136,7 @@ function assign(assignment) {
|
|
|
141
136
|
return assign;
|
|
142
137
|
}
|
|
143
138
|
|
|
144
|
-
function resolveChoose(_, state, actionArgs, {
|
|
139
|
+
function resolveChoose(_, state, actionArgs, _actionParams, {
|
|
145
140
|
branches
|
|
146
141
|
}) {
|
|
147
142
|
const matchedActions = branches.find(condition => {
|
|
@@ -150,7 +145,7 @@ function resolveChoose(_, state, actionArgs, {
|
|
|
150
145
|
return [state, undefined, toArray(matchedActions)];
|
|
151
146
|
}
|
|
152
147
|
function choose(branches) {
|
|
153
|
-
function choose(
|
|
148
|
+
function choose(args, params) {
|
|
154
149
|
{
|
|
155
150
|
throw new Error(`This isn't supposed to be called`);
|
|
156
151
|
}
|
|
@@ -161,12 +156,12 @@ function choose(branches) {
|
|
|
161
156
|
return choose;
|
|
162
157
|
}
|
|
163
158
|
|
|
164
|
-
function resolveLog(_, state, actionArgs, {
|
|
159
|
+
function resolveLog(_, state, actionArgs, actionParams, {
|
|
165
160
|
value,
|
|
166
161
|
label
|
|
167
162
|
}) {
|
|
168
163
|
return [state, {
|
|
169
|
-
value: typeof value === 'function' ? value(actionArgs) : value,
|
|
164
|
+
value: typeof value === 'function' ? value(actionArgs, actionParams) : value,
|
|
170
165
|
label
|
|
171
166
|
}];
|
|
172
167
|
}
|
|
@@ -197,7 +192,7 @@ function log(value = ({
|
|
|
197
192
|
context,
|
|
198
193
|
event
|
|
199
194
|
}), label) {
|
|
200
|
-
function log(
|
|
195
|
+
function log(args, params) {
|
|
201
196
|
{
|
|
202
197
|
throw new Error(`This isn't supposed to be called`);
|
|
203
198
|
}
|
|
@@ -210,7 +205,7 @@ function log(value = ({
|
|
|
210
205
|
return log;
|
|
211
206
|
}
|
|
212
207
|
|
|
213
|
-
function resolvePure(_, state, args, {
|
|
208
|
+
function resolvePure(_, state, args, _actionParams, {
|
|
214
209
|
get
|
|
215
210
|
}) {
|
|
216
211
|
return [state, undefined, toArray(get({
|
|
@@ -219,7 +214,7 @@ function resolvePure(_, state, args, {
|
|
|
219
214
|
}))];
|
|
220
215
|
}
|
|
221
216
|
function pure(getActions) {
|
|
222
|
-
function pure(
|
|
217
|
+
function pure(args, params) {
|
|
223
218
|
{
|
|
224
219
|
throw new Error(`This isn't supposed to be called`);
|
|
225
220
|
}
|
|
@@ -231,6 +226,9 @@ function pure(getActions) {
|
|
|
231
226
|
}
|
|
232
227
|
|
|
233
228
|
/**
|
|
229
|
+
*
|
|
230
|
+
* @remarks
|
|
231
|
+
*
|
|
234
232
|
* `T | unknown` reduces to `unknown` and that can be problematic when it comes to contextual typing.
|
|
235
233
|
* It especially is a problem when the union has a function member, like here:
|
|
236
234
|
*
|
|
@@ -251,7 +249,10 @@ function pure(getActions) {
|
|
|
251
249
|
/**
|
|
252
250
|
* The string or object representing the state value relative to the parent state node.
|
|
253
251
|
*
|
|
252
|
+
* @remarks
|
|
253
|
+
*
|
|
254
254
|
* - For a child atomic state node, this is a string, e.g., `"pending"`.
|
|
255
|
+
*
|
|
255
256
|
* - For complex state nodes, this is an object, e.g., `{ success: "someChildState" }`.
|
|
256
257
|
*/
|
|
257
258
|
|
|
@@ -265,7 +266,7 @@ let SpecialTargets = /*#__PURE__*/function (SpecialTargets) {
|
|
|
265
266
|
return SpecialTargets;
|
|
266
267
|
}({});
|
|
267
268
|
|
|
268
|
-
function resolveSendTo(
|
|
269
|
+
function resolveSendTo(actorScope, state, args, actionParams, {
|
|
269
270
|
to,
|
|
270
271
|
event: eventOrExpr,
|
|
271
272
|
id,
|
|
@@ -275,21 +276,21 @@ function resolveSendTo(actorContext, state, args, {
|
|
|
275
276
|
if (typeof eventOrExpr === 'string') {
|
|
276
277
|
throw new Error(`Only event objects may be used with sendTo; use sendTo({ type: "${eventOrExpr}" }) instead`);
|
|
277
278
|
}
|
|
278
|
-
const resolvedEvent = typeof eventOrExpr === 'function' ? eventOrExpr(args) : eventOrExpr;
|
|
279
|
+
const resolvedEvent = typeof eventOrExpr === 'function' ? eventOrExpr(args, actionParams) : eventOrExpr;
|
|
279
280
|
let resolvedDelay;
|
|
280
281
|
if (typeof delay === 'string') {
|
|
281
282
|
const configDelay = delaysMap && delaysMap[delay];
|
|
282
|
-
resolvedDelay = typeof configDelay === 'function' ? configDelay(args) : configDelay;
|
|
283
|
+
resolvedDelay = typeof configDelay === 'function' ? configDelay(args, actionParams) : configDelay;
|
|
283
284
|
} else {
|
|
284
|
-
resolvedDelay = typeof delay === 'function' ? delay(args) : delay;
|
|
285
|
+
resolvedDelay = typeof delay === 'function' ? delay(args, actionParams) : delay;
|
|
285
286
|
}
|
|
286
|
-
const resolvedTarget = typeof to === 'function' ? to(args) : to;
|
|
287
|
+
const resolvedTarget = typeof to === 'function' ? to(args, actionParams) : to;
|
|
287
288
|
let targetActorRef;
|
|
288
289
|
if (typeof resolvedTarget === 'string') {
|
|
289
290
|
if (resolvedTarget === SpecialTargets.Parent) {
|
|
290
|
-
targetActorRef =
|
|
291
|
+
targetActorRef = actorScope?.self._parent;
|
|
291
292
|
} else if (resolvedTarget === SpecialTargets.Internal) {
|
|
292
|
-
targetActorRef =
|
|
293
|
+
targetActorRef = actorScope?.self;
|
|
293
294
|
} else if (resolvedTarget.startsWith('#_')) {
|
|
294
295
|
// SCXML compatibility: https://www.w3.org/TR/scxml/#SCXMLEventProcessor
|
|
295
296
|
// #_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.
|
|
@@ -301,7 +302,7 @@ function resolveSendTo(actorContext, state, args, {
|
|
|
301
302
|
throw new Error(`Unable to send event to actor '${resolvedTarget}' from machine '${state.machine.id}'.`);
|
|
302
303
|
}
|
|
303
304
|
} else {
|
|
304
|
-
targetActorRef = resolvedTarget ||
|
|
305
|
+
targetActorRef = resolvedTarget || actorScope?.self;
|
|
305
306
|
}
|
|
306
307
|
return [state, {
|
|
307
308
|
to: targetActorRef,
|
|
@@ -315,20 +316,20 @@ function retryResolveSendTo(_, state, params) {
|
|
|
315
316
|
params.to = state.children[params.to];
|
|
316
317
|
}
|
|
317
318
|
}
|
|
318
|
-
function executeSendTo(
|
|
319
|
+
function executeSendTo(actorScope, params) {
|
|
319
320
|
if (typeof params.delay === 'number') {
|
|
320
|
-
|
|
321
|
+
actorScope.self.delaySend(params);
|
|
321
322
|
return;
|
|
322
323
|
}
|
|
323
324
|
|
|
324
325
|
// this forms an outgoing events queue
|
|
325
326
|
// thanks to that the recipient actors are able to read the *updated* snapshot value of the sender
|
|
326
|
-
|
|
327
|
+
actorScope.defer(() => {
|
|
327
328
|
const {
|
|
328
329
|
to,
|
|
329
330
|
event
|
|
330
331
|
} = params;
|
|
331
|
-
|
|
332
|
+
actorScope?.system._relay(actorScope.self, to, event.type === XSTATE_ERROR ? createErrorActorEvent(actorScope.self.id, event.data) : event);
|
|
332
333
|
});
|
|
333
334
|
}
|
|
334
335
|
/**
|
|
@@ -341,7 +342,7 @@ function executeSendTo(actorContext, params) {
|
|
|
341
342
|
* - `delay` - The number of milliseconds to delay the sending of the event.
|
|
342
343
|
*/
|
|
343
344
|
function sendTo(to, eventOrExpr, options) {
|
|
344
|
-
function sendTo(
|
|
345
|
+
function sendTo(args, params) {
|
|
345
346
|
{
|
|
346
347
|
throw new Error(`This isn't supposed to be called`);
|
|
347
348
|
}
|