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,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var interpreter = require('./interpreter-
|
|
3
|
+
var interpreter = require('./interpreter-a2236840.development.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
|
/**
|
|
@@ -40,16 +40,17 @@ function cancel(sendId) {
|
|
|
40
40
|
}
|
|
41
41
|
cancel.type = 'xstate.cancel';
|
|
42
42
|
cancel.sendId = sendId;
|
|
43
|
-
cancel.resolve =
|
|
44
|
-
cancel.execute =
|
|
43
|
+
cancel.resolve = resolveCancel;
|
|
44
|
+
cancel.execute = executeCancel;
|
|
45
45
|
return cancel;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
function
|
|
48
|
+
function resolveInvoke(actorContext, state, actionArgs, {
|
|
49
49
|
id,
|
|
50
50
|
systemId,
|
|
51
51
|
src,
|
|
52
|
-
input
|
|
52
|
+
input,
|
|
53
|
+
syncSnapshot
|
|
53
54
|
}) {
|
|
54
55
|
const referenced = interpreter.resolveReferencedActor(state.machine.implementations.actors[src]);
|
|
55
56
|
let actorRef;
|
|
@@ -67,6 +68,21 @@ function resolve$2(actorContext, state, actionArgs, {
|
|
|
67
68
|
self: actorContext?.self
|
|
68
69
|
}) : configuredInput
|
|
69
70
|
});
|
|
71
|
+
if (syncSnapshot) {
|
|
72
|
+
actorRef.subscribe({
|
|
73
|
+
next: snapshot => {
|
|
74
|
+
if (snapshot.status === 'active') {
|
|
75
|
+
actorContext.self.send({
|
|
76
|
+
type: `xstate.snapshot.${id}`,
|
|
77
|
+
snapshot
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
error: () => {
|
|
82
|
+
/* TODO */
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
}
|
|
70
86
|
}
|
|
71
87
|
if (!actorRef) {
|
|
72
88
|
console.warn(`Actor type '${src}' not found in machine '${actorContext.id}'.`);
|
|
@@ -81,7 +97,7 @@ function resolve$2(actorContext, state, actionArgs, {
|
|
|
81
97
|
actorRef
|
|
82
98
|
}];
|
|
83
99
|
}
|
|
84
|
-
function
|
|
100
|
+
function executeInvoke(actorContext, {
|
|
85
101
|
id,
|
|
86
102
|
actorRef
|
|
87
103
|
}) {
|
|
@@ -107,7 +123,8 @@ function invoke({
|
|
|
107
123
|
id,
|
|
108
124
|
systemId,
|
|
109
125
|
src,
|
|
110
|
-
input
|
|
126
|
+
input,
|
|
127
|
+
onSnapshot
|
|
111
128
|
}) {
|
|
112
129
|
function invoke(_) {
|
|
113
130
|
{
|
|
@@ -119,12 +136,13 @@ function invoke({
|
|
|
119
136
|
invoke.systemId = systemId;
|
|
120
137
|
invoke.src = src;
|
|
121
138
|
invoke.input = input;
|
|
122
|
-
invoke.
|
|
123
|
-
invoke.
|
|
139
|
+
invoke.syncSnapshot = !!onSnapshot;
|
|
140
|
+
invoke.resolve = resolveInvoke;
|
|
141
|
+
invoke.execute = executeInvoke;
|
|
124
142
|
return invoke;
|
|
125
143
|
}
|
|
126
144
|
|
|
127
|
-
function
|
|
145
|
+
function resolveStop(_, state, args, {
|
|
128
146
|
actorRef
|
|
129
147
|
}) {
|
|
130
148
|
const actorRefOrString = typeof actorRef === 'function' ? actorRef(args) : actorRef;
|
|
@@ -140,7 +158,7 @@ function resolve$1(_, state, args, {
|
|
|
140
158
|
children
|
|
141
159
|
}), resolvedActorRef];
|
|
142
160
|
}
|
|
143
|
-
function
|
|
161
|
+
function executeStop(actorContext, actorRef) {
|
|
144
162
|
if (!actorRef) {
|
|
145
163
|
return;
|
|
146
164
|
}
|
|
@@ -166,8 +184,8 @@ function stop(actorRef) {
|
|
|
166
184
|
}
|
|
167
185
|
stop.type = 'xstate.stop';
|
|
168
186
|
stop.actorRef = actorRef;
|
|
169
|
-
stop.resolve =
|
|
170
|
-
stop.execute =
|
|
187
|
+
stop.resolve = resolveStop;
|
|
188
|
+
stop.execute = executeStop;
|
|
171
189
|
return stop;
|
|
172
190
|
}
|
|
173
191
|
|
|
@@ -282,9 +300,18 @@ function evaluateGuard(guard, context, event, state) {
|
|
|
282
300
|
}
|
|
283
301
|
|
|
284
302
|
function getOutput(configuration, context, event, self) {
|
|
285
|
-
const
|
|
303
|
+
const {
|
|
304
|
+
machine
|
|
305
|
+
} = configuration[0];
|
|
306
|
+
const {
|
|
307
|
+
root
|
|
308
|
+
} = machine;
|
|
309
|
+
if (!root.output) {
|
|
310
|
+
return undefined;
|
|
311
|
+
}
|
|
286
312
|
const finalChildStateNode = configuration.find(stateNode => stateNode.type === 'final' && stateNode.parent === machine.root);
|
|
287
|
-
|
|
313
|
+
const doneStateEvent = interpreter.createDoneStateEvent(finalChildStateNode.id, finalChildStateNode.output ? interpreter.resolveOutput(finalChildStateNode.output, context, event, self) : undefined);
|
|
314
|
+
return interpreter.resolveOutput(root.output, context, doneStateEvent, self);
|
|
288
315
|
}
|
|
289
316
|
const isAtomicStateNode = stateNode => stateNode.type === 'atomic' || stateNode.type === 'final';
|
|
290
317
|
function getChildren(stateNode) {
|
|
@@ -923,7 +950,7 @@ function microstepProcedure(transitions, currentState, mutConfiguration, event,
|
|
|
923
950
|
historyValue,
|
|
924
951
|
_internalQueue: internalQueue,
|
|
925
952
|
context: nextState.context,
|
|
926
|
-
done,
|
|
953
|
+
status: done ? 'done' : currentState.status,
|
|
927
954
|
output,
|
|
928
955
|
children: nextState.children
|
|
929
956
|
});
|
|
@@ -961,7 +988,7 @@ function enterStates(event, filteredTransitions, mutConfiguration, actions, inte
|
|
|
961
988
|
if (!parent.parent) {
|
|
962
989
|
continue;
|
|
963
990
|
}
|
|
964
|
-
internalQueue.push(interpreter.createDoneStateEvent(parent.id, stateNodeToEnter.output ? interpreter.
|
|
991
|
+
internalQueue.push(interpreter.createDoneStateEvent(parent.id, stateNodeToEnter.output ? interpreter.resolveOutput(stateNodeToEnter.output, currentState.context, event, actorContext.self) : undefined));
|
|
965
992
|
if (parent.parent) {
|
|
966
993
|
const grandparent = parent.parent;
|
|
967
994
|
if (grandparent.type === 'parallel') {
|
|
@@ -1155,7 +1182,7 @@ function macrostep(state, event, actorCtx) {
|
|
|
1155
1182
|
nextState = microstep(transitions, state, actorCtx, nextEvent, false);
|
|
1156
1183
|
states.push(nextState);
|
|
1157
1184
|
}
|
|
1158
|
-
while (
|
|
1185
|
+
while (nextState.status === 'active') {
|
|
1159
1186
|
let enabledTransitions = selectEventlessTransitions(nextState, nextEvent);
|
|
1160
1187
|
if (!enabledTransitions.length) {
|
|
1161
1188
|
if (!nextState._internalQueue.length) {
|
|
@@ -1172,7 +1199,7 @@ function macrostep(state, event, actorCtx) {
|
|
|
1172
1199
|
states.push(nextState);
|
|
1173
1200
|
}
|
|
1174
1201
|
}
|
|
1175
|
-
if (nextState.
|
|
1202
|
+
if (nextState.status !== 'active') {
|
|
1176
1203
|
// Perform the stop step to ensure that child actors are stopped
|
|
1177
1204
|
stopStep(nextEvent, nextState, actorCtx);
|
|
1178
1205
|
}
|
|
@@ -1265,7 +1292,8 @@ class State {
|
|
|
1265
1292
|
meta: {},
|
|
1266
1293
|
configuration: [],
|
|
1267
1294
|
// TODO: fix,
|
|
1268
|
-
children: {}
|
|
1295
|
+
children: {},
|
|
1296
|
+
status: 'active'
|
|
1269
1297
|
}, machine);
|
|
1270
1298
|
}
|
|
1271
1299
|
return stateValue;
|
|
@@ -1276,7 +1304,8 @@ class State {
|
|
|
1276
1304
|
context,
|
|
1277
1305
|
meta: undefined,
|
|
1278
1306
|
configuration: Array.from(configuration),
|
|
1279
|
-
children: {}
|
|
1307
|
+
children: {},
|
|
1308
|
+
status: 'active'
|
|
1280
1309
|
}, machine);
|
|
1281
1310
|
}
|
|
1282
1311
|
|
|
@@ -1289,8 +1318,7 @@ class State {
|
|
|
1289
1318
|
this.machine = machine;
|
|
1290
1319
|
this.tags = void 0;
|
|
1291
1320
|
this.value = void 0;
|
|
1292
|
-
this.
|
|
1293
|
-
this.output = void 0;
|
|
1321
|
+
this.status = void 0;
|
|
1294
1322
|
this.error = void 0;
|
|
1295
1323
|
this.context = void 0;
|
|
1296
1324
|
this.historyValue = {};
|
|
@@ -1306,7 +1334,7 @@ class State {
|
|
|
1306
1334
|
this.children = config.children;
|
|
1307
1335
|
this.value = getStateValue(machine.root, this.configuration);
|
|
1308
1336
|
this.tags = new Set(interpreter.flatten(this.configuration.map(sn => sn.tags)));
|
|
1309
|
-
this.
|
|
1337
|
+
this.status = config.status;
|
|
1310
1338
|
this.output = config.output;
|
|
1311
1339
|
this.error = config.error;
|
|
1312
1340
|
}
|
|
@@ -1404,9 +1432,10 @@ function getPersistedState(state) {
|
|
|
1404
1432
|
} = state;
|
|
1405
1433
|
const childrenJson = {};
|
|
1406
1434
|
for (const id in children) {
|
|
1435
|
+
const child = children[id];
|
|
1407
1436
|
childrenJson[id] = {
|
|
1408
|
-
state:
|
|
1409
|
-
src:
|
|
1437
|
+
state: child.getPersistedState?.(),
|
|
1438
|
+
src: child.src
|
|
1410
1439
|
};
|
|
1411
1440
|
}
|
|
1412
1441
|
return {
|
|
@@ -1415,7 +1444,7 @@ function getPersistedState(state) {
|
|
|
1415
1444
|
};
|
|
1416
1445
|
}
|
|
1417
1446
|
|
|
1418
|
-
function
|
|
1447
|
+
function resolveRaise(_, state, args, {
|
|
1419
1448
|
event: eventOrExpr,
|
|
1420
1449
|
id,
|
|
1421
1450
|
delay
|
|
@@ -1440,7 +1469,7 @@ function resolve(_, state, args, {
|
|
|
1440
1469
|
delay: resolvedDelay
|
|
1441
1470
|
}];
|
|
1442
1471
|
}
|
|
1443
|
-
function
|
|
1472
|
+
function executeRaise(actorContext, params) {
|
|
1444
1473
|
if (typeof params.delay === 'number') {
|
|
1445
1474
|
actorContext.self.delaySend(params);
|
|
1446
1475
|
return;
|
|
@@ -1462,8 +1491,8 @@ function raise(eventOrExpr, options) {
|
|
|
1462
1491
|
raise.event = eventOrExpr;
|
|
1463
1492
|
raise.id = options?.id;
|
|
1464
1493
|
raise.delay = options?.delay;
|
|
1465
|
-
raise.resolve =
|
|
1466
|
-
raise.execute =
|
|
1494
|
+
raise.resolve = resolveRaise;
|
|
1495
|
+
raise.execute = executeRaise;
|
|
1467
1496
|
return raise;
|
|
1468
1497
|
}
|
|
1469
1498
|
|
|
@@ -1,7 +1,7 @@
|
|
|
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-b4bfe138.development.cjs.js');
|
|
4
|
+
var interpreter = require('./interpreter-a2236840.development.cjs.js');
|
|
5
5
|
|
|
6
6
|
function createSpawner(actorContext, {
|
|
7
7
|
machine,
|
|
@@ -19,7 +19,7 @@ function createSpawner(actorContext, {
|
|
|
19
19
|
const input = 'input' in options ? options.input : referenced.input;
|
|
20
20
|
|
|
21
21
|
// TODO: this should also receive `src`
|
|
22
|
-
const
|
|
22
|
+
const actorRef = interpreter.createActor(referenced.src, {
|
|
23
23
|
id: options.id,
|
|
24
24
|
parent: actorContext.self,
|
|
25
25
|
input: typeof input === 'function' ? input({
|
|
@@ -29,16 +29,48 @@ function createSpawner(actorContext, {
|
|
|
29
29
|
}) : input,
|
|
30
30
|
systemId
|
|
31
31
|
});
|
|
32
|
-
spawnedChildren[
|
|
33
|
-
|
|
32
|
+
spawnedChildren[actorRef.id] = actorRef;
|
|
33
|
+
if (options.syncSnapshot) {
|
|
34
|
+
actorRef.subscribe({
|
|
35
|
+
next: snapshot => {
|
|
36
|
+
if (snapshot.status === 'active') {
|
|
37
|
+
actorContext.self.send({
|
|
38
|
+
type: `xstate.snapshot.${actorRef.id}`,
|
|
39
|
+
snapshot
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
error: () => {
|
|
44
|
+
/* TODO */
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
return actorRef;
|
|
34
49
|
} else {
|
|
35
50
|
// TODO: this should also receive `src`
|
|
36
|
-
|
|
51
|
+
const actorRef = interpreter.createActor(src, {
|
|
37
52
|
id: options.id,
|
|
38
53
|
parent: actorContext.self,
|
|
39
54
|
input: options.input,
|
|
40
55
|
systemId
|
|
41
56
|
});
|
|
57
|
+
if (options.syncSnapshot) {
|
|
58
|
+
actorRef.subscribe({
|
|
59
|
+
next: snapshot => {
|
|
60
|
+
if (snapshot.status === 'active') {
|
|
61
|
+
actorContext.self.send({
|
|
62
|
+
type: `xstate.snapshot.${actorRef.id}`,
|
|
63
|
+
snapshot,
|
|
64
|
+
id: actorRef.id
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
error: () => {
|
|
69
|
+
/* TODO */
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
return actorRef;
|
|
42
74
|
}
|
|
43
75
|
};
|
|
44
76
|
return (src, options) => {
|
|
@@ -59,7 +91,7 @@ function createSpawner(actorContext, {
|
|
|
59
91
|
};
|
|
60
92
|
}
|
|
61
93
|
|
|
62
|
-
function
|
|
94
|
+
function resolveAssign(actorContext, state, actionArgs, {
|
|
63
95
|
assignment
|
|
64
96
|
}) {
|
|
65
97
|
if (!state.context) {
|
|
@@ -105,11 +137,11 @@ function assign(assignment) {
|
|
|
105
137
|
}
|
|
106
138
|
assign.type = 'xstate.assign';
|
|
107
139
|
assign.assignment = assignment;
|
|
108
|
-
assign.resolve =
|
|
140
|
+
assign.resolve = resolveAssign;
|
|
109
141
|
return assign;
|
|
110
142
|
}
|
|
111
143
|
|
|
112
|
-
function
|
|
144
|
+
function resolveChoose(_, state, actionArgs, {
|
|
113
145
|
branches
|
|
114
146
|
}) {
|
|
115
147
|
const matchedActions = branches.find(condition => {
|
|
@@ -125,11 +157,11 @@ function choose(branches) {
|
|
|
125
157
|
}
|
|
126
158
|
choose.type = 'xstate.choose';
|
|
127
159
|
choose.branches = branches;
|
|
128
|
-
choose.resolve =
|
|
160
|
+
choose.resolve = resolveChoose;
|
|
129
161
|
return choose;
|
|
130
162
|
}
|
|
131
163
|
|
|
132
|
-
function
|
|
164
|
+
function resolveLog(_, state, actionArgs, {
|
|
133
165
|
value,
|
|
134
166
|
label
|
|
135
167
|
}) {
|
|
@@ -138,7 +170,7 @@ function resolve$2(_, state, actionArgs, {
|
|
|
138
170
|
label
|
|
139
171
|
}];
|
|
140
172
|
}
|
|
141
|
-
function
|
|
173
|
+
function executeLog({
|
|
142
174
|
logger
|
|
143
175
|
}, {
|
|
144
176
|
value,
|
|
@@ -173,12 +205,12 @@ function log(value = ({
|
|
|
173
205
|
log.type = 'xstate.log';
|
|
174
206
|
log.value = value;
|
|
175
207
|
log.label = label;
|
|
176
|
-
log.resolve =
|
|
177
|
-
log.execute =
|
|
208
|
+
log.resolve = resolveLog;
|
|
209
|
+
log.execute = executeLog;
|
|
178
210
|
return log;
|
|
179
211
|
}
|
|
180
212
|
|
|
181
|
-
function
|
|
213
|
+
function resolvePure(_, state, args, {
|
|
182
214
|
get
|
|
183
215
|
}) {
|
|
184
216
|
return [state, undefined, interpreter.toArray(get({
|
|
@@ -194,7 +226,7 @@ function pure(getActions) {
|
|
|
194
226
|
}
|
|
195
227
|
pure.type = 'xstate.pure';
|
|
196
228
|
pure.get = getActions;
|
|
197
|
-
pure.resolve =
|
|
229
|
+
pure.resolve = resolvePure;
|
|
198
230
|
return pure;
|
|
199
231
|
}
|
|
200
232
|
|
|
@@ -233,7 +265,7 @@ let SpecialTargets = /*#__PURE__*/function (SpecialTargets) {
|
|
|
233
265
|
return SpecialTargets;
|
|
234
266
|
}({});
|
|
235
267
|
|
|
236
|
-
function
|
|
268
|
+
function resolveSendTo(actorContext, state, args, {
|
|
237
269
|
to,
|
|
238
270
|
event: eventOrExpr,
|
|
239
271
|
id,
|
|
@@ -278,7 +310,7 @@ function resolve(actorContext, state, args, {
|
|
|
278
310
|
delay: resolvedDelay
|
|
279
311
|
}];
|
|
280
312
|
}
|
|
281
|
-
function
|
|
313
|
+
function executeSendTo(actorContext, params) {
|
|
282
314
|
if (typeof params.delay === 'number') {
|
|
283
315
|
actorContext.self.delaySend(params);
|
|
284
316
|
return;
|
|
@@ -311,8 +343,8 @@ function sendTo(to, eventOrExpr, options) {
|
|
|
311
343
|
sendTo.event = eventOrExpr;
|
|
312
344
|
sendTo.id = options?.id;
|
|
313
345
|
sendTo.delay = options?.delay;
|
|
314
|
-
sendTo.resolve =
|
|
315
|
-
sendTo.execute =
|
|
346
|
+
sendTo.resolve = resolveSendTo;
|
|
347
|
+
sendTo.execute = executeSendTo;
|
|
316
348
|
return sendTo;
|
|
317
349
|
}
|
|
318
350
|
|
|
@@ -1,7 +1,7 @@
|
|
|
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-90808d65.cjs.js');
|
|
4
|
+
var interpreter = require('./interpreter-05e11c15.cjs.js');
|
|
5
5
|
|
|
6
6
|
function createSpawner(actorContext, {
|
|
7
7
|
machine,
|
|
@@ -19,7 +19,7 @@ function createSpawner(actorContext, {
|
|
|
19
19
|
const input = 'input' in options ? options.input : referenced.input;
|
|
20
20
|
|
|
21
21
|
// TODO: this should also receive `src`
|
|
22
|
-
const
|
|
22
|
+
const actorRef = interpreter.createActor(referenced.src, {
|
|
23
23
|
id: options.id,
|
|
24
24
|
parent: actorContext.self,
|
|
25
25
|
input: typeof input === 'function' ? input({
|
|
@@ -29,16 +29,48 @@ function createSpawner(actorContext, {
|
|
|
29
29
|
}) : input,
|
|
30
30
|
systemId
|
|
31
31
|
});
|
|
32
|
-
spawnedChildren[
|
|
33
|
-
|
|
32
|
+
spawnedChildren[actorRef.id] = actorRef;
|
|
33
|
+
if (options.syncSnapshot) {
|
|
34
|
+
actorRef.subscribe({
|
|
35
|
+
next: snapshot => {
|
|
36
|
+
if (snapshot.status === 'active') {
|
|
37
|
+
actorContext.self.send({
|
|
38
|
+
type: `xstate.snapshot.${actorRef.id}`,
|
|
39
|
+
snapshot
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
error: () => {
|
|
44
|
+
/* TODO */
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
return actorRef;
|
|
34
49
|
} else {
|
|
35
50
|
// TODO: this should also receive `src`
|
|
36
|
-
|
|
51
|
+
const actorRef = interpreter.createActor(src, {
|
|
37
52
|
id: options.id,
|
|
38
53
|
parent: actorContext.self,
|
|
39
54
|
input: options.input,
|
|
40
55
|
systemId
|
|
41
56
|
});
|
|
57
|
+
if (options.syncSnapshot) {
|
|
58
|
+
actorRef.subscribe({
|
|
59
|
+
next: snapshot => {
|
|
60
|
+
if (snapshot.status === 'active') {
|
|
61
|
+
actorContext.self.send({
|
|
62
|
+
type: `xstate.snapshot.${actorRef.id}`,
|
|
63
|
+
snapshot,
|
|
64
|
+
id: actorRef.id
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
error: () => {
|
|
69
|
+
/* TODO */
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
return actorRef;
|
|
42
74
|
}
|
|
43
75
|
};
|
|
44
76
|
return (src, options) => {
|
|
@@ -59,7 +91,7 @@ function createSpawner(actorContext, {
|
|
|
59
91
|
};
|
|
60
92
|
}
|
|
61
93
|
|
|
62
|
-
function
|
|
94
|
+
function resolveAssign(actorContext, state, actionArgs, {
|
|
63
95
|
assignment
|
|
64
96
|
}) {
|
|
65
97
|
if (!state.context) {
|
|
@@ -102,11 +134,11 @@ function assign(assignment) {
|
|
|
102
134
|
}
|
|
103
135
|
assign.type = 'xstate.assign';
|
|
104
136
|
assign.assignment = assignment;
|
|
105
|
-
assign.resolve =
|
|
137
|
+
assign.resolve = resolveAssign;
|
|
106
138
|
return assign;
|
|
107
139
|
}
|
|
108
140
|
|
|
109
|
-
function
|
|
141
|
+
function resolveChoose(_, state, actionArgs, {
|
|
110
142
|
branches
|
|
111
143
|
}) {
|
|
112
144
|
const matchedActions = branches.find(condition => {
|
|
@@ -119,11 +151,11 @@ function choose(branches) {
|
|
|
119
151
|
}
|
|
120
152
|
choose.type = 'xstate.choose';
|
|
121
153
|
choose.branches = branches;
|
|
122
|
-
choose.resolve =
|
|
154
|
+
choose.resolve = resolveChoose;
|
|
123
155
|
return choose;
|
|
124
156
|
}
|
|
125
157
|
|
|
126
|
-
function
|
|
158
|
+
function resolveLog(_, state, actionArgs, {
|
|
127
159
|
value,
|
|
128
160
|
label
|
|
129
161
|
}) {
|
|
@@ -132,7 +164,7 @@ function resolve$2(_, state, actionArgs, {
|
|
|
132
164
|
label
|
|
133
165
|
}];
|
|
134
166
|
}
|
|
135
|
-
function
|
|
167
|
+
function executeLog({
|
|
136
168
|
logger
|
|
137
169
|
}, {
|
|
138
170
|
value,
|
|
@@ -164,12 +196,12 @@ function log(value = ({
|
|
|
164
196
|
log.type = 'xstate.log';
|
|
165
197
|
log.value = value;
|
|
166
198
|
log.label = label;
|
|
167
|
-
log.resolve =
|
|
168
|
-
log.execute =
|
|
199
|
+
log.resolve = resolveLog;
|
|
200
|
+
log.execute = executeLog;
|
|
169
201
|
return log;
|
|
170
202
|
}
|
|
171
203
|
|
|
172
|
-
function
|
|
204
|
+
function resolvePure(_, state, args, {
|
|
173
205
|
get
|
|
174
206
|
}) {
|
|
175
207
|
return [state, undefined, interpreter.toArray(get({
|
|
@@ -182,7 +214,7 @@ function pure(getActions) {
|
|
|
182
214
|
}
|
|
183
215
|
pure.type = 'xstate.pure';
|
|
184
216
|
pure.get = getActions;
|
|
185
|
-
pure.resolve =
|
|
217
|
+
pure.resolve = resolvePure;
|
|
186
218
|
return pure;
|
|
187
219
|
}
|
|
188
220
|
|
|
@@ -221,7 +253,7 @@ let SpecialTargets = /*#__PURE__*/function (SpecialTargets) {
|
|
|
221
253
|
return SpecialTargets;
|
|
222
254
|
}({});
|
|
223
255
|
|
|
224
|
-
function
|
|
256
|
+
function resolveSendTo(actorContext, state, args, {
|
|
225
257
|
to,
|
|
226
258
|
event: eventOrExpr,
|
|
227
259
|
id,
|
|
@@ -266,7 +298,7 @@ function resolve(actorContext, state, args, {
|
|
|
266
298
|
delay: resolvedDelay
|
|
267
299
|
}];
|
|
268
300
|
}
|
|
269
|
-
function
|
|
301
|
+
function executeSendTo(actorContext, params) {
|
|
270
302
|
if (typeof params.delay === 'number') {
|
|
271
303
|
actorContext.self.delaySend(params);
|
|
272
304
|
return;
|
|
@@ -296,8 +328,8 @@ function sendTo(to, eventOrExpr, options) {
|
|
|
296
328
|
sendTo.event = eventOrExpr;
|
|
297
329
|
sendTo.id = options?.id;
|
|
298
330
|
sendTo.delay = options?.delay;
|
|
299
|
-
sendTo.resolve =
|
|
300
|
-
sendTo.execute =
|
|
331
|
+
sendTo.resolve = resolveSendTo;
|
|
332
|
+
sendTo.execute = executeSendTo;
|
|
301
333
|
return sendTo;
|
|
302
334
|
}
|
|
303
335
|
|