xstate 5.0.0-beta.29 → 5.0.0-beta.31
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 +100 -104
- package/actors/dist/xstate-actors.development.cjs.js +100 -104
- package/actors/dist/xstate-actors.development.esm.js +100 -104
- package/actors/dist/xstate-actors.esm.js +100 -104
- 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/Machine.d.ts +2 -2
- package/dist/declarations/src/State.d.ts +4 -6
- package/dist/declarations/src/StateMachine.d.ts +28 -21
- package/dist/declarations/src/StateNode.d.ts +3 -3
- package/dist/declarations/src/actions/stop.d.ts +1 -1
- package/dist/declarations/src/actors/callback.d.ts +8 -8
- package/dist/declarations/src/actors/index.d.ts +3 -3
- package/dist/declarations/src/actors/observable.d.ts +12 -13
- package/dist/declarations/src/actors/promise.d.ts +11 -14
- package/dist/declarations/src/actors/transition.d.ts +10 -7
- package/dist/declarations/src/index.d.ts +1 -1
- package/dist/declarations/src/interpreter.d.ts +4 -4
- package/dist/declarations/src/spawn.d.ts +3 -0
- package/dist/declarations/src/stateUtils.d.ts +5 -6
- package/dist/declarations/src/types.d.ts +74 -69
- package/dist/declarations/src/utils.d.ts +4 -4
- package/dist/{interpreter-c357bc50.cjs.js → interpreter-05e11c15.cjs.js} +11 -13
- package/dist/{interpreter-e2c6a579.development.cjs.js → interpreter-a2236840.development.cjs.js} +12 -14
- package/dist/{interpreter-498891b2.esm.js → interpreter-d5fa7ce0.esm.js} +11 -13
- package/dist/{interpreter-6e7909c8.development.esm.js → interpreter-e4d2487f.development.esm.js} +12 -14
- package/dist/{raise-59f2c242.esm.js → raise-6a68d0cc.esm.js} +61 -32
- package/dist/{raise-e778a828.development.esm.js → raise-6fbd4513.development.esm.js} +61 -32
- package/dist/{raise-03e57569.cjs.js → raise-90808d65.cjs.js} +61 -32
- package/dist/{raise-f751dfac.development.cjs.js → raise-b4bfe138.development.cjs.js} +61 -32
- package/dist/{send-f53778f6.development.cjs.js → send-4163d2af.development.cjs.js} +52 -20
- package/dist/{send-51717e53.cjs.js → send-72e85cc6.cjs.js} +52 -20
- package/dist/{send-42c83fb2.development.esm.js → send-7baeedcb.development.esm.js} +52 -20
- package/dist/{send-fff224db.esm.js → send-e5f0f3f6.esm.js} +52 -20
- package/dist/xstate.cjs.js +15 -24
- package/dist/xstate.development.cjs.js +18 -24
- package/dist/xstate.development.esm.js +21 -27
- package/dist/xstate.esm.js +18 -27
- 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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { r as resolveReferencedActor, d as createActor, f as ActorStatus, k as createErrorActorEvent, l as toStateValue, n as STATE_IDENTIFIER, o as normalizeTarget, t as toArray, N as NULL_EVENT, a as toTransitionConfigArray, S as STATE_DELIMITER, q as toStatePath, s as createDoneStateEvent, u as
|
|
1
|
+
import { r as resolveReferencedActor, d as createActor, f as ActorStatus, k as createErrorActorEvent, l as toStateValue, n as STATE_IDENTIFIER, o as normalizeTarget, t as toArray, N as NULL_EVENT, a as toTransitionConfigArray, S as STATE_DELIMITER, q as toStatePath, s as createDoneStateEvent, u as resolveOutput, W as WILDCARD, j as XSTATE_STOP, X as XSTATE_INIT, v as isArray, w as createAfterEvent, x as flatten, e as matchesState } from './interpreter-e4d2487f.development.esm.js';
|
|
2
2
|
|
|
3
3
|
const cache = new WeakMap();
|
|
4
4
|
function memo(object, key, fn) {
|
|
@@ -14,13 +14,13 @@ function memo(object, key, fn) {
|
|
|
14
14
|
return memoizedData[key];
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
function
|
|
17
|
+
function resolveCancel(_, state, actionArgs, {
|
|
18
18
|
sendId
|
|
19
19
|
}) {
|
|
20
20
|
const resolvedSendId = typeof sendId === 'function' ? sendId(actionArgs) : sendId;
|
|
21
21
|
return [state, resolvedSendId];
|
|
22
22
|
}
|
|
23
|
-
function
|
|
23
|
+
function executeCancel(actorContext, resolvedSendId) {
|
|
24
24
|
actorContext.self.cancel(resolvedSendId);
|
|
25
25
|
}
|
|
26
26
|
/**
|
|
@@ -38,16 +38,17 @@ function cancel(sendId) {
|
|
|
38
38
|
}
|
|
39
39
|
cancel.type = 'xstate.cancel';
|
|
40
40
|
cancel.sendId = sendId;
|
|
41
|
-
cancel.resolve =
|
|
42
|
-
cancel.execute =
|
|
41
|
+
cancel.resolve = resolveCancel;
|
|
42
|
+
cancel.execute = executeCancel;
|
|
43
43
|
return cancel;
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
function
|
|
46
|
+
function resolveInvoke(actorContext, state, actionArgs, {
|
|
47
47
|
id,
|
|
48
48
|
systemId,
|
|
49
49
|
src,
|
|
50
|
-
input
|
|
50
|
+
input,
|
|
51
|
+
syncSnapshot
|
|
51
52
|
}) {
|
|
52
53
|
const referenced = resolveReferencedActor(state.machine.implementations.actors[src]);
|
|
53
54
|
let actorRef;
|
|
@@ -65,6 +66,21 @@ function resolve$2(actorContext, state, actionArgs, {
|
|
|
65
66
|
self: actorContext?.self
|
|
66
67
|
}) : configuredInput
|
|
67
68
|
});
|
|
69
|
+
if (syncSnapshot) {
|
|
70
|
+
actorRef.subscribe({
|
|
71
|
+
next: snapshot => {
|
|
72
|
+
if (snapshot.status === 'active') {
|
|
73
|
+
actorContext.self.send({
|
|
74
|
+
type: `xstate.snapshot.${id}`,
|
|
75
|
+
snapshot
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
error: () => {
|
|
80
|
+
/* TODO */
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
}
|
|
68
84
|
}
|
|
69
85
|
if (!actorRef) {
|
|
70
86
|
console.warn(`Actor type '${src}' not found in machine '${actorContext.id}'.`);
|
|
@@ -79,7 +95,7 @@ function resolve$2(actorContext, state, actionArgs, {
|
|
|
79
95
|
actorRef
|
|
80
96
|
}];
|
|
81
97
|
}
|
|
82
|
-
function
|
|
98
|
+
function executeInvoke(actorContext, {
|
|
83
99
|
id,
|
|
84
100
|
actorRef
|
|
85
101
|
}) {
|
|
@@ -105,7 +121,8 @@ function invoke({
|
|
|
105
121
|
id,
|
|
106
122
|
systemId,
|
|
107
123
|
src,
|
|
108
|
-
input
|
|
124
|
+
input,
|
|
125
|
+
onSnapshot
|
|
109
126
|
}) {
|
|
110
127
|
function invoke(_) {
|
|
111
128
|
{
|
|
@@ -117,12 +134,13 @@ function invoke({
|
|
|
117
134
|
invoke.systemId = systemId;
|
|
118
135
|
invoke.src = src;
|
|
119
136
|
invoke.input = input;
|
|
120
|
-
invoke.
|
|
121
|
-
invoke.
|
|
137
|
+
invoke.syncSnapshot = !!onSnapshot;
|
|
138
|
+
invoke.resolve = resolveInvoke;
|
|
139
|
+
invoke.execute = executeInvoke;
|
|
122
140
|
return invoke;
|
|
123
141
|
}
|
|
124
142
|
|
|
125
|
-
function
|
|
143
|
+
function resolveStop(_, state, args, {
|
|
126
144
|
actorRef
|
|
127
145
|
}) {
|
|
128
146
|
const actorRefOrString = typeof actorRef === 'function' ? actorRef(args) : actorRef;
|
|
@@ -138,7 +156,7 @@ function resolve$1(_, state, args, {
|
|
|
138
156
|
children
|
|
139
157
|
}), resolvedActorRef];
|
|
140
158
|
}
|
|
141
|
-
function
|
|
159
|
+
function executeStop(actorContext, actorRef) {
|
|
142
160
|
if (!actorRef) {
|
|
143
161
|
return;
|
|
144
162
|
}
|
|
@@ -164,8 +182,8 @@ function stop(actorRef) {
|
|
|
164
182
|
}
|
|
165
183
|
stop.type = 'xstate.stop';
|
|
166
184
|
stop.actorRef = actorRef;
|
|
167
|
-
stop.resolve =
|
|
168
|
-
stop.execute =
|
|
185
|
+
stop.resolve = resolveStop;
|
|
186
|
+
stop.execute = executeStop;
|
|
169
187
|
return stop;
|
|
170
188
|
}
|
|
171
189
|
|
|
@@ -280,9 +298,18 @@ function evaluateGuard(guard, context, event, state) {
|
|
|
280
298
|
}
|
|
281
299
|
|
|
282
300
|
function getOutput(configuration, context, event, self) {
|
|
283
|
-
const
|
|
301
|
+
const {
|
|
302
|
+
machine
|
|
303
|
+
} = configuration[0];
|
|
304
|
+
const {
|
|
305
|
+
root
|
|
306
|
+
} = machine;
|
|
307
|
+
if (!root.output) {
|
|
308
|
+
return undefined;
|
|
309
|
+
}
|
|
284
310
|
const finalChildStateNode = configuration.find(stateNode => stateNode.type === 'final' && stateNode.parent === machine.root);
|
|
285
|
-
|
|
311
|
+
const doneStateEvent = createDoneStateEvent(finalChildStateNode.id, finalChildStateNode.output ? resolveOutput(finalChildStateNode.output, context, event, self) : undefined);
|
|
312
|
+
return resolveOutput(root.output, context, doneStateEvent, self);
|
|
286
313
|
}
|
|
287
314
|
const isAtomicStateNode = stateNode => stateNode.type === 'atomic' || stateNode.type === 'final';
|
|
288
315
|
function getChildren(stateNode) {
|
|
@@ -921,7 +948,7 @@ function microstepProcedure(transitions, currentState, mutConfiguration, event,
|
|
|
921
948
|
historyValue,
|
|
922
949
|
_internalQueue: internalQueue,
|
|
923
950
|
context: nextState.context,
|
|
924
|
-
done,
|
|
951
|
+
status: done ? 'done' : currentState.status,
|
|
925
952
|
output,
|
|
926
953
|
children: nextState.children
|
|
927
954
|
});
|
|
@@ -959,7 +986,7 @@ function enterStates(event, filteredTransitions, mutConfiguration, actions, inte
|
|
|
959
986
|
if (!parent.parent) {
|
|
960
987
|
continue;
|
|
961
988
|
}
|
|
962
|
-
internalQueue.push(createDoneStateEvent(parent.id, stateNodeToEnter.output ?
|
|
989
|
+
internalQueue.push(createDoneStateEvent(parent.id, stateNodeToEnter.output ? resolveOutput(stateNodeToEnter.output, currentState.context, event, actorContext.self) : undefined));
|
|
963
990
|
if (parent.parent) {
|
|
964
991
|
const grandparent = parent.parent;
|
|
965
992
|
if (grandparent.type === 'parallel') {
|
|
@@ -1153,7 +1180,7 @@ function macrostep(state, event, actorCtx) {
|
|
|
1153
1180
|
nextState = microstep(transitions, state, actorCtx, nextEvent, false);
|
|
1154
1181
|
states.push(nextState);
|
|
1155
1182
|
}
|
|
1156
|
-
while (
|
|
1183
|
+
while (nextState.status === 'active') {
|
|
1157
1184
|
let enabledTransitions = selectEventlessTransitions(nextState, nextEvent);
|
|
1158
1185
|
if (!enabledTransitions.length) {
|
|
1159
1186
|
if (!nextState._internalQueue.length) {
|
|
@@ -1170,7 +1197,7 @@ function macrostep(state, event, actorCtx) {
|
|
|
1170
1197
|
states.push(nextState);
|
|
1171
1198
|
}
|
|
1172
1199
|
}
|
|
1173
|
-
if (nextState.
|
|
1200
|
+
if (nextState.status !== 'active') {
|
|
1174
1201
|
// Perform the stop step to ensure that child actors are stopped
|
|
1175
1202
|
stopStep(nextEvent, nextState, actorCtx);
|
|
1176
1203
|
}
|
|
@@ -1263,7 +1290,8 @@ class State {
|
|
|
1263
1290
|
meta: {},
|
|
1264
1291
|
configuration: [],
|
|
1265
1292
|
// TODO: fix,
|
|
1266
|
-
children: {}
|
|
1293
|
+
children: {},
|
|
1294
|
+
status: 'active'
|
|
1267
1295
|
}, machine);
|
|
1268
1296
|
}
|
|
1269
1297
|
return stateValue;
|
|
@@ -1274,7 +1302,8 @@ class State {
|
|
|
1274
1302
|
context,
|
|
1275
1303
|
meta: undefined,
|
|
1276
1304
|
configuration: Array.from(configuration),
|
|
1277
|
-
children: {}
|
|
1305
|
+
children: {},
|
|
1306
|
+
status: 'active'
|
|
1278
1307
|
}, machine);
|
|
1279
1308
|
}
|
|
1280
1309
|
|
|
@@ -1287,8 +1316,7 @@ class State {
|
|
|
1287
1316
|
this.machine = machine;
|
|
1288
1317
|
this.tags = void 0;
|
|
1289
1318
|
this.value = void 0;
|
|
1290
|
-
this.
|
|
1291
|
-
this.output = void 0;
|
|
1319
|
+
this.status = void 0;
|
|
1292
1320
|
this.error = void 0;
|
|
1293
1321
|
this.context = void 0;
|
|
1294
1322
|
this.historyValue = {};
|
|
@@ -1304,7 +1332,7 @@ class State {
|
|
|
1304
1332
|
this.children = config.children;
|
|
1305
1333
|
this.value = getStateValue(machine.root, this.configuration);
|
|
1306
1334
|
this.tags = new Set(flatten(this.configuration.map(sn => sn.tags)));
|
|
1307
|
-
this.
|
|
1335
|
+
this.status = config.status;
|
|
1308
1336
|
this.output = config.output;
|
|
1309
1337
|
this.error = config.error;
|
|
1310
1338
|
}
|
|
@@ -1402,9 +1430,10 @@ function getPersistedState(state) {
|
|
|
1402
1430
|
} = state;
|
|
1403
1431
|
const childrenJson = {};
|
|
1404
1432
|
for (const id in children) {
|
|
1433
|
+
const child = children[id];
|
|
1405
1434
|
childrenJson[id] = {
|
|
1406
|
-
state:
|
|
1407
|
-
src:
|
|
1435
|
+
state: child.getPersistedState?.(),
|
|
1436
|
+
src: child.src
|
|
1408
1437
|
};
|
|
1409
1438
|
}
|
|
1410
1439
|
return {
|
|
@@ -1413,7 +1442,7 @@ function getPersistedState(state) {
|
|
|
1413
1442
|
};
|
|
1414
1443
|
}
|
|
1415
1444
|
|
|
1416
|
-
function
|
|
1445
|
+
function resolveRaise(_, state, args, {
|
|
1417
1446
|
event: eventOrExpr,
|
|
1418
1447
|
id,
|
|
1419
1448
|
delay
|
|
@@ -1438,7 +1467,7 @@ function resolve(_, state, args, {
|
|
|
1438
1467
|
delay: resolvedDelay
|
|
1439
1468
|
}];
|
|
1440
1469
|
}
|
|
1441
|
-
function
|
|
1470
|
+
function executeRaise(actorContext, params) {
|
|
1442
1471
|
if (typeof params.delay === 'number') {
|
|
1443
1472
|
actorContext.self.delaySend(params);
|
|
1444
1473
|
return;
|
|
@@ -1460,8 +1489,8 @@ function raise(eventOrExpr, options) {
|
|
|
1460
1489
|
raise.event = eventOrExpr;
|
|
1461
1490
|
raise.id = options?.id;
|
|
1462
1491
|
raise.delay = options?.delay;
|
|
1463
|
-
raise.resolve =
|
|
1464
|
-
raise.execute =
|
|
1492
|
+
raise.resolve = resolveRaise;
|
|
1493
|
+
raise.execute = executeRaise;
|
|
1465
1494
|
return raise;
|
|
1466
1495
|
}
|
|
1467
1496
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var interpreter = require('./interpreter-
|
|
3
|
+
var interpreter = require('./interpreter-05e11c15.cjs.js');
|
|
4
4
|
|
|
5
5
|
const cache = new WeakMap();
|
|
6
6
|
function memo(object, key, fn) {
|
|
@@ -16,13 +16,13 @@ function memo(object, key, fn) {
|
|
|
16
16
|
return memoizedData[key];
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
function
|
|
19
|
+
function resolveCancel(_, state, actionArgs, {
|
|
20
20
|
sendId
|
|
21
21
|
}) {
|
|
22
22
|
const resolvedSendId = typeof sendId === 'function' ? sendId(actionArgs) : sendId;
|
|
23
23
|
return [state, resolvedSendId];
|
|
24
24
|
}
|
|
25
|
-
function
|
|
25
|
+
function executeCancel(actorContext, resolvedSendId) {
|
|
26
26
|
actorContext.self.cancel(resolvedSendId);
|
|
27
27
|
}
|
|
28
28
|
/**
|
|
@@ -37,16 +37,17 @@ function cancel(sendId) {
|
|
|
37
37
|
}
|
|
38
38
|
cancel.type = 'xstate.cancel';
|
|
39
39
|
cancel.sendId = sendId;
|
|
40
|
-
cancel.resolve =
|
|
41
|
-
cancel.execute =
|
|
40
|
+
cancel.resolve = resolveCancel;
|
|
41
|
+
cancel.execute = executeCancel;
|
|
42
42
|
return cancel;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
function
|
|
45
|
+
function resolveInvoke(actorContext, state, actionArgs, {
|
|
46
46
|
id,
|
|
47
47
|
systemId,
|
|
48
48
|
src,
|
|
49
|
-
input
|
|
49
|
+
input,
|
|
50
|
+
syncSnapshot
|
|
50
51
|
}) {
|
|
51
52
|
const referenced = interpreter.resolveReferencedActor(state.machine.implementations.actors[src]);
|
|
52
53
|
let actorRef;
|
|
@@ -64,6 +65,21 @@ function resolve$2(actorContext, state, actionArgs, {
|
|
|
64
65
|
self: actorContext?.self
|
|
65
66
|
}) : configuredInput
|
|
66
67
|
});
|
|
68
|
+
if (syncSnapshot) {
|
|
69
|
+
actorRef.subscribe({
|
|
70
|
+
next: snapshot => {
|
|
71
|
+
if (snapshot.status === 'active') {
|
|
72
|
+
actorContext.self.send({
|
|
73
|
+
type: `xstate.snapshot.${id}`,
|
|
74
|
+
snapshot
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
error: () => {
|
|
79
|
+
/* TODO */
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
}
|
|
67
83
|
}
|
|
68
84
|
return [cloneState(state, {
|
|
69
85
|
children: {
|
|
@@ -75,7 +91,7 @@ function resolve$2(actorContext, state, actionArgs, {
|
|
|
75
91
|
actorRef
|
|
76
92
|
}];
|
|
77
93
|
}
|
|
78
|
-
function
|
|
94
|
+
function executeInvoke(actorContext, {
|
|
79
95
|
id,
|
|
80
96
|
actorRef
|
|
81
97
|
}) {
|
|
@@ -101,7 +117,8 @@ function invoke({
|
|
|
101
117
|
id,
|
|
102
118
|
systemId,
|
|
103
119
|
src,
|
|
104
|
-
input
|
|
120
|
+
input,
|
|
121
|
+
onSnapshot
|
|
105
122
|
}) {
|
|
106
123
|
function invoke(_) {
|
|
107
124
|
}
|
|
@@ -110,12 +127,13 @@ function invoke({
|
|
|
110
127
|
invoke.systemId = systemId;
|
|
111
128
|
invoke.src = src;
|
|
112
129
|
invoke.input = input;
|
|
113
|
-
invoke.
|
|
114
|
-
invoke.
|
|
130
|
+
invoke.syncSnapshot = !!onSnapshot;
|
|
131
|
+
invoke.resolve = resolveInvoke;
|
|
132
|
+
invoke.execute = executeInvoke;
|
|
115
133
|
return invoke;
|
|
116
134
|
}
|
|
117
135
|
|
|
118
|
-
function
|
|
136
|
+
function resolveStop(_, state, args, {
|
|
119
137
|
actorRef
|
|
120
138
|
}) {
|
|
121
139
|
const actorRefOrString = typeof actorRef === 'function' ? actorRef(args) : actorRef;
|
|
@@ -131,7 +149,7 @@ function resolve$1(_, state, args, {
|
|
|
131
149
|
children
|
|
132
150
|
}), resolvedActorRef];
|
|
133
151
|
}
|
|
134
|
-
function
|
|
152
|
+
function executeStop(actorContext, actorRef) {
|
|
135
153
|
if (!actorRef) {
|
|
136
154
|
return;
|
|
137
155
|
}
|
|
@@ -154,8 +172,8 @@ function stop(actorRef) {
|
|
|
154
172
|
}
|
|
155
173
|
stop.type = 'xstate.stop';
|
|
156
174
|
stop.actorRef = actorRef;
|
|
157
|
-
stop.resolve =
|
|
158
|
-
stop.execute =
|
|
175
|
+
stop.resolve = resolveStop;
|
|
176
|
+
stop.execute = executeStop;
|
|
159
177
|
return stop;
|
|
160
178
|
}
|
|
161
179
|
|
|
@@ -262,9 +280,18 @@ function evaluateGuard(guard, context, event, state) {
|
|
|
262
280
|
}
|
|
263
281
|
|
|
264
282
|
function getOutput(configuration, context, event, self) {
|
|
265
|
-
const
|
|
283
|
+
const {
|
|
284
|
+
machine
|
|
285
|
+
} = configuration[0];
|
|
286
|
+
const {
|
|
287
|
+
root
|
|
288
|
+
} = machine;
|
|
289
|
+
if (!root.output) {
|
|
290
|
+
return undefined;
|
|
291
|
+
}
|
|
266
292
|
const finalChildStateNode = configuration.find(stateNode => stateNode.type === 'final' && stateNode.parent === machine.root);
|
|
267
|
-
|
|
293
|
+
const doneStateEvent = interpreter.createDoneStateEvent(finalChildStateNode.id, finalChildStateNode.output ? interpreter.resolveOutput(finalChildStateNode.output, context, event, self) : undefined);
|
|
294
|
+
return interpreter.resolveOutput(root.output, context, doneStateEvent, self);
|
|
268
295
|
}
|
|
269
296
|
const isAtomicStateNode = stateNode => stateNode.type === 'atomic' || stateNode.type === 'final';
|
|
270
297
|
function getChildren(stateNode) {
|
|
@@ -892,7 +919,7 @@ function microstepProcedure(transitions, currentState, mutConfiguration, event,
|
|
|
892
919
|
historyValue,
|
|
893
920
|
_internalQueue: internalQueue,
|
|
894
921
|
context: nextState.context,
|
|
895
|
-
done,
|
|
922
|
+
status: done ? 'done' : currentState.status,
|
|
896
923
|
output,
|
|
897
924
|
children: nextState.children
|
|
898
925
|
});
|
|
@@ -930,7 +957,7 @@ function enterStates(event, filteredTransitions, mutConfiguration, actions, inte
|
|
|
930
957
|
if (!parent.parent) {
|
|
931
958
|
continue;
|
|
932
959
|
}
|
|
933
|
-
internalQueue.push(interpreter.createDoneStateEvent(parent.id, stateNodeToEnter.output ? interpreter.
|
|
960
|
+
internalQueue.push(interpreter.createDoneStateEvent(parent.id, stateNodeToEnter.output ? interpreter.resolveOutput(stateNodeToEnter.output, currentState.context, event, actorContext.self) : undefined));
|
|
934
961
|
if (parent.parent) {
|
|
935
962
|
const grandparent = parent.parent;
|
|
936
963
|
if (grandparent.type === 'parallel') {
|
|
@@ -1121,7 +1148,7 @@ function macrostep(state, event, actorCtx) {
|
|
|
1121
1148
|
nextState = microstep(transitions, state, actorCtx, nextEvent, false);
|
|
1122
1149
|
states.push(nextState);
|
|
1123
1150
|
}
|
|
1124
|
-
while (
|
|
1151
|
+
while (nextState.status === 'active') {
|
|
1125
1152
|
let enabledTransitions = selectEventlessTransitions(nextState, nextEvent);
|
|
1126
1153
|
if (!enabledTransitions.length) {
|
|
1127
1154
|
if (!nextState._internalQueue.length) {
|
|
@@ -1138,7 +1165,7 @@ function macrostep(state, event, actorCtx) {
|
|
|
1138
1165
|
states.push(nextState);
|
|
1139
1166
|
}
|
|
1140
1167
|
}
|
|
1141
|
-
if (nextState.
|
|
1168
|
+
if (nextState.status !== 'active') {
|
|
1142
1169
|
// Perform the stop step to ensure that child actors are stopped
|
|
1143
1170
|
stopStep(nextEvent, nextState, actorCtx);
|
|
1144
1171
|
}
|
|
@@ -1231,7 +1258,8 @@ class State {
|
|
|
1231
1258
|
meta: {},
|
|
1232
1259
|
configuration: [],
|
|
1233
1260
|
// TODO: fix,
|
|
1234
|
-
children: {}
|
|
1261
|
+
children: {},
|
|
1262
|
+
status: 'active'
|
|
1235
1263
|
}, machine);
|
|
1236
1264
|
}
|
|
1237
1265
|
return stateValue;
|
|
@@ -1242,7 +1270,8 @@ class State {
|
|
|
1242
1270
|
context,
|
|
1243
1271
|
meta: undefined,
|
|
1244
1272
|
configuration: Array.from(configuration),
|
|
1245
|
-
children: {}
|
|
1273
|
+
children: {},
|
|
1274
|
+
status: 'active'
|
|
1246
1275
|
}, machine);
|
|
1247
1276
|
}
|
|
1248
1277
|
|
|
@@ -1255,8 +1284,7 @@ class State {
|
|
|
1255
1284
|
this.machine = machine;
|
|
1256
1285
|
this.tags = void 0;
|
|
1257
1286
|
this.value = void 0;
|
|
1258
|
-
this.
|
|
1259
|
-
this.output = void 0;
|
|
1287
|
+
this.status = void 0;
|
|
1260
1288
|
this.error = void 0;
|
|
1261
1289
|
this.context = void 0;
|
|
1262
1290
|
this.historyValue = {};
|
|
@@ -1272,7 +1300,7 @@ class State {
|
|
|
1272
1300
|
this.children = config.children;
|
|
1273
1301
|
this.value = getStateValue(machine.root, this.configuration);
|
|
1274
1302
|
this.tags = new Set(interpreter.flatten(this.configuration.map(sn => sn.tags)));
|
|
1275
|
-
this.
|
|
1303
|
+
this.status = config.status;
|
|
1276
1304
|
this.output = config.output;
|
|
1277
1305
|
this.error = config.error;
|
|
1278
1306
|
}
|
|
@@ -1367,9 +1395,10 @@ function getPersistedState(state) {
|
|
|
1367
1395
|
} = state;
|
|
1368
1396
|
const childrenJson = {};
|
|
1369
1397
|
for (const id in children) {
|
|
1398
|
+
const child = children[id];
|
|
1370
1399
|
childrenJson[id] = {
|
|
1371
|
-
state:
|
|
1372
|
-
src:
|
|
1400
|
+
state: child.getPersistedState?.(),
|
|
1401
|
+
src: child.src
|
|
1373
1402
|
};
|
|
1374
1403
|
}
|
|
1375
1404
|
return {
|
|
@@ -1378,7 +1407,7 @@ function getPersistedState(state) {
|
|
|
1378
1407
|
};
|
|
1379
1408
|
}
|
|
1380
1409
|
|
|
1381
|
-
function
|
|
1410
|
+
function resolveRaise(_, state, args, {
|
|
1382
1411
|
event: eventOrExpr,
|
|
1383
1412
|
id,
|
|
1384
1413
|
delay
|
|
@@ -1403,7 +1432,7 @@ function resolve(_, state, args, {
|
|
|
1403
1432
|
delay: resolvedDelay
|
|
1404
1433
|
}];
|
|
1405
1434
|
}
|
|
1406
|
-
function
|
|
1435
|
+
function executeRaise(actorContext, params) {
|
|
1407
1436
|
if (typeof params.delay === 'number') {
|
|
1408
1437
|
actorContext.self.delaySend(params);
|
|
1409
1438
|
return;
|
|
@@ -1422,8 +1451,8 @@ function raise(eventOrExpr, options) {
|
|
|
1422
1451
|
raise.event = eventOrExpr;
|
|
1423
1452
|
raise.id = options?.id;
|
|
1424
1453
|
raise.delay = options?.delay;
|
|
1425
|
-
raise.resolve =
|
|
1426
|
-
raise.execute =
|
|
1454
|
+
raise.resolve = resolveRaise;
|
|
1455
|
+
raise.execute = executeRaise;
|
|
1427
1456
|
return raise;
|
|
1428
1457
|
}
|
|
1429
1458
|
|