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
|
@@ -316,6 +316,9 @@ function resolveReferencedActor(machine, src) {
|
|
|
316
316
|
}
|
|
317
317
|
return machine.implementations.actors[src];
|
|
318
318
|
}
|
|
319
|
+
function getAllOwnEventDescriptors(snapshot) {
|
|
320
|
+
return [...new Set(flatten([...snapshot._nodes.map(sn => sn.ownEvents)]))];
|
|
321
|
+
}
|
|
319
322
|
|
|
320
323
|
const $$ACTOR_TYPE = 1;
|
|
321
324
|
// those values are currently used by @xstate/react directly so it's important to keep the assigned values in sync
|
|
@@ -342,32 +345,6 @@ const defaultOptions = {
|
|
|
342
345
|
* 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.
|
|
343
346
|
*/
|
|
344
347
|
class Actor {
|
|
345
|
-
/**
|
|
346
|
-
* The current internal state of the actor.
|
|
347
|
-
*/
|
|
348
|
-
|
|
349
|
-
/**
|
|
350
|
-
* The clock that is responsible for setting and clearing timeouts, such as delayed events and transitions.
|
|
351
|
-
*/
|
|
352
|
-
|
|
353
|
-
/**
|
|
354
|
-
* The unique identifier for this actor relative to its parent.
|
|
355
|
-
*/
|
|
356
|
-
|
|
357
|
-
/** @internal */
|
|
358
|
-
|
|
359
|
-
// Actor Ref
|
|
360
|
-
|
|
361
|
-
// TODO: add typings for system
|
|
362
|
-
|
|
363
|
-
/**
|
|
364
|
-
* The globally unique process ID for this invocation.
|
|
365
|
-
*/
|
|
366
|
-
|
|
367
|
-
/**
|
|
368
|
-
* The system to which this actor belongs.
|
|
369
|
-
*/
|
|
370
|
-
|
|
371
348
|
/**
|
|
372
349
|
* Creates a new actor instance for the given logic with the provided options, if any.
|
|
373
350
|
*
|
|
@@ -376,23 +353,43 @@ class Actor {
|
|
|
376
353
|
*/
|
|
377
354
|
constructor(logic, options) {
|
|
378
355
|
this.logic = logic;
|
|
356
|
+
/**
|
|
357
|
+
* The current internal state of the actor.
|
|
358
|
+
*/
|
|
379
359
|
this._state = void 0;
|
|
360
|
+
/**
|
|
361
|
+
* The clock that is responsible for setting and clearing timeouts, such as delayed events and transitions.
|
|
362
|
+
*/
|
|
380
363
|
this.clock = void 0;
|
|
381
364
|
this.options = void 0;
|
|
365
|
+
/**
|
|
366
|
+
* The unique identifier for this actor relative to its parent.
|
|
367
|
+
*/
|
|
382
368
|
this.id = void 0;
|
|
383
369
|
this.mailbox = new Mailbox(this._process.bind(this));
|
|
384
370
|
this.delayedEventsMap = {};
|
|
385
371
|
this.observers = new Set();
|
|
386
372
|
this.logger = void 0;
|
|
373
|
+
/** @internal */
|
|
387
374
|
this._processingStatus = ProcessingStatus.NotStarted;
|
|
375
|
+
// Actor Ref
|
|
388
376
|
this._parent = void 0;
|
|
377
|
+
this._syncSnapshot = void 0;
|
|
389
378
|
this.ref = void 0;
|
|
379
|
+
// TODO: add typings for system
|
|
390
380
|
this._actorScope = void 0;
|
|
391
381
|
this._systemId = void 0;
|
|
382
|
+
/**
|
|
383
|
+
* The globally unique process ID for this invocation.
|
|
384
|
+
*/
|
|
392
385
|
this.sessionId = void 0;
|
|
386
|
+
/**
|
|
387
|
+
* The system to which this actor belongs.
|
|
388
|
+
*/
|
|
393
389
|
this.system = void 0;
|
|
394
390
|
this._doneEvent = void 0;
|
|
395
391
|
this.src = void 0;
|
|
392
|
+
// array of functions to defer
|
|
396
393
|
this._deferred = [];
|
|
397
394
|
const resolvedOptions = {
|
|
398
395
|
...defaultOptions,
|
|
@@ -402,6 +399,7 @@ class Actor {
|
|
|
402
399
|
clock,
|
|
403
400
|
logger,
|
|
404
401
|
parent,
|
|
402
|
+
syncSnapshot,
|
|
405
403
|
id,
|
|
406
404
|
systemId,
|
|
407
405
|
inspect
|
|
@@ -416,6 +414,7 @@ class Actor {
|
|
|
416
414
|
this.logger = logger;
|
|
417
415
|
this.clock = clock;
|
|
418
416
|
this._parent = parent;
|
|
417
|
+
this._syncSnapshot = syncSnapshot;
|
|
419
418
|
this.options = resolvedOptions;
|
|
420
419
|
this.src = resolvedOptions.src ?? logic;
|
|
421
420
|
this.ref = this;
|
|
@@ -455,9 +454,6 @@ class Actor {
|
|
|
455
454
|
_initState(persistedState) {
|
|
456
455
|
this._state = persistedState ? this.logic.restoreState ? this.logic.restoreState(persistedState, this._actorScope) : persistedState : this.logic.getInitialState(this._actorScope, this.options?.input);
|
|
457
456
|
}
|
|
458
|
-
|
|
459
|
-
// array of functions to defer
|
|
460
|
-
|
|
461
457
|
update(snapshot, event) {
|
|
462
458
|
// Update state
|
|
463
459
|
this._state = snapshot;
|
|
@@ -574,6 +570,19 @@ class Actor {
|
|
|
574
570
|
// Do not restart the service if it is already started
|
|
575
571
|
return this;
|
|
576
572
|
}
|
|
573
|
+
if (this._syncSnapshot) {
|
|
574
|
+
this.subscribe({
|
|
575
|
+
next: snapshot => {
|
|
576
|
+
if (snapshot.status === 'active') {
|
|
577
|
+
this._parent.send({
|
|
578
|
+
type: `xstate.snapshot.${this.id}`,
|
|
579
|
+
snapshot
|
|
580
|
+
});
|
|
581
|
+
}
|
|
582
|
+
},
|
|
583
|
+
error: () => {}
|
|
584
|
+
});
|
|
585
|
+
}
|
|
577
586
|
this.system._register(this.sessionId, this);
|
|
578
587
|
if (this._systemId) {
|
|
579
588
|
this.system._set(this._systemId, this);
|
|
@@ -851,20 +860,6 @@ const interpret = createActor;
|
|
|
851
860
|
* @deprecated Use `Actor` instead.
|
|
852
861
|
*/
|
|
853
862
|
|
|
854
|
-
const cache = new WeakMap();
|
|
855
|
-
function memo(object, key, fn) {
|
|
856
|
-
let memoizedData = cache.get(object);
|
|
857
|
-
if (!memoizedData) {
|
|
858
|
-
memoizedData = {
|
|
859
|
-
[key]: fn()
|
|
860
|
-
};
|
|
861
|
-
cache.set(object, memoizedData);
|
|
862
|
-
} else if (!(key in memoizedData)) {
|
|
863
|
-
memoizedData[key] = fn();
|
|
864
|
-
}
|
|
865
|
-
return memoizedData[key];
|
|
866
|
-
}
|
|
867
|
-
|
|
868
863
|
function resolveCancel(_, state, actionArgs, actionParams, {
|
|
869
864
|
sendId
|
|
870
865
|
}) {
|
|
@@ -906,6 +901,7 @@ function resolveSpawn(actorScope, state, actionArgs, _actionParams, {
|
|
|
906
901
|
id: resolvedId,
|
|
907
902
|
src,
|
|
908
903
|
parent: actorScope?.self,
|
|
904
|
+
syncSnapshot,
|
|
909
905
|
systemId,
|
|
910
906
|
input: typeof input === 'function' ? input({
|
|
911
907
|
context: state.context,
|
|
@@ -913,19 +909,6 @@ function resolveSpawn(actorScope, state, actionArgs, _actionParams, {
|
|
|
913
909
|
self: actorScope?.self
|
|
914
910
|
}) : input
|
|
915
911
|
});
|
|
916
|
-
if (syncSnapshot) {
|
|
917
|
-
actorRef.subscribe({
|
|
918
|
-
next: snapshot => {
|
|
919
|
-
if (snapshot.status === 'active') {
|
|
920
|
-
actorScope.self.send({
|
|
921
|
-
type: `xstate.snapshot.${id}`,
|
|
922
|
-
snapshot
|
|
923
|
-
});
|
|
924
|
-
}
|
|
925
|
-
},
|
|
926
|
-
error: () => {}
|
|
927
|
-
});
|
|
928
|
-
}
|
|
929
912
|
}
|
|
930
913
|
return [cloneMachineSnapshot(state, {
|
|
931
914
|
children: {
|
|
@@ -1035,7 +1018,7 @@ function checkStateIn(state, _, {
|
|
|
1035
1018
|
}) {
|
|
1036
1019
|
if (typeof stateValue === 'string' && isStateId(stateValue)) {
|
|
1037
1020
|
const target = state.machine.getStateNodeById(stateValue);
|
|
1038
|
-
return state.
|
|
1021
|
+
return state._nodes.some(sn => sn === target);
|
|
1039
1022
|
}
|
|
1040
1023
|
return state.matches(stateValue);
|
|
1041
1024
|
}
|
|
@@ -1146,26 +1129,25 @@ function getProperAncestors(stateNode, toStateNode) {
|
|
|
1146
1129
|
}
|
|
1147
1130
|
return ancestors;
|
|
1148
1131
|
}
|
|
1149
|
-
function
|
|
1150
|
-
const
|
|
1151
|
-
const
|
|
1152
|
-
const adjList = getAdjList(configurationSet);
|
|
1132
|
+
function getAllStateNodes(stateNodes) {
|
|
1133
|
+
const nodeSet = new Set(stateNodes);
|
|
1134
|
+
const adjList = getAdjList(nodeSet);
|
|
1153
1135
|
|
|
1154
1136
|
// add descendants
|
|
1155
|
-
for (const s of
|
|
1137
|
+
for (const s of nodeSet) {
|
|
1156
1138
|
// if previously active, add existing child nodes
|
|
1157
1139
|
if (s.type === 'compound' && (!adjList.get(s) || !adjList.get(s).length)) {
|
|
1158
|
-
getInitialStateNodesWithTheirAncestors(s).forEach(sn =>
|
|
1140
|
+
getInitialStateNodesWithTheirAncestors(s).forEach(sn => nodeSet.add(sn));
|
|
1159
1141
|
} else {
|
|
1160
1142
|
if (s.type === 'parallel') {
|
|
1161
1143
|
for (const child of getChildren(s)) {
|
|
1162
1144
|
if (child.type === 'history') {
|
|
1163
1145
|
continue;
|
|
1164
1146
|
}
|
|
1165
|
-
if (!
|
|
1147
|
+
if (!nodeSet.has(child)) {
|
|
1166
1148
|
const initialStates = getInitialStateNodesWithTheirAncestors(child);
|
|
1167
1149
|
for (const initialStateNode of initialStates) {
|
|
1168
|
-
|
|
1150
|
+
nodeSet.add(initialStateNode);
|
|
1169
1151
|
}
|
|
1170
1152
|
}
|
|
1171
1153
|
}
|
|
@@ -1174,14 +1156,14 @@ function getConfiguration(stateNodes) {
|
|
|
1174
1156
|
}
|
|
1175
1157
|
|
|
1176
1158
|
// add all ancestors
|
|
1177
|
-
for (const s of
|
|
1159
|
+
for (const s of nodeSet) {
|
|
1178
1160
|
let m = s.parent;
|
|
1179
1161
|
while (m) {
|
|
1180
|
-
|
|
1162
|
+
nodeSet.add(m);
|
|
1181
1163
|
m = m.parent;
|
|
1182
1164
|
}
|
|
1183
1165
|
}
|
|
1184
|
-
return
|
|
1166
|
+
return nodeSet;
|
|
1185
1167
|
}
|
|
1186
1168
|
function getValueFromAdj(baseNode, adjList) {
|
|
1187
1169
|
const childStateNodes = adjList.get(baseNode);
|
|
@@ -1205,9 +1187,9 @@ function getValueFromAdj(baseNode, adjList) {
|
|
|
1205
1187
|
}
|
|
1206
1188
|
return stateValue;
|
|
1207
1189
|
}
|
|
1208
|
-
function getAdjList(
|
|
1190
|
+
function getAdjList(stateNodes) {
|
|
1209
1191
|
const adjList = new Map();
|
|
1210
|
-
for (const s of
|
|
1192
|
+
for (const s of stateNodes) {
|
|
1211
1193
|
if (!adjList.has(s)) {
|
|
1212
1194
|
adjList.set(s, []);
|
|
1213
1195
|
}
|
|
@@ -1220,16 +1202,16 @@ function getAdjList(configuration) {
|
|
|
1220
1202
|
}
|
|
1221
1203
|
return adjList;
|
|
1222
1204
|
}
|
|
1223
|
-
function getStateValue(rootNode,
|
|
1224
|
-
const config =
|
|
1205
|
+
function getStateValue(rootNode, stateNodes) {
|
|
1206
|
+
const config = getAllStateNodes(stateNodes);
|
|
1225
1207
|
return getValueFromAdj(rootNode, getAdjList(config));
|
|
1226
1208
|
}
|
|
1227
|
-
function isInFinalState(
|
|
1209
|
+
function isInFinalState(stateNodeSet, stateNode) {
|
|
1228
1210
|
if (stateNode.type === 'compound') {
|
|
1229
|
-
return getChildren(stateNode).some(s => s.type === 'final' &&
|
|
1211
|
+
return getChildren(stateNode).some(s => s.type === 'final' && stateNodeSet.has(s));
|
|
1230
1212
|
}
|
|
1231
1213
|
if (stateNode.type === 'parallel') {
|
|
1232
|
-
return getChildren(stateNode).every(sn => isInFinalState(
|
|
1214
|
+
return getChildren(stateNode).every(sn => isInFinalState(stateNodeSet, sn));
|
|
1233
1215
|
}
|
|
1234
1216
|
return stateNode.type === 'final';
|
|
1235
1217
|
}
|
|
@@ -1589,13 +1571,13 @@ function hasIntersection(s1, s2) {
|
|
|
1589
1571
|
}
|
|
1590
1572
|
return false;
|
|
1591
1573
|
}
|
|
1592
|
-
function removeConflictingTransitions(enabledTransitions,
|
|
1574
|
+
function removeConflictingTransitions(enabledTransitions, stateNodeSet, historyValue) {
|
|
1593
1575
|
const filteredTransitions = new Set();
|
|
1594
1576
|
for (const t1 of enabledTransitions) {
|
|
1595
1577
|
let t1Preempted = false;
|
|
1596
1578
|
const transitionsToRemove = new Set();
|
|
1597
1579
|
for (const t2 of filteredTransitions) {
|
|
1598
|
-
if (hasIntersection(computeExitSet([t1],
|
|
1580
|
+
if (hasIntersection(computeExitSet([t1], stateNodeSet, historyValue), computeExitSet([t2], stateNodeSet, historyValue))) {
|
|
1599
1581
|
if (isDescendant(t1.source, t2.source)) {
|
|
1600
1582
|
transitionsToRemove.add(t2);
|
|
1601
1583
|
} else {
|
|
@@ -1662,7 +1644,7 @@ function getTransitionDomain(transition, historyValue) {
|
|
|
1662
1644
|
}
|
|
1663
1645
|
return transition.source.machine.root;
|
|
1664
1646
|
}
|
|
1665
|
-
function computeExitSet(transitions,
|
|
1647
|
+
function computeExitSet(transitions, stateNodeSet, historyValue) {
|
|
1666
1648
|
const statesToExit = new Set();
|
|
1667
1649
|
for (const t of transitions) {
|
|
1668
1650
|
if (t.target?.length) {
|
|
@@ -1670,7 +1652,7 @@ function computeExitSet(transitions, configuration, historyValue) {
|
|
|
1670
1652
|
if (t.reenter && t.source === domain) {
|
|
1671
1653
|
statesToExit.add(domain);
|
|
1672
1654
|
}
|
|
1673
|
-
for (const stateNode of
|
|
1655
|
+
for (const stateNode of stateNodeSet) {
|
|
1674
1656
|
if (isDescendant(stateNode, domain)) {
|
|
1675
1657
|
statesToExit.add(stateNode);
|
|
1676
1658
|
}
|
|
@@ -1679,12 +1661,12 @@ function computeExitSet(transitions, configuration, historyValue) {
|
|
|
1679
1661
|
}
|
|
1680
1662
|
return [...statesToExit];
|
|
1681
1663
|
}
|
|
1682
|
-
function
|
|
1683
|
-
if (
|
|
1664
|
+
function areStateNodeCollectionsEqual(prevStateNodes, nextStateNodeSet) {
|
|
1665
|
+
if (prevStateNodes.length !== nextStateNodeSet.size) {
|
|
1684
1666
|
return false;
|
|
1685
1667
|
}
|
|
1686
|
-
for (const node of
|
|
1687
|
-
if (!
|
|
1668
|
+
for (const node of prevStateNodes) {
|
|
1669
|
+
if (!nextStateNodeSet.has(node)) {
|
|
1688
1670
|
return false;
|
|
1689
1671
|
}
|
|
1690
1672
|
}
|
|
@@ -1698,31 +1680,31 @@ function microstep(transitions, currentState, actorScope, event, isInitial, inte
|
|
|
1698
1680
|
if (!transitions.length) {
|
|
1699
1681
|
return currentState;
|
|
1700
1682
|
}
|
|
1701
|
-
const
|
|
1683
|
+
const mutStateNodeSet = new Set(currentState._nodes);
|
|
1702
1684
|
let historyValue = currentState.historyValue;
|
|
1703
|
-
const filteredTransitions = removeConflictingTransitions(transitions,
|
|
1685
|
+
const filteredTransitions = removeConflictingTransitions(transitions, mutStateNodeSet, historyValue);
|
|
1704
1686
|
let nextState = currentState;
|
|
1705
1687
|
|
|
1706
1688
|
// Exit states
|
|
1707
1689
|
if (!isInitial) {
|
|
1708
|
-
[nextState, historyValue] = exitStates(nextState, event, actorScope, filteredTransitions,
|
|
1690
|
+
[nextState, historyValue] = exitStates(nextState, event, actorScope, filteredTransitions, mutStateNodeSet, historyValue, internalQueue);
|
|
1709
1691
|
}
|
|
1710
1692
|
|
|
1711
1693
|
// Execute transition content
|
|
1712
1694
|
nextState = resolveActionsAndContext(nextState, event, actorScope, filteredTransitions.flatMap(t => t.actions), internalQueue);
|
|
1713
1695
|
|
|
1714
1696
|
// Enter states
|
|
1715
|
-
nextState = enterStates(nextState, event, actorScope, filteredTransitions,
|
|
1716
|
-
const
|
|
1697
|
+
nextState = enterStates(nextState, event, actorScope, filteredTransitions, mutStateNodeSet, internalQueue, historyValue, isInitial);
|
|
1698
|
+
const nextStateNodes = [...mutStateNodeSet];
|
|
1717
1699
|
if (nextState.status === 'done') {
|
|
1718
|
-
nextState = resolveActionsAndContext(nextState, event, actorScope,
|
|
1700
|
+
nextState = resolveActionsAndContext(nextState, event, actorScope, nextStateNodes.sort((a, b) => b.order - a.order).flatMap(state => state.exit), internalQueue);
|
|
1719
1701
|
}
|
|
1720
1702
|
try {
|
|
1721
|
-
if (historyValue === currentState.historyValue &&
|
|
1703
|
+
if (historyValue === currentState.historyValue && areStateNodeCollectionsEqual(currentState._nodes, mutStateNodeSet)) {
|
|
1722
1704
|
return nextState;
|
|
1723
1705
|
}
|
|
1724
1706
|
return cloneMachineSnapshot(nextState, {
|
|
1725
|
-
|
|
1707
|
+
_nodes: nextStateNodes,
|
|
1726
1708
|
historyValue
|
|
1727
1709
|
});
|
|
1728
1710
|
} catch (e) {
|
|
@@ -1738,7 +1720,7 @@ function getMachineOutput(state, event, actorScope, rootNode, rootCompletionNode
|
|
|
1738
1720
|
const doneStateEvent = createDoneStateEvent(rootCompletionNode.id, rootCompletionNode.output && rootCompletionNode.parent ? resolveOutput(rootCompletionNode.output, state.context, event, actorScope.self) : undefined);
|
|
1739
1721
|
return resolveOutput(rootNode.output, state.context, doneStateEvent, actorScope.self);
|
|
1740
1722
|
}
|
|
1741
|
-
function enterStates(currentState, event, actorScope, filteredTransitions,
|
|
1723
|
+
function enterStates(currentState, event, actorScope, filteredTransitions, mutStateNodeSet, internalQueue, historyValue, isInitial) {
|
|
1742
1724
|
let nextState = currentState;
|
|
1743
1725
|
const statesToEnter = new Set();
|
|
1744
1726
|
// those are states that were directly targeted or indirectly targeted by the explicit target
|
|
@@ -1753,7 +1735,7 @@ function enterStates(currentState, event, actorScope, filteredTransitions, mutCo
|
|
|
1753
1735
|
}
|
|
1754
1736
|
const completedNodes = new Set();
|
|
1755
1737
|
for (const stateNodeToEnter of [...statesToEnter].sort((a, b) => a.order - b.order)) {
|
|
1756
|
-
|
|
1738
|
+
mutStateNodeSet.add(stateNodeToEnter);
|
|
1757
1739
|
const actions = [];
|
|
1758
1740
|
|
|
1759
1741
|
// Add entry actions
|
|
@@ -1776,7 +1758,7 @@ function enterStates(currentState, event, actorScope, filteredTransitions, mutCo
|
|
|
1776
1758
|
if (parent?.type === 'compound') {
|
|
1777
1759
|
internalQueue.push(createDoneStateEvent(parent.id, stateNodeToEnter.output ? resolveOutput(stateNodeToEnter.output, nextState.context, event, actorScope.self) : undefined));
|
|
1778
1760
|
}
|
|
1779
|
-
while (ancestorMarker?.type === 'parallel' && !completedNodes.has(ancestorMarker) && isInFinalState(
|
|
1761
|
+
while (ancestorMarker?.type === 'parallel' && !completedNodes.has(ancestorMarker) && isInFinalState(mutStateNodeSet, ancestorMarker)) {
|
|
1780
1762
|
completedNodes.add(ancestorMarker);
|
|
1781
1763
|
internalQueue.push(createDoneStateEvent(ancestorMarker.id));
|
|
1782
1764
|
rootCompletionNode = ancestorMarker;
|
|
@@ -1886,9 +1868,9 @@ function addAncestorStatesToEnter(statesToEnter, historyValue, statesForDefaultE
|
|
|
1886
1868
|
function addProperAncestorStatesToEnter(stateNode, toStateNode, statesToEnter, historyValue, statesForDefaultEntry) {
|
|
1887
1869
|
addAncestorStatesToEnter(statesToEnter, historyValue, statesForDefaultEntry, getProperAncestors(stateNode, toStateNode));
|
|
1888
1870
|
}
|
|
1889
|
-
function exitStates(currentState, event, actorScope, transitions,
|
|
1871
|
+
function exitStates(currentState, event, actorScope, transitions, mutStateNodeSet, historyValue, internalQueue) {
|
|
1890
1872
|
let nextState = currentState;
|
|
1891
|
-
const statesToExit = computeExitSet(transitions,
|
|
1873
|
+
const statesToExit = computeExitSet(transitions, mutStateNodeSet, historyValue);
|
|
1892
1874
|
statesToExit.sort((a, b) => b.order - a.order);
|
|
1893
1875
|
let changedHistory;
|
|
1894
1876
|
|
|
@@ -1906,12 +1888,12 @@ function exitStates(currentState, event, actorScope, transitions, mutConfigurati
|
|
|
1906
1888
|
changedHistory ??= {
|
|
1907
1889
|
...historyValue
|
|
1908
1890
|
};
|
|
1909
|
-
changedHistory[historyNode.id] = Array.from(
|
|
1891
|
+
changedHistory[historyNode.id] = Array.from(mutStateNodeSet).filter(predicate);
|
|
1910
1892
|
}
|
|
1911
1893
|
}
|
|
1912
1894
|
for (const s of statesToExit) {
|
|
1913
1895
|
nextState = resolveActionsAndContext(nextState, event, actorScope, [...s.exit, ...s.invoke.map(def => stop(def.id))], internalQueue);
|
|
1914
|
-
|
|
1896
|
+
mutStateNodeSet.delete(s);
|
|
1915
1897
|
}
|
|
1916
1898
|
return [nextState, changedHistory || historyValue];
|
|
1917
1899
|
}
|
|
@@ -2040,7 +2022,7 @@ function selectTransitions(event, nextState) {
|
|
|
2040
2022
|
}
|
|
2041
2023
|
function selectEventlessTransitions(nextState, event) {
|
|
2042
2024
|
const enabledTransitionSet = new Set();
|
|
2043
|
-
const atomicStates = nextState.
|
|
2025
|
+
const atomicStates = nextState._nodes.filter(isAtomicStateNode);
|
|
2044
2026
|
for (const stateNode of atomicStates) {
|
|
2045
2027
|
loop: for (const s of [stateNode].concat(getProperAncestors(stateNode, undefined))) {
|
|
2046
2028
|
if (!s.always) {
|
|
@@ -2054,7 +2036,7 @@ function selectEventlessTransitions(nextState, event) {
|
|
|
2054
2036
|
}
|
|
2055
2037
|
}
|
|
2056
2038
|
}
|
|
2057
|
-
return removeConflictingTransitions(Array.from(enabledTransitionSet), new Set(nextState.
|
|
2039
|
+
return removeConflictingTransitions(Array.from(enabledTransitionSet), new Set(nextState._nodes), nextState.historyValue);
|
|
2058
2040
|
}
|
|
2059
2041
|
|
|
2060
2042
|
/**
|
|
@@ -2063,8 +2045,8 @@ function selectEventlessTransitions(nextState, event) {
|
|
|
2063
2045
|
* @param stateValue The partial state value to resolve.
|
|
2064
2046
|
*/
|
|
2065
2047
|
function resolveStateValue(rootNode, stateValue) {
|
|
2066
|
-
const
|
|
2067
|
-
return getStateValue(rootNode, [...
|
|
2048
|
+
const allStateNodes = getAllStateNodes(getStateNodes(rootNode, stateValue));
|
|
2049
|
+
return getStateValue(rootNode, [...allStateNodes]);
|
|
2068
2050
|
}
|
|
2069
2051
|
|
|
2070
2052
|
function isMachineSnapshot(value) {
|
|
@@ -2084,10 +2066,10 @@ const machineSnapshotCan = function can(event) {
|
|
|
2084
2066
|
};
|
|
2085
2067
|
const machineSnapshotToJSON = function toJSON() {
|
|
2086
2068
|
const {
|
|
2087
|
-
|
|
2069
|
+
_nodes: nodes,
|
|
2088
2070
|
tags,
|
|
2089
2071
|
machine,
|
|
2090
|
-
|
|
2072
|
+
getMeta,
|
|
2091
2073
|
toJSON,
|
|
2092
2074
|
can,
|
|
2093
2075
|
hasTag,
|
|
@@ -2099,13 +2081,8 @@ const machineSnapshotToJSON = function toJSON() {
|
|
|
2099
2081
|
tags: Array.from(tags)
|
|
2100
2082
|
};
|
|
2101
2083
|
};
|
|
2102
|
-
const
|
|
2103
|
-
return
|
|
2104
|
-
return [...new Set(flatten([...this.configuration.map(sn => sn.ownEvents)]))];
|
|
2105
|
-
});
|
|
2106
|
-
};
|
|
2107
|
-
const machineSnapshotMeta = function nextEvents() {
|
|
2108
|
-
return this.configuration.reduce((acc, stateNode) => {
|
|
2084
|
+
const machineSnapshotGetMeta = function getMeta() {
|
|
2085
|
+
return this._nodes.reduce((acc, stateNode) => {
|
|
2109
2086
|
if (stateNode.meta !== undefined) {
|
|
2110
2087
|
acc[stateNode.id] = stateNode.meta;
|
|
2111
2088
|
}
|
|
@@ -2113,48 +2090,34 @@ const machineSnapshotMeta = function nextEvents() {
|
|
|
2113
2090
|
}, {});
|
|
2114
2091
|
};
|
|
2115
2092
|
function createMachineSnapshot(config, machine) {
|
|
2116
|
-
|
|
2093
|
+
return {
|
|
2117
2094
|
status: config.status,
|
|
2118
2095
|
output: config.output,
|
|
2119
2096
|
error: config.error,
|
|
2120
2097
|
machine,
|
|
2121
2098
|
context: config.context,
|
|
2122
|
-
|
|
2123
|
-
value: getStateValue(machine.root, config.
|
|
2124
|
-
tags: new Set(flatten(config.
|
|
2099
|
+
_nodes: config._nodes,
|
|
2100
|
+
value: getStateValue(machine.root, config._nodes),
|
|
2101
|
+
tags: new Set(flatten(config._nodes.map(sn => sn.tags))),
|
|
2125
2102
|
children: config.children,
|
|
2126
2103
|
historyValue: config.historyValue || {},
|
|
2127
2104
|
// this one is generic in the target and it's hard to create a matching non-generic source signature
|
|
2128
2105
|
matches: machineSnapshotMatches,
|
|
2129
2106
|
hasTag: machineSnapshotHasTag,
|
|
2130
2107
|
can: machineSnapshotCan,
|
|
2108
|
+
getMeta: machineSnapshotGetMeta,
|
|
2131
2109
|
toJSON: machineSnapshotToJSON
|
|
2132
2110
|
};
|
|
2133
|
-
Object.defineProperties(snapshot, {
|
|
2134
|
-
nextEvents: {
|
|
2135
|
-
get: machineSnapshotNextEvents,
|
|
2136
|
-
configurable: true,
|
|
2137
|
-
enumerable: true
|
|
2138
|
-
},
|
|
2139
|
-
meta: {
|
|
2140
|
-
get: machineSnapshotMeta,
|
|
2141
|
-
configurable: true,
|
|
2142
|
-
enumerable: true
|
|
2143
|
-
}
|
|
2144
|
-
});
|
|
2145
|
-
return snapshot;
|
|
2146
2111
|
}
|
|
2147
2112
|
function cloneMachineSnapshot(state, config = {}) {
|
|
2148
|
-
return createMachineSnapshot(
|
|
2149
|
-
// TODO: it's wasteful that this spread triggers getters
|
|
2150
|
-
{
|
|
2113
|
+
return createMachineSnapshot({
|
|
2151
2114
|
...state,
|
|
2152
2115
|
...config
|
|
2153
2116
|
}, state.machine);
|
|
2154
2117
|
}
|
|
2155
2118
|
function getPersistedState(state, options) {
|
|
2156
2119
|
const {
|
|
2157
|
-
|
|
2120
|
+
_nodes: nodes,
|
|
2158
2121
|
tags,
|
|
2159
2122
|
machine,
|
|
2160
2123
|
children,
|
|
@@ -2162,8 +2125,8 @@ function getPersistedState(state, options) {
|
|
|
2162
2125
|
can,
|
|
2163
2126
|
hasTag,
|
|
2164
2127
|
matches,
|
|
2128
|
+
getMeta,
|
|
2165
2129
|
toJSON,
|
|
2166
|
-
nextEvents,
|
|
2167
2130
|
...jsonValues
|
|
2168
2131
|
} = state;
|
|
2169
2132
|
const childrenJson = {};
|
|
@@ -2172,7 +2135,8 @@ function getPersistedState(state, options) {
|
|
|
2172
2135
|
childrenJson[id] = {
|
|
2173
2136
|
state: child.getPersistedState(options),
|
|
2174
2137
|
src: child.src,
|
|
2175
|
-
systemId: child._systemId
|
|
2138
|
+
systemId: child._systemId,
|
|
2139
|
+
syncSnapshot: child._syncSnapshot
|
|
2176
2140
|
};
|
|
2177
2141
|
}
|
|
2178
2142
|
const persisted = {
|
|
@@ -2261,4 +2225,4 @@ function raise(eventOrExpr, options) {
|
|
|
2261
2225
|
return raise;
|
|
2262
2226
|
}
|
|
2263
2227
|
|
|
2264
|
-
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,
|
|
2228
|
+
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 };
|