xstate 5.0.0-beta.44 → 5.0.0-beta.46
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 -2
- package/actions/dist/xstate-actions.development.cjs.js +2 -2
- package/actions/dist/xstate-actions.development.esm.js +2 -2
- package/actions/dist/xstate-actions.esm.js +2 -2
- package/actions/dist/xstate-actions.umd.min.js +1 -1
- package/actions/dist/xstate-actions.umd.min.js.map +1 -1
- package/actors/dist/xstate-actors.cjs.js +134 -9
- package/actors/dist/xstate-actors.development.cjs.js +134 -9
- package/actors/dist/xstate-actors.development.esm.js +134 -9
- package/actors/dist/xstate-actors.esm.js +134 -9
- 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 +18 -28
- package/dist/declarations/src/StateMachine.d.ts +11 -29
- package/dist/declarations/src/StateNode.d.ts +8 -6
- package/dist/declarations/src/actions/choose.d.ts +3 -3
- package/dist/declarations/src/actions/pure.d.ts +4 -4
- package/dist/declarations/src/actors/observable.d.ts +80 -4
- package/dist/declarations/src/actors/transition.d.ts +53 -4
- package/dist/declarations/src/createMachine.d.ts +5 -0
- package/dist/declarations/src/guards.d.ts +26 -4
- package/dist/declarations/src/index.d.ts +3 -2
- package/dist/declarations/src/interpreter.d.ts +1 -0
- package/dist/declarations/src/setup.d.ts +35 -0
- package/dist/declarations/src/stateUtils.d.ts +7 -7
- package/dist/declarations/src/types.d.ts +54 -25
- package/dist/declarations/src/utils.d.ts +2 -1
- package/dist/{raise-5854eaca.esm.js → raise-1682abb7.esm.js} +99 -135
- package/dist/{raise-fb6f017b.cjs.js → raise-a1d3d7e9.cjs.js} +100 -136
- package/dist/{raise-ed700d14.development.cjs.js → raise-a9e7e31c.development.cjs.js} +100 -136
- package/dist/{raise-348cc74e.development.esm.js → raise-fa23c2b9.development.esm.js} +99 -135
- package/dist/{send-53e5693c.cjs.js → send-2fa3a204.cjs.js} +24 -28
- package/dist/{send-00466e37.development.cjs.js → send-5b256a89.development.cjs.js} +24 -28
- package/dist/{send-a0193bdb.development.esm.js → send-9acdf858.development.esm.js} +24 -28
- package/dist/{send-b7b4befa.esm.js → send-a237e4e8.esm.js} +24 -28
- package/dist/xstate.cjs.js +102 -92
- package/dist/xstate.cjs.mjs +2 -0
- package/dist/xstate.development.cjs.js +102 -92
- package/dist/xstate.development.cjs.mjs +2 -0
- package/dist/xstate.development.esm.js +97 -89
- package/dist/xstate.esm.js +97 -89
- 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 +1 -1
- package/guards/dist/xstate-guards.umd.min.js.map +1 -1
- package/package.json +1 -1
- package/dist/declarations/src/Machine.d.ts +0 -5
|
@@ -319,6 +319,9 @@ function resolveReferencedActor(machine, src) {
|
|
|
319
319
|
}
|
|
320
320
|
return machine.implementations.actors[src];
|
|
321
321
|
}
|
|
322
|
+
function getAllOwnEventDescriptors(snapshot) {
|
|
323
|
+
return [...new Set(flatten([...snapshot._nodes.map(sn => sn.ownEvents)]))];
|
|
324
|
+
}
|
|
322
325
|
|
|
323
326
|
const $$ACTOR_TYPE = 1;
|
|
324
327
|
// those values are currently used by @xstate/react directly so it's important to keep the assigned values in sync
|
|
@@ -345,32 +348,6 @@ const defaultOptions = {
|
|
|
345
348
|
* An Actor is a running process that can receive events, send events and change its behavior based on the events it receives, which can cause effects outside of the actor. When you run a state machine, it becomes an actor.
|
|
346
349
|
*/
|
|
347
350
|
class Actor {
|
|
348
|
-
/**
|
|
349
|
-
* The current internal state of the actor.
|
|
350
|
-
*/
|
|
351
|
-
|
|
352
|
-
/**
|
|
353
|
-
* The clock that is responsible for setting and clearing timeouts, such as delayed events and transitions.
|
|
354
|
-
*/
|
|
355
|
-
|
|
356
|
-
/**
|
|
357
|
-
* The unique identifier for this actor relative to its parent.
|
|
358
|
-
*/
|
|
359
|
-
|
|
360
|
-
/** @internal */
|
|
361
|
-
|
|
362
|
-
// Actor Ref
|
|
363
|
-
|
|
364
|
-
// TODO: add typings for system
|
|
365
|
-
|
|
366
|
-
/**
|
|
367
|
-
* The globally unique process ID for this invocation.
|
|
368
|
-
*/
|
|
369
|
-
|
|
370
|
-
/**
|
|
371
|
-
* The system to which this actor belongs.
|
|
372
|
-
*/
|
|
373
|
-
|
|
374
351
|
/**
|
|
375
352
|
* Creates a new actor instance for the given logic with the provided options, if any.
|
|
376
353
|
*
|
|
@@ -379,23 +356,43 @@ class Actor {
|
|
|
379
356
|
*/
|
|
380
357
|
constructor(logic, options) {
|
|
381
358
|
this.logic = logic;
|
|
359
|
+
/**
|
|
360
|
+
* The current internal state of the actor.
|
|
361
|
+
*/
|
|
382
362
|
this._state = void 0;
|
|
363
|
+
/**
|
|
364
|
+
* The clock that is responsible for setting and clearing timeouts, such as delayed events and transitions.
|
|
365
|
+
*/
|
|
383
366
|
this.clock = void 0;
|
|
384
367
|
this.options = void 0;
|
|
368
|
+
/**
|
|
369
|
+
* The unique identifier for this actor relative to its parent.
|
|
370
|
+
*/
|
|
385
371
|
this.id = void 0;
|
|
386
372
|
this.mailbox = new Mailbox(this._process.bind(this));
|
|
387
373
|
this.delayedEventsMap = {};
|
|
388
374
|
this.observers = new Set();
|
|
389
375
|
this.logger = void 0;
|
|
376
|
+
/** @internal */
|
|
390
377
|
this._processingStatus = ProcessingStatus.NotStarted;
|
|
378
|
+
// Actor Ref
|
|
391
379
|
this._parent = void 0;
|
|
380
|
+
this._syncSnapshot = void 0;
|
|
392
381
|
this.ref = void 0;
|
|
382
|
+
// TODO: add typings for system
|
|
393
383
|
this._actorScope = void 0;
|
|
394
384
|
this._systemId = void 0;
|
|
385
|
+
/**
|
|
386
|
+
* The globally unique process ID for this invocation.
|
|
387
|
+
*/
|
|
395
388
|
this.sessionId = void 0;
|
|
389
|
+
/**
|
|
390
|
+
* The system to which this actor belongs.
|
|
391
|
+
*/
|
|
396
392
|
this.system = void 0;
|
|
397
393
|
this._doneEvent = void 0;
|
|
398
394
|
this.src = void 0;
|
|
395
|
+
// array of functions to defer
|
|
399
396
|
this._deferred = [];
|
|
400
397
|
const resolvedOptions = {
|
|
401
398
|
...defaultOptions,
|
|
@@ -405,6 +402,7 @@ class Actor {
|
|
|
405
402
|
clock,
|
|
406
403
|
logger,
|
|
407
404
|
parent,
|
|
405
|
+
syncSnapshot,
|
|
408
406
|
id,
|
|
409
407
|
systemId,
|
|
410
408
|
inspect
|
|
@@ -419,6 +417,7 @@ class Actor {
|
|
|
419
417
|
this.logger = logger;
|
|
420
418
|
this.clock = clock;
|
|
421
419
|
this._parent = parent;
|
|
420
|
+
this._syncSnapshot = syncSnapshot;
|
|
422
421
|
this.options = resolvedOptions;
|
|
423
422
|
this.src = resolvedOptions.src ?? logic;
|
|
424
423
|
this.ref = this;
|
|
@@ -458,9 +457,6 @@ class Actor {
|
|
|
458
457
|
_initState(persistedState) {
|
|
459
458
|
this._state = persistedState ? this.logic.restoreState ? this.logic.restoreState(persistedState, this._actorScope) : persistedState : this.logic.getInitialState(this._actorScope, this.options?.input);
|
|
460
459
|
}
|
|
461
|
-
|
|
462
|
-
// array of functions to defer
|
|
463
|
-
|
|
464
460
|
update(snapshot, event) {
|
|
465
461
|
// Update state
|
|
466
462
|
this._state = snapshot;
|
|
@@ -577,6 +573,19 @@ class Actor {
|
|
|
577
573
|
// Do not restart the service if it is already started
|
|
578
574
|
return this;
|
|
579
575
|
}
|
|
576
|
+
if (this._syncSnapshot) {
|
|
577
|
+
this.subscribe({
|
|
578
|
+
next: snapshot => {
|
|
579
|
+
if (snapshot.status === 'active') {
|
|
580
|
+
this._parent.send({
|
|
581
|
+
type: `xstate.snapshot.${this.id}`,
|
|
582
|
+
snapshot
|
|
583
|
+
});
|
|
584
|
+
}
|
|
585
|
+
},
|
|
586
|
+
error: () => {}
|
|
587
|
+
});
|
|
588
|
+
}
|
|
580
589
|
this.system._register(this.sessionId, this);
|
|
581
590
|
if (this._systemId) {
|
|
582
591
|
this.system._set(this._systemId, this);
|
|
@@ -862,20 +871,6 @@ const interpret = createActor;
|
|
|
862
871
|
* @deprecated Use `Actor` instead.
|
|
863
872
|
*/
|
|
864
873
|
|
|
865
|
-
const cache = new WeakMap();
|
|
866
|
-
function memo(object, key, fn) {
|
|
867
|
-
let memoizedData = cache.get(object);
|
|
868
|
-
if (!memoizedData) {
|
|
869
|
-
memoizedData = {
|
|
870
|
-
[key]: fn()
|
|
871
|
-
};
|
|
872
|
-
cache.set(object, memoizedData);
|
|
873
|
-
} else if (!(key in memoizedData)) {
|
|
874
|
-
memoizedData[key] = fn();
|
|
875
|
-
}
|
|
876
|
-
return memoizedData[key];
|
|
877
|
-
}
|
|
878
|
-
|
|
879
874
|
function resolveCancel(_, state, actionArgs, actionParams, {
|
|
880
875
|
sendId
|
|
881
876
|
}) {
|
|
@@ -920,6 +915,7 @@ function resolveSpawn(actorScope, state, actionArgs, _actionParams, {
|
|
|
920
915
|
id: resolvedId,
|
|
921
916
|
src,
|
|
922
917
|
parent: actorScope?.self,
|
|
918
|
+
syncSnapshot,
|
|
923
919
|
systemId,
|
|
924
920
|
input: typeof input === 'function' ? input({
|
|
925
921
|
context: state.context,
|
|
@@ -927,19 +923,6 @@ function resolveSpawn(actorScope, state, actionArgs, _actionParams, {
|
|
|
927
923
|
self: actorScope?.self
|
|
928
924
|
}) : input
|
|
929
925
|
});
|
|
930
|
-
if (syncSnapshot) {
|
|
931
|
-
actorRef.subscribe({
|
|
932
|
-
next: snapshot => {
|
|
933
|
-
if (snapshot.status === 'active') {
|
|
934
|
-
actorScope.self.send({
|
|
935
|
-
type: `xstate.snapshot.${id}`,
|
|
936
|
-
snapshot
|
|
937
|
-
});
|
|
938
|
-
}
|
|
939
|
-
},
|
|
940
|
-
error: () => {}
|
|
941
|
-
});
|
|
942
|
-
}
|
|
943
926
|
}
|
|
944
927
|
if (!actorRef) {
|
|
945
928
|
console.warn(`Actor type '${src}' not found in machine '${actorScope.id}'.`);
|
|
@@ -1058,7 +1041,7 @@ function checkStateIn(state, _, {
|
|
|
1058
1041
|
}) {
|
|
1059
1042
|
if (typeof stateValue === 'string' && isStateId(stateValue)) {
|
|
1060
1043
|
const target = state.machine.getStateNodeById(stateValue);
|
|
1061
|
-
return state.
|
|
1044
|
+
return state._nodes.some(sn => sn === target);
|
|
1062
1045
|
}
|
|
1063
1046
|
return state.matches(stateValue);
|
|
1064
1047
|
}
|
|
@@ -1177,26 +1160,25 @@ function getProperAncestors(stateNode, toStateNode) {
|
|
|
1177
1160
|
}
|
|
1178
1161
|
return ancestors;
|
|
1179
1162
|
}
|
|
1180
|
-
function
|
|
1181
|
-
const
|
|
1182
|
-
const
|
|
1183
|
-
const adjList = getAdjList(configurationSet);
|
|
1163
|
+
function getAllStateNodes(stateNodes) {
|
|
1164
|
+
const nodeSet = new Set(stateNodes);
|
|
1165
|
+
const adjList = getAdjList(nodeSet);
|
|
1184
1166
|
|
|
1185
1167
|
// add descendants
|
|
1186
|
-
for (const s of
|
|
1168
|
+
for (const s of nodeSet) {
|
|
1187
1169
|
// if previously active, add existing child nodes
|
|
1188
1170
|
if (s.type === 'compound' && (!adjList.get(s) || !adjList.get(s).length)) {
|
|
1189
|
-
getInitialStateNodesWithTheirAncestors(s).forEach(sn =>
|
|
1171
|
+
getInitialStateNodesWithTheirAncestors(s).forEach(sn => nodeSet.add(sn));
|
|
1190
1172
|
} else {
|
|
1191
1173
|
if (s.type === 'parallel') {
|
|
1192
1174
|
for (const child of getChildren(s)) {
|
|
1193
1175
|
if (child.type === 'history') {
|
|
1194
1176
|
continue;
|
|
1195
1177
|
}
|
|
1196
|
-
if (!
|
|
1178
|
+
if (!nodeSet.has(child)) {
|
|
1197
1179
|
const initialStates = getInitialStateNodesWithTheirAncestors(child);
|
|
1198
1180
|
for (const initialStateNode of initialStates) {
|
|
1199
|
-
|
|
1181
|
+
nodeSet.add(initialStateNode);
|
|
1200
1182
|
}
|
|
1201
1183
|
}
|
|
1202
1184
|
}
|
|
@@ -1205,14 +1187,14 @@ function getConfiguration(stateNodes) {
|
|
|
1205
1187
|
}
|
|
1206
1188
|
|
|
1207
1189
|
// add all ancestors
|
|
1208
|
-
for (const s of
|
|
1190
|
+
for (const s of nodeSet) {
|
|
1209
1191
|
let m = s.parent;
|
|
1210
1192
|
while (m) {
|
|
1211
|
-
|
|
1193
|
+
nodeSet.add(m);
|
|
1212
1194
|
m = m.parent;
|
|
1213
1195
|
}
|
|
1214
1196
|
}
|
|
1215
|
-
return
|
|
1197
|
+
return nodeSet;
|
|
1216
1198
|
}
|
|
1217
1199
|
function getValueFromAdj(baseNode, adjList) {
|
|
1218
1200
|
const childStateNodes = adjList.get(baseNode);
|
|
@@ -1236,9 +1218,9 @@ function getValueFromAdj(baseNode, adjList) {
|
|
|
1236
1218
|
}
|
|
1237
1219
|
return stateValue;
|
|
1238
1220
|
}
|
|
1239
|
-
function getAdjList(
|
|
1221
|
+
function getAdjList(stateNodes) {
|
|
1240
1222
|
const adjList = new Map();
|
|
1241
|
-
for (const s of
|
|
1223
|
+
for (const s of stateNodes) {
|
|
1242
1224
|
if (!adjList.has(s)) {
|
|
1243
1225
|
adjList.set(s, []);
|
|
1244
1226
|
}
|
|
@@ -1251,16 +1233,16 @@ function getAdjList(configuration) {
|
|
|
1251
1233
|
}
|
|
1252
1234
|
return adjList;
|
|
1253
1235
|
}
|
|
1254
|
-
function getStateValue(rootNode,
|
|
1255
|
-
const config =
|
|
1236
|
+
function getStateValue(rootNode, stateNodes) {
|
|
1237
|
+
const config = getAllStateNodes(stateNodes);
|
|
1256
1238
|
return getValueFromAdj(rootNode, getAdjList(config));
|
|
1257
1239
|
}
|
|
1258
|
-
function isInFinalState(
|
|
1240
|
+
function isInFinalState(stateNodeSet, stateNode) {
|
|
1259
1241
|
if (stateNode.type === 'compound') {
|
|
1260
|
-
return getChildren(stateNode).some(s => s.type === 'final' &&
|
|
1242
|
+
return getChildren(stateNode).some(s => s.type === 'final' && stateNodeSet.has(s));
|
|
1261
1243
|
}
|
|
1262
1244
|
if (stateNode.type === 'parallel') {
|
|
1263
|
-
return getChildren(stateNode).every(sn => isInFinalState(
|
|
1245
|
+
return getChildren(stateNode).every(sn => isInFinalState(stateNodeSet, sn));
|
|
1264
1246
|
}
|
|
1265
1247
|
return stateNode.type === 'final';
|
|
1266
1248
|
}
|
|
@@ -1631,13 +1613,13 @@ function hasIntersection(s1, s2) {
|
|
|
1631
1613
|
}
|
|
1632
1614
|
return false;
|
|
1633
1615
|
}
|
|
1634
|
-
function removeConflictingTransitions(enabledTransitions,
|
|
1616
|
+
function removeConflictingTransitions(enabledTransitions, stateNodeSet, historyValue) {
|
|
1635
1617
|
const filteredTransitions = new Set();
|
|
1636
1618
|
for (const t1 of enabledTransitions) {
|
|
1637
1619
|
let t1Preempted = false;
|
|
1638
1620
|
const transitionsToRemove = new Set();
|
|
1639
1621
|
for (const t2 of filteredTransitions) {
|
|
1640
|
-
if (hasIntersection(computeExitSet([t1],
|
|
1622
|
+
if (hasIntersection(computeExitSet([t1], stateNodeSet, historyValue), computeExitSet([t2], stateNodeSet, historyValue))) {
|
|
1641
1623
|
if (isDescendant(t1.source, t2.source)) {
|
|
1642
1624
|
transitionsToRemove.add(t2);
|
|
1643
1625
|
} else {
|
|
@@ -1704,7 +1686,7 @@ function getTransitionDomain(transition, historyValue) {
|
|
|
1704
1686
|
}
|
|
1705
1687
|
return transition.source.machine.root;
|
|
1706
1688
|
}
|
|
1707
|
-
function computeExitSet(transitions,
|
|
1689
|
+
function computeExitSet(transitions, stateNodeSet, historyValue) {
|
|
1708
1690
|
const statesToExit = new Set();
|
|
1709
1691
|
for (const t of transitions) {
|
|
1710
1692
|
if (t.target?.length) {
|
|
@@ -1712,7 +1694,7 @@ function computeExitSet(transitions, configuration, historyValue) {
|
|
|
1712
1694
|
if (t.reenter && t.source === domain) {
|
|
1713
1695
|
statesToExit.add(domain);
|
|
1714
1696
|
}
|
|
1715
|
-
for (const stateNode of
|
|
1697
|
+
for (const stateNode of stateNodeSet) {
|
|
1716
1698
|
if (isDescendant(stateNode, domain)) {
|
|
1717
1699
|
statesToExit.add(stateNode);
|
|
1718
1700
|
}
|
|
@@ -1721,12 +1703,12 @@ function computeExitSet(transitions, configuration, historyValue) {
|
|
|
1721
1703
|
}
|
|
1722
1704
|
return [...statesToExit];
|
|
1723
1705
|
}
|
|
1724
|
-
function
|
|
1725
|
-
if (
|
|
1706
|
+
function areStateNodeCollectionsEqual(prevStateNodes, nextStateNodeSet) {
|
|
1707
|
+
if (prevStateNodes.length !== nextStateNodeSet.size) {
|
|
1726
1708
|
return false;
|
|
1727
1709
|
}
|
|
1728
|
-
for (const node of
|
|
1729
|
-
if (!
|
|
1710
|
+
for (const node of prevStateNodes) {
|
|
1711
|
+
if (!nextStateNodeSet.has(node)) {
|
|
1730
1712
|
return false;
|
|
1731
1713
|
}
|
|
1732
1714
|
}
|
|
@@ -1740,31 +1722,31 @@ function microstep(transitions, currentState, actorScope, event, isInitial, inte
|
|
|
1740
1722
|
if (!transitions.length) {
|
|
1741
1723
|
return currentState;
|
|
1742
1724
|
}
|
|
1743
|
-
const
|
|
1725
|
+
const mutStateNodeSet = new Set(currentState._nodes);
|
|
1744
1726
|
let historyValue = currentState.historyValue;
|
|
1745
|
-
const filteredTransitions = removeConflictingTransitions(transitions,
|
|
1727
|
+
const filteredTransitions = removeConflictingTransitions(transitions, mutStateNodeSet, historyValue);
|
|
1746
1728
|
let nextState = currentState;
|
|
1747
1729
|
|
|
1748
1730
|
// Exit states
|
|
1749
1731
|
if (!isInitial) {
|
|
1750
|
-
[nextState, historyValue] = exitStates(nextState, event, actorScope, filteredTransitions,
|
|
1732
|
+
[nextState, historyValue] = exitStates(nextState, event, actorScope, filteredTransitions, mutStateNodeSet, historyValue, internalQueue);
|
|
1751
1733
|
}
|
|
1752
1734
|
|
|
1753
1735
|
// Execute transition content
|
|
1754
1736
|
nextState = resolveActionsAndContext(nextState, event, actorScope, filteredTransitions.flatMap(t => t.actions), internalQueue);
|
|
1755
1737
|
|
|
1756
1738
|
// Enter states
|
|
1757
|
-
nextState = enterStates(nextState, event, actorScope, filteredTransitions,
|
|
1758
|
-
const
|
|
1739
|
+
nextState = enterStates(nextState, event, actorScope, filteredTransitions, mutStateNodeSet, internalQueue, historyValue, isInitial);
|
|
1740
|
+
const nextStateNodes = [...mutStateNodeSet];
|
|
1759
1741
|
if (nextState.status === 'done') {
|
|
1760
|
-
nextState = resolveActionsAndContext(nextState, event, actorScope,
|
|
1742
|
+
nextState = resolveActionsAndContext(nextState, event, actorScope, nextStateNodes.sort((a, b) => b.order - a.order).flatMap(state => state.exit), internalQueue);
|
|
1761
1743
|
}
|
|
1762
1744
|
try {
|
|
1763
|
-
if (historyValue === currentState.historyValue &&
|
|
1745
|
+
if (historyValue === currentState.historyValue && areStateNodeCollectionsEqual(currentState._nodes, mutStateNodeSet)) {
|
|
1764
1746
|
return nextState;
|
|
1765
1747
|
}
|
|
1766
1748
|
return cloneMachineSnapshot(nextState, {
|
|
1767
|
-
|
|
1749
|
+
_nodes: nextStateNodes,
|
|
1768
1750
|
historyValue
|
|
1769
1751
|
});
|
|
1770
1752
|
} catch (e) {
|
|
@@ -1780,7 +1762,7 @@ function getMachineOutput(state, event, actorScope, rootNode, rootCompletionNode
|
|
|
1780
1762
|
const doneStateEvent = createDoneStateEvent(rootCompletionNode.id, rootCompletionNode.output && rootCompletionNode.parent ? resolveOutput(rootCompletionNode.output, state.context, event, actorScope.self) : undefined);
|
|
1781
1763
|
return resolveOutput(rootNode.output, state.context, doneStateEvent, actorScope.self);
|
|
1782
1764
|
}
|
|
1783
|
-
function enterStates(currentState, event, actorScope, filteredTransitions,
|
|
1765
|
+
function enterStates(currentState, event, actorScope, filteredTransitions, mutStateNodeSet, internalQueue, historyValue, isInitial) {
|
|
1784
1766
|
let nextState = currentState;
|
|
1785
1767
|
const statesToEnter = new Set();
|
|
1786
1768
|
// those are states that were directly targeted or indirectly targeted by the explicit target
|
|
@@ -1795,7 +1777,7 @@ function enterStates(currentState, event, actorScope, filteredTransitions, mutCo
|
|
|
1795
1777
|
}
|
|
1796
1778
|
const completedNodes = new Set();
|
|
1797
1779
|
for (const stateNodeToEnter of [...statesToEnter].sort((a, b) => a.order - b.order)) {
|
|
1798
|
-
|
|
1780
|
+
mutStateNodeSet.add(stateNodeToEnter);
|
|
1799
1781
|
const actions = [];
|
|
1800
1782
|
|
|
1801
1783
|
// Add entry actions
|
|
@@ -1818,7 +1800,7 @@ function enterStates(currentState, event, actorScope, filteredTransitions, mutCo
|
|
|
1818
1800
|
if (parent?.type === 'compound') {
|
|
1819
1801
|
internalQueue.push(createDoneStateEvent(parent.id, stateNodeToEnter.output ? resolveOutput(stateNodeToEnter.output, nextState.context, event, actorScope.self) : undefined));
|
|
1820
1802
|
}
|
|
1821
|
-
while (ancestorMarker?.type === 'parallel' && !completedNodes.has(ancestorMarker) && isInFinalState(
|
|
1803
|
+
while (ancestorMarker?.type === 'parallel' && !completedNodes.has(ancestorMarker) && isInFinalState(mutStateNodeSet, ancestorMarker)) {
|
|
1822
1804
|
completedNodes.add(ancestorMarker);
|
|
1823
1805
|
internalQueue.push(createDoneStateEvent(ancestorMarker.id));
|
|
1824
1806
|
rootCompletionNode = ancestorMarker;
|
|
@@ -1928,9 +1910,9 @@ function addAncestorStatesToEnter(statesToEnter, historyValue, statesForDefaultE
|
|
|
1928
1910
|
function addProperAncestorStatesToEnter(stateNode, toStateNode, statesToEnter, historyValue, statesForDefaultEntry) {
|
|
1929
1911
|
addAncestorStatesToEnter(statesToEnter, historyValue, statesForDefaultEntry, getProperAncestors(stateNode, toStateNode));
|
|
1930
1912
|
}
|
|
1931
|
-
function exitStates(currentState, event, actorScope, transitions,
|
|
1913
|
+
function exitStates(currentState, event, actorScope, transitions, mutStateNodeSet, historyValue, internalQueue) {
|
|
1932
1914
|
let nextState = currentState;
|
|
1933
|
-
const statesToExit = computeExitSet(transitions,
|
|
1915
|
+
const statesToExit = computeExitSet(transitions, mutStateNodeSet, historyValue);
|
|
1934
1916
|
statesToExit.sort((a, b) => b.order - a.order);
|
|
1935
1917
|
let changedHistory;
|
|
1936
1918
|
|
|
@@ -1948,12 +1930,12 @@ function exitStates(currentState, event, actorScope, transitions, mutConfigurati
|
|
|
1948
1930
|
changedHistory ??= {
|
|
1949
1931
|
...historyValue
|
|
1950
1932
|
};
|
|
1951
|
-
changedHistory[historyNode.id] = Array.from(
|
|
1933
|
+
changedHistory[historyNode.id] = Array.from(mutStateNodeSet).filter(predicate);
|
|
1952
1934
|
}
|
|
1953
1935
|
}
|
|
1954
1936
|
for (const s of statesToExit) {
|
|
1955
1937
|
nextState = resolveActionsAndContext(nextState, event, actorScope, [...s.exit, ...s.invoke.map(def => stop(def.id))], internalQueue);
|
|
1956
|
-
|
|
1938
|
+
mutStateNodeSet.delete(s);
|
|
1957
1939
|
}
|
|
1958
1940
|
return [nextState, changedHistory || historyValue];
|
|
1959
1941
|
}
|
|
@@ -2085,7 +2067,7 @@ function selectTransitions(event, nextState) {
|
|
|
2085
2067
|
}
|
|
2086
2068
|
function selectEventlessTransitions(nextState, event) {
|
|
2087
2069
|
const enabledTransitionSet = new Set();
|
|
2088
|
-
const atomicStates = nextState.
|
|
2070
|
+
const atomicStates = nextState._nodes.filter(isAtomicStateNode);
|
|
2089
2071
|
for (const stateNode of atomicStates) {
|
|
2090
2072
|
loop: for (const s of [stateNode].concat(getProperAncestors(stateNode, undefined))) {
|
|
2091
2073
|
if (!s.always) {
|
|
@@ -2099,7 +2081,7 @@ function selectEventlessTransitions(nextState, event) {
|
|
|
2099
2081
|
}
|
|
2100
2082
|
}
|
|
2101
2083
|
}
|
|
2102
|
-
return removeConflictingTransitions(Array.from(enabledTransitionSet), new Set(nextState.
|
|
2084
|
+
return removeConflictingTransitions(Array.from(enabledTransitionSet), new Set(nextState._nodes), nextState.historyValue);
|
|
2103
2085
|
}
|
|
2104
2086
|
|
|
2105
2087
|
/**
|
|
@@ -2108,8 +2090,8 @@ function selectEventlessTransitions(nextState, event) {
|
|
|
2108
2090
|
* @param stateValue The partial state value to resolve.
|
|
2109
2091
|
*/
|
|
2110
2092
|
function resolveStateValue(rootNode, stateValue) {
|
|
2111
|
-
const
|
|
2112
|
-
return getStateValue(rootNode, [...
|
|
2093
|
+
const allStateNodes = getAllStateNodes(getStateNodes(rootNode, stateValue));
|
|
2094
|
+
return getStateValue(rootNode, [...allStateNodes]);
|
|
2113
2095
|
}
|
|
2114
2096
|
|
|
2115
2097
|
function isMachineSnapshot(value) {
|
|
@@ -2132,10 +2114,10 @@ const machineSnapshotCan = function can(event) {
|
|
|
2132
2114
|
};
|
|
2133
2115
|
const machineSnapshotToJSON = function toJSON() {
|
|
2134
2116
|
const {
|
|
2135
|
-
|
|
2117
|
+
_nodes: nodes,
|
|
2136
2118
|
tags,
|
|
2137
2119
|
machine,
|
|
2138
|
-
|
|
2120
|
+
getMeta,
|
|
2139
2121
|
toJSON,
|
|
2140
2122
|
can,
|
|
2141
2123
|
hasTag,
|
|
@@ -2147,13 +2129,8 @@ const machineSnapshotToJSON = function toJSON() {
|
|
|
2147
2129
|
tags: Array.from(tags)
|
|
2148
2130
|
};
|
|
2149
2131
|
};
|
|
2150
|
-
const
|
|
2151
|
-
return
|
|
2152
|
-
return [...new Set(flatten([...this.configuration.map(sn => sn.ownEvents)]))];
|
|
2153
|
-
});
|
|
2154
|
-
};
|
|
2155
|
-
const machineSnapshotMeta = function nextEvents() {
|
|
2156
|
-
return this.configuration.reduce((acc, stateNode) => {
|
|
2132
|
+
const machineSnapshotGetMeta = function getMeta() {
|
|
2133
|
+
return this._nodes.reduce((acc, stateNode) => {
|
|
2157
2134
|
if (stateNode.meta !== undefined) {
|
|
2158
2135
|
acc[stateNode.id] = stateNode.meta;
|
|
2159
2136
|
}
|
|
@@ -2161,48 +2138,34 @@ const machineSnapshotMeta = function nextEvents() {
|
|
|
2161
2138
|
}, {});
|
|
2162
2139
|
};
|
|
2163
2140
|
function createMachineSnapshot(config, machine) {
|
|
2164
|
-
|
|
2141
|
+
return {
|
|
2165
2142
|
status: config.status,
|
|
2166
2143
|
output: config.output,
|
|
2167
2144
|
error: config.error,
|
|
2168
2145
|
machine,
|
|
2169
2146
|
context: config.context,
|
|
2170
|
-
|
|
2171
|
-
value: getStateValue(machine.root, config.
|
|
2172
|
-
tags: new Set(flatten(config.
|
|
2147
|
+
_nodes: config._nodes,
|
|
2148
|
+
value: getStateValue(machine.root, config._nodes),
|
|
2149
|
+
tags: new Set(flatten(config._nodes.map(sn => sn.tags))),
|
|
2173
2150
|
children: config.children,
|
|
2174
2151
|
historyValue: config.historyValue || {},
|
|
2175
2152
|
// this one is generic in the target and it's hard to create a matching non-generic source signature
|
|
2176
2153
|
matches: machineSnapshotMatches,
|
|
2177
2154
|
hasTag: machineSnapshotHasTag,
|
|
2178
2155
|
can: machineSnapshotCan,
|
|
2156
|
+
getMeta: machineSnapshotGetMeta,
|
|
2179
2157
|
toJSON: machineSnapshotToJSON
|
|
2180
2158
|
};
|
|
2181
|
-
Object.defineProperties(snapshot, {
|
|
2182
|
-
nextEvents: {
|
|
2183
|
-
get: machineSnapshotNextEvents,
|
|
2184
|
-
configurable: true,
|
|
2185
|
-
enumerable: true
|
|
2186
|
-
},
|
|
2187
|
-
meta: {
|
|
2188
|
-
get: machineSnapshotMeta,
|
|
2189
|
-
configurable: true,
|
|
2190
|
-
enumerable: true
|
|
2191
|
-
}
|
|
2192
|
-
});
|
|
2193
|
-
return snapshot;
|
|
2194
2159
|
}
|
|
2195
2160
|
function cloneMachineSnapshot(state, config = {}) {
|
|
2196
|
-
return createMachineSnapshot(
|
|
2197
|
-
// TODO: it's wasteful that this spread triggers getters
|
|
2198
|
-
{
|
|
2161
|
+
return createMachineSnapshot({
|
|
2199
2162
|
...state,
|
|
2200
2163
|
...config
|
|
2201
2164
|
}, state.machine);
|
|
2202
2165
|
}
|
|
2203
2166
|
function getPersistedState(state, options) {
|
|
2204
2167
|
const {
|
|
2205
|
-
|
|
2168
|
+
_nodes: nodes,
|
|
2206
2169
|
tags,
|
|
2207
2170
|
machine,
|
|
2208
2171
|
children,
|
|
@@ -2210,8 +2173,8 @@ function getPersistedState(state, options) {
|
|
|
2210
2173
|
can,
|
|
2211
2174
|
hasTag,
|
|
2212
2175
|
matches,
|
|
2176
|
+
getMeta,
|
|
2213
2177
|
toJSON,
|
|
2214
|
-
nextEvents,
|
|
2215
2178
|
...jsonValues
|
|
2216
2179
|
} = state;
|
|
2217
2180
|
const childrenJson = {};
|
|
@@ -2223,7 +2186,8 @@ function getPersistedState(state, options) {
|
|
|
2223
2186
|
childrenJson[id] = {
|
|
2224
2187
|
state: child.getPersistedState(options),
|
|
2225
2188
|
src: child.src,
|
|
2226
|
-
systemId: child._systemId
|
|
2189
|
+
systemId: child._systemId,
|
|
2190
|
+
syncSnapshot: child._syncSnapshot
|
|
2227
2191
|
};
|
|
2228
2192
|
}
|
|
2229
2193
|
const persisted = {
|
|
@@ -2315,4 +2279,4 @@ function raise(eventOrExpr, options) {
|
|
|
2315
2279
|
return raise;
|
|
2316
2280
|
}
|
|
2317
2281
|
|
|
2318
|
-
export { $$ACTOR_TYPE as $, getPersistedState as A, resolveReferencedActor as B, createActor as C, Actor as D, interpret as E, isMachineSnapshot as F, matchesState as G, pathToStateValue as H, toObserver as I, and as J, not as K, or as L, stateIn as M, NULL_EVENT as N, cancel as O, raise as P, stop as Q, spawn as R, STATE_DELIMITER as S, ProcessingStatus as T, createErrorActorEvent as U, XSTATE_ERROR as V, XSTATE_STOP as X, toTransitionConfigArray as a, formatTransition as b,
|
|
2282
|
+
export { $$ACTOR_TYPE as $, getPersistedState as A, resolveReferencedActor as B, createActor as C, Actor as D, interpret as E, isMachineSnapshot as F, matchesState as G, pathToStateValue as H, toObserver as I, and as J, not as K, or as L, stateIn as M, NULL_EVENT as N, cancel as O, raise as P, stop as Q, spawn as R, STATE_DELIMITER as S, ProcessingStatus as T, createErrorActorEvent as U, XSTATE_ERROR as V, XSTATE_STOP as X, toTransitionConfigArray as a, formatTransition as b, createInvokeId as c, formatInitialTransition as d, evaluateGuard as e, formatTransitions as f, getDelayedTransitions as g, getCandidates as h, getAllStateNodes as i, getStateNodes as j, createMachineSnapshot as k, isInFinalState as l, mapValues as m, isErrorActorEvent as n, getAllOwnEventDescriptors as o, cloneMachineSnapshot as p, macrostep as q, resolveStateValue as r, transitionNode as s, toArray as t, resolveActionsAndContext as u, createInitEvent as v, microstep as w, getInitialStateNodes as x, isStateId as y, getStateNodeByPath as z };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var guards_dist_xstateGuards = require('./raise-
|
|
3
|
+
var guards_dist_xstateGuards = require('./raise-a1d3d7e9.cjs.js');
|
|
4
4
|
|
|
5
5
|
function createSpawner(actorScope, {
|
|
6
6
|
machine,
|
|
@@ -19,6 +19,7 @@ function createSpawner(actorScope, {
|
|
|
19
19
|
const actorRef = guards_dist_xstateGuards.createActor(logic, {
|
|
20
20
|
id: options.id,
|
|
21
21
|
parent: actorScope.self,
|
|
22
|
+
syncSnapshot: options.syncSnapshot,
|
|
22
23
|
input: typeof input === 'function' ? input({
|
|
23
24
|
context,
|
|
24
25
|
event,
|
|
@@ -28,42 +29,16 @@ function createSpawner(actorScope, {
|
|
|
28
29
|
systemId
|
|
29
30
|
});
|
|
30
31
|
spawnedChildren[actorRef.id] = actorRef;
|
|
31
|
-
if (options.syncSnapshot) {
|
|
32
|
-
actorRef.subscribe({
|
|
33
|
-
next: snapshot => {
|
|
34
|
-
if (snapshot.status === 'active') {
|
|
35
|
-
actorScope.self.send({
|
|
36
|
-
type: `xstate.snapshot.${actorRef.id}`,
|
|
37
|
-
snapshot
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
},
|
|
41
|
-
error: () => {}
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
32
|
return actorRef;
|
|
45
33
|
} else {
|
|
46
34
|
const actorRef = guards_dist_xstateGuards.createActor(src, {
|
|
47
35
|
id: options.id,
|
|
48
36
|
parent: actorScope.self,
|
|
37
|
+
syncSnapshot: options.syncSnapshot,
|
|
49
38
|
input: options.input,
|
|
50
39
|
src,
|
|
51
40
|
systemId
|
|
52
41
|
});
|
|
53
|
-
if (options.syncSnapshot) {
|
|
54
|
-
actorRef.subscribe({
|
|
55
|
-
next: snapshot => {
|
|
56
|
-
if (snapshot.status === 'active') {
|
|
57
|
-
actorScope.self.send({
|
|
58
|
-
type: `xstate.snapshot.${actorRef.id}`,
|
|
59
|
-
snapshot,
|
|
60
|
-
id: actorRef.id
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
},
|
|
64
|
-
error: () => {}
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
42
|
return actorRef;
|
|
68
43
|
}
|
|
69
44
|
};
|
|
@@ -254,6 +229,27 @@ let SpecialTargets = /*#__PURE__*/function (SpecialTargets) {
|
|
|
254
229
|
return SpecialTargets;
|
|
255
230
|
}({});
|
|
256
231
|
|
|
232
|
+
/**
|
|
233
|
+
* @deprecated Use `AnyActor` instead.
|
|
234
|
+
*/
|
|
235
|
+
|
|
236
|
+
// Based on RxJS types
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* @deprecated Use `Actor<T>` instead.
|
|
240
|
+
*/
|
|
241
|
+
|
|
242
|
+
// only meant to be used internally for debugging purposes
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Represents logic which can be used by an actor.
|
|
246
|
+
*
|
|
247
|
+
* @template TSnapshot - The type of the snapshot.
|
|
248
|
+
* @template TEvent - The type of the event object.
|
|
249
|
+
* @template TInput - The type of the input.
|
|
250
|
+
* @template TSystem - The type of the actor system.
|
|
251
|
+
*/
|
|
252
|
+
|
|
257
253
|
function resolveSendTo(actorScope, state, args, actionParams, {
|
|
258
254
|
to,
|
|
259
255
|
event: eventOrExpr,
|