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