xstate 5.0.0-beta.41 → 5.0.0-beta.42
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 +1 -1
- package/actors/dist/xstate-actors.development.cjs.js +1 -1
- package/actors/dist/xstate-actors.development.esm.js +1 -1
- package/actors/dist/xstate-actors.esm.js +1 -1
- package/actors/dist/xstate-actors.umd.min.js.map +1 -1
- package/dist/declarations/src/State.d.ts +35 -42
- package/dist/declarations/src/StateMachine.d.ts +12 -29
- package/dist/declarations/src/StateNode.d.ts +2 -2
- package/dist/declarations/src/index.d.ts +3 -4
- package/dist/declarations/src/interpreter.d.ts +12 -0
- package/dist/declarations/src/stateUtils.d.ts +7 -8
- package/dist/declarations/src/types.d.ts +112 -15
- package/dist/{interpreter-70ed981b.development.cjs.js → interpreter-23e4041c.development.cjs.js} +23 -10
- package/dist/{interpreter-480db258.esm.js → interpreter-3d0c0ff2.esm.js} +24 -10
- package/dist/{interpreter-fb2829f1.cjs.js → interpreter-b6bdd134.cjs.js} +23 -10
- package/dist/{interpreter-936da690.development.esm.js → interpreter-f2620ea7.development.esm.js} +24 -10
- package/dist/{raise-f757be00.development.esm.js → raise-51ae36e5.development.esm.js} +76 -175
- package/dist/{raise-beae3fd3.cjs.js → raise-6b64c553.cjs.js} +74 -174
- package/dist/{raise-5ab465ed.development.cjs.js → raise-8f482ce9.development.cjs.js} +77 -177
- package/dist/{raise-9d6921da.esm.js → raise-d2084327.esm.js} +73 -172
- package/dist/{send-a931d1b8.esm.js → send-4e732fa5.esm.js} +5 -3
- package/dist/{send-b26e3812.development.esm.js → send-7a350091.development.esm.js} +5 -3
- package/dist/{send-ca5f706c.cjs.js → send-85b562d8.cjs.js} +5 -3
- package/dist/{send-fb87a01a.development.cjs.js → send-cc8f864e.development.cjs.js} +5 -3
- package/dist/xstate.cjs.js +23 -49
- package/dist/xstate.cjs.mjs +0 -2
- package/dist/xstate.development.cjs.js +23 -49
- package/dist/xstate.development.cjs.mjs +0 -2
- package/dist/xstate.development.esm.js +27 -51
- package/dist/xstate.esm.js +27 -51
- 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
- package/dist/declarations/src/mapState.d.ts +0 -3
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var interpreter = require('./interpreter-
|
|
3
|
+
var interpreter = require('./interpreter-23e4041c.development.cjs.js');
|
|
4
4
|
|
|
5
5
|
const cache = new WeakMap();
|
|
6
6
|
function memo(object, key, fn) {
|
|
@@ -89,7 +89,7 @@ function resolveSpawn(actorScope, state, actionArgs, _actionParams, {
|
|
|
89
89
|
if (!actorRef) {
|
|
90
90
|
console.warn(`Actor type '${src}' not found in machine '${actorScope.id}'.`);
|
|
91
91
|
}
|
|
92
|
-
return [
|
|
92
|
+
return [cloneMachineSnapshot(state, {
|
|
93
93
|
children: {
|
|
94
94
|
...state.children,
|
|
95
95
|
[resolvedId]: actorRef
|
|
@@ -152,7 +152,7 @@ function resolveStop(_, state, args, actionParams, {
|
|
|
152
152
|
};
|
|
153
153
|
delete children[resolvedActorRef.id];
|
|
154
154
|
}
|
|
155
|
-
return [
|
|
155
|
+
return [cloneMachineSnapshot(state, {
|
|
156
156
|
children
|
|
157
157
|
}), resolvedActorRef];
|
|
158
158
|
}
|
|
@@ -685,10 +685,9 @@ function getStateNodeByPath(stateNode, statePath) {
|
|
|
685
685
|
/**
|
|
686
686
|
* Returns the state nodes represented by the current state value.
|
|
687
687
|
*
|
|
688
|
-
* @param
|
|
688
|
+
* @param stateValue The state value or State instance
|
|
689
689
|
*/
|
|
690
|
-
function getStateNodes(stateNode,
|
|
691
|
-
const stateValue = state instanceof State ? state.value : interpreter.toStateValue(state);
|
|
690
|
+
function getStateNodes(stateNode, stateValue) {
|
|
692
691
|
if (typeof stateValue === 'string') {
|
|
693
692
|
return [stateNode, stateNode.states[stateValue]];
|
|
694
693
|
}
|
|
@@ -909,7 +908,7 @@ function microstep(transitions, currentState, actorScope, event, isInitial, inte
|
|
|
909
908
|
if (historyValue === currentState.historyValue && areConfigurationsEqual(currentState.configuration, mutConfiguration)) {
|
|
910
909
|
return nextState;
|
|
911
910
|
}
|
|
912
|
-
return
|
|
911
|
+
return cloneMachineSnapshot(nextState, {
|
|
913
912
|
configuration: nextConfiguration,
|
|
914
913
|
historyValue
|
|
915
914
|
});
|
|
@@ -973,9 +972,9 @@ function enterStates(currentState, event, actorScope, filteredTransitions, mutCo
|
|
|
973
972
|
if (ancestorMarker) {
|
|
974
973
|
continue;
|
|
975
974
|
}
|
|
976
|
-
nextState =
|
|
975
|
+
nextState = cloneMachineSnapshot(nextState, {
|
|
977
976
|
status: 'done',
|
|
978
|
-
output: getMachineOutput(nextState, event, actorScope,
|
|
977
|
+
output: getMachineOutput(nextState, event, actorScope, nextState.machine.root, rootCompletionNode)
|
|
979
978
|
});
|
|
980
979
|
}
|
|
981
980
|
}
|
|
@@ -1179,7 +1178,7 @@ function macrostep(state, event, actorScope, internalQueue = []) {
|
|
|
1179
1178
|
|
|
1180
1179
|
// Handle stop event
|
|
1181
1180
|
if (event.type === interpreter.XSTATE_STOP) {
|
|
1182
|
-
nextState =
|
|
1181
|
+
nextState = cloneMachineSnapshot(stopChildren(nextState, event, actorScope), {
|
|
1183
1182
|
status: 'stopped'
|
|
1184
1183
|
});
|
|
1185
1184
|
states.push(nextState);
|
|
@@ -1257,173 +1256,70 @@ function resolveStateValue(rootNode, stateValue) {
|
|
|
1257
1256
|
const configuration = getConfiguration(getStateNodes(rootNode, stateValue));
|
|
1258
1257
|
return getStateValue(rootNode, [...configuration]);
|
|
1259
1258
|
}
|
|
1260
|
-
function getInitialConfiguration(rootNode) {
|
|
1261
|
-
const configuration = [];
|
|
1262
|
-
const initialTransition = rootNode.initial;
|
|
1263
|
-
const statesToEnter = new Set();
|
|
1264
|
-
const statesForDefaultEntry = new Set([rootNode]);
|
|
1265
|
-
computeEntrySet([initialTransition], {}, statesForDefaultEntry, statesToEnter);
|
|
1266
|
-
for (const stateNodeToEnter of [...statesToEnter].sort((a, b) => a.order - b.order)) {
|
|
1267
|
-
configuration.push(stateNodeToEnter);
|
|
1268
|
-
}
|
|
1269
|
-
return configuration;
|
|
1270
|
-
}
|
|
1271
|
-
|
|
1272
|
-
class State {
|
|
1273
|
-
/**
|
|
1274
|
-
* Indicates whether the state is a final state.
|
|
1275
|
-
*/
|
|
1276
|
-
|
|
1277
|
-
/**
|
|
1278
|
-
* The output data of the top-level finite state.
|
|
1279
|
-
*/
|
|
1280
|
-
|
|
1281
|
-
/**
|
|
1282
|
-
* The enabled state nodes representative of the state value.
|
|
1283
|
-
*/
|
|
1284
|
-
|
|
1285
|
-
/**
|
|
1286
|
-
* An object mapping actor names to spawned/invoked actors.
|
|
1287
|
-
*/
|
|
1288
|
-
|
|
1289
|
-
/**
|
|
1290
|
-
* Creates a new State instance for the given `stateValue` and `context`.
|
|
1291
|
-
* @param stateValue
|
|
1292
|
-
* @param context
|
|
1293
|
-
*/
|
|
1294
|
-
static from(stateValue, context = {}, machine) {
|
|
1295
|
-
if (stateValue instanceof State) {
|
|
1296
|
-
if (stateValue.context !== context) {
|
|
1297
|
-
return new State({
|
|
1298
|
-
value: stateValue.value,
|
|
1299
|
-
context,
|
|
1300
|
-
meta: {},
|
|
1301
|
-
configuration: [],
|
|
1302
|
-
// TODO: fix,
|
|
1303
|
-
children: {},
|
|
1304
|
-
status: 'active'
|
|
1305
|
-
}, machine);
|
|
1306
|
-
}
|
|
1307
|
-
return stateValue;
|
|
1308
|
-
}
|
|
1309
|
-
const configuration = getConfiguration(getStateNodes(machine.root, stateValue));
|
|
1310
|
-
return new State({
|
|
1311
|
-
value: stateValue,
|
|
1312
|
-
context,
|
|
1313
|
-
meta: undefined,
|
|
1314
|
-
configuration: Array.from(configuration),
|
|
1315
|
-
children: {},
|
|
1316
|
-
status: 'active'
|
|
1317
|
-
}, machine);
|
|
1318
|
-
}
|
|
1319
|
-
|
|
1320
|
-
/**
|
|
1321
|
-
* Creates a new `State` instance that represents the current state of a running machine.
|
|
1322
|
-
*
|
|
1323
|
-
* @param config
|
|
1324
|
-
*/
|
|
1325
|
-
constructor(config, machine) {
|
|
1326
|
-
this.machine = machine;
|
|
1327
|
-
this.tags = void 0;
|
|
1328
|
-
this.value = void 0;
|
|
1329
|
-
this.status = void 0;
|
|
1330
|
-
this.error = void 0;
|
|
1331
|
-
this.context = void 0;
|
|
1332
|
-
this.historyValue = {};
|
|
1333
|
-
this.configuration = void 0;
|
|
1334
|
-
this.children = void 0;
|
|
1335
|
-
this.context = config.context;
|
|
1336
|
-
this.historyValue = config.historyValue || {};
|
|
1337
|
-
this.matches = this.matches.bind(this);
|
|
1338
|
-
this.toStrings = this.toStrings.bind(this);
|
|
1339
|
-
this.configuration = config.configuration ?? Array.from(getConfiguration(getStateNodes(machine.root, config.value)));
|
|
1340
|
-
this.children = config.children;
|
|
1341
|
-
this.value = getStateValue(machine.root, this.configuration);
|
|
1342
|
-
this.tags = new Set(interpreter.flatten(this.configuration.map(sn => sn.tags)));
|
|
1343
|
-
this.status = config.status;
|
|
1344
|
-
this.output = config.output;
|
|
1345
|
-
this.error = config.error;
|
|
1346
|
-
}
|
|
1347
|
-
|
|
1348
|
-
/**
|
|
1349
|
-
* Returns an array of all the string leaf state node paths.
|
|
1350
|
-
* @param stateValue
|
|
1351
|
-
* @param delimiter The character(s) that separate each subpath in the string state node path.
|
|
1352
|
-
*/
|
|
1353
|
-
toStrings(stateValue = this.value) {
|
|
1354
|
-
if (typeof stateValue === 'string') {
|
|
1355
|
-
return [stateValue];
|
|
1356
|
-
}
|
|
1357
|
-
const valueKeys = Object.keys(stateValue);
|
|
1358
|
-
return valueKeys.concat(...valueKeys.map(key => this.toStrings(stateValue[key]).map(s => key + interpreter.STATE_DELIMITER + s)));
|
|
1359
|
-
}
|
|
1360
|
-
toJSON() {
|
|
1361
|
-
const {
|
|
1362
|
-
configuration,
|
|
1363
|
-
tags,
|
|
1364
|
-
machine,
|
|
1365
|
-
...jsonValues
|
|
1366
|
-
} = this;
|
|
1367
|
-
return {
|
|
1368
|
-
...jsonValues,
|
|
1369
|
-
tags: Array.from(tags),
|
|
1370
|
-
meta: this.meta
|
|
1371
|
-
};
|
|
1372
|
-
}
|
|
1373
|
-
|
|
1374
|
-
/**
|
|
1375
|
-
* Whether the current state value is a subset of the given parent state value.
|
|
1376
|
-
* @param parentStateValue
|
|
1377
|
-
*/
|
|
1378
|
-
matches(parentStateValue) {
|
|
1379
|
-
return interpreter.matchesState(parentStateValue, this.value);
|
|
1380
|
-
}
|
|
1381
|
-
|
|
1382
|
-
/**
|
|
1383
|
-
* Whether the current state configuration has a state node with the specified `tag`.
|
|
1384
|
-
* @param tag
|
|
1385
|
-
*/
|
|
1386
|
-
hasTag(tag) {
|
|
1387
|
-
return this.tags.has(tag);
|
|
1388
|
-
}
|
|
1389
1259
|
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
}
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
get nextEvents() {
|
|
1412
|
-
return memo(this, 'nextEvents', () => {
|
|
1413
|
-
return [...new Set(interpreter.flatten([...this.configuration.map(sn => sn.ownEvents)]))];
|
|
1414
|
-
});
|
|
1415
|
-
}
|
|
1416
|
-
get meta() {
|
|
1417
|
-
return this.configuration.reduce((acc, stateNode) => {
|
|
1418
|
-
if (stateNode.meta !== undefined) {
|
|
1419
|
-
acc[stateNode.id] = stateNode.meta;
|
|
1260
|
+
function createMachineSnapshot(config, machine) {
|
|
1261
|
+
return {
|
|
1262
|
+
status: config.status,
|
|
1263
|
+
output: config.output,
|
|
1264
|
+
error: config.error,
|
|
1265
|
+
machine,
|
|
1266
|
+
context: config.context,
|
|
1267
|
+
configuration: config.configuration,
|
|
1268
|
+
value: getStateValue(machine.root, config.configuration),
|
|
1269
|
+
tags: new Set(interpreter.flatten(config.configuration.map(sn => sn.tags))),
|
|
1270
|
+
children: config.children,
|
|
1271
|
+
historyValue: config.historyValue || {},
|
|
1272
|
+
matches(parentStateValue) {
|
|
1273
|
+
return interpreter.matchesState(parentStateValue, this.value);
|
|
1274
|
+
},
|
|
1275
|
+
hasTag(tag) {
|
|
1276
|
+
return this.tags.has(tag);
|
|
1277
|
+
},
|
|
1278
|
+
can(event) {
|
|
1279
|
+
if (!this.machine) {
|
|
1280
|
+
console.warn(`state.can(...) used outside of a machine-created State object; this will always return false.`);
|
|
1420
1281
|
}
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1282
|
+
const transitionData = this.machine.getTransitionData(this, event);
|
|
1283
|
+
return !!transitionData?.length &&
|
|
1284
|
+
// Check that at least one transition is not forbidden
|
|
1285
|
+
transitionData.some(t => t.target !== undefined || t.actions.length);
|
|
1286
|
+
},
|
|
1287
|
+
get nextEvents() {
|
|
1288
|
+
return memo(this, 'nextEvents', () => {
|
|
1289
|
+
return [...new Set(interpreter.flatten([...this.configuration.map(sn => sn.ownEvents)]))];
|
|
1290
|
+
});
|
|
1291
|
+
},
|
|
1292
|
+
get meta() {
|
|
1293
|
+
return this.configuration.reduce((acc, stateNode) => {
|
|
1294
|
+
if (stateNode.meta !== undefined) {
|
|
1295
|
+
acc[stateNode.id] = stateNode.meta;
|
|
1296
|
+
}
|
|
1297
|
+
return acc;
|
|
1298
|
+
}, {});
|
|
1299
|
+
},
|
|
1300
|
+
toJSON() {
|
|
1301
|
+
const {
|
|
1302
|
+
configuration,
|
|
1303
|
+
tags,
|
|
1304
|
+
machine,
|
|
1305
|
+
nextEvents,
|
|
1306
|
+
toJSON,
|
|
1307
|
+
can,
|
|
1308
|
+
hasTag,
|
|
1309
|
+
matches,
|
|
1310
|
+
...jsonValues
|
|
1311
|
+
} = this;
|
|
1312
|
+
return {
|
|
1313
|
+
...jsonValues,
|
|
1314
|
+
tags: Array.from(tags)
|
|
1315
|
+
};
|
|
1316
|
+
}
|
|
1317
|
+
};
|
|
1424
1318
|
}
|
|
1425
|
-
function
|
|
1426
|
-
return
|
|
1319
|
+
function cloneMachineSnapshot(state, config = {}) {
|
|
1320
|
+
return createMachineSnapshot(
|
|
1321
|
+
// TODO: it's wasteful that this spread triggers getters
|
|
1322
|
+
{
|
|
1427
1323
|
...state,
|
|
1428
1324
|
...config
|
|
1429
1325
|
}, state.machine);
|
|
@@ -1435,6 +1331,11 @@ function getPersistedState(state, options) {
|
|
|
1435
1331
|
machine,
|
|
1436
1332
|
children,
|
|
1437
1333
|
context,
|
|
1334
|
+
can,
|
|
1335
|
+
hasTag,
|
|
1336
|
+
matches,
|
|
1337
|
+
toJSON,
|
|
1338
|
+
nextEvents,
|
|
1438
1339
|
...jsonValues
|
|
1439
1340
|
} = state;
|
|
1440
1341
|
const childrenJson = {};
|
|
@@ -1538,10 +1439,10 @@ function raise(eventOrExpr, options) {
|
|
|
1538
1439
|
return raise;
|
|
1539
1440
|
}
|
|
1540
1441
|
|
|
1541
|
-
exports.State = State;
|
|
1542
1442
|
exports.and = and;
|
|
1543
1443
|
exports.cancel = cancel;
|
|
1544
|
-
exports.
|
|
1444
|
+
exports.cloneMachineSnapshot = cloneMachineSnapshot;
|
|
1445
|
+
exports.createMachineSnapshot = createMachineSnapshot;
|
|
1545
1446
|
exports.evaluateGuard = evaluateGuard;
|
|
1546
1447
|
exports.formatInitialTransition = formatInitialTransition;
|
|
1547
1448
|
exports.formatTransition = formatTransition;
|
|
@@ -1549,7 +1450,6 @@ exports.formatTransitions = formatTransitions;
|
|
|
1549
1450
|
exports.getCandidates = getCandidates;
|
|
1550
1451
|
exports.getConfiguration = getConfiguration;
|
|
1551
1452
|
exports.getDelayedTransitions = getDelayedTransitions;
|
|
1552
|
-
exports.getInitialConfiguration = getInitialConfiguration;
|
|
1553
1453
|
exports.getInitialStateNodes = getInitialStateNodes;
|
|
1554
1454
|
exports.getPersistedState = getPersistedState;
|
|
1555
1455
|
exports.getStateNodeByPath = getStateNodeByPath;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { r as resolveReferencedActor, d as createActor, P as ProcessingStatus, h as createErrorActorEvent, j as
|
|
1
|
+
import { r as resolveReferencedActor, d as createActor, P as ProcessingStatus, h as createErrorActorEvent, j as STATE_IDENTIFIER, n as normalizeTarget, t as toArray, N as NULL_EVENT, a as toTransitionConfigArray, S as STATE_DELIMITER, k as toStatePath, l as createDoneStateEvent, o as resolveOutput, X as XSTATE_STOP, q as XSTATE_INIT, W as WILDCARD, s as createAfterEvent, u as flatten, f as matchesState, $ as $$ACTOR_TYPE } from './interpreter-3d0c0ff2.esm.js';
|
|
2
2
|
|
|
3
3
|
const cache = new WeakMap();
|
|
4
4
|
function memo(object, key, fn) {
|
|
@@ -81,7 +81,7 @@ function resolveSpawn(actorScope, state, actionArgs, _actionParams, {
|
|
|
81
81
|
});
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
|
-
return [
|
|
84
|
+
return [cloneMachineSnapshot(state, {
|
|
85
85
|
children: {
|
|
86
86
|
...state.children,
|
|
87
87
|
[resolvedId]: actorRef
|
|
@@ -141,7 +141,7 @@ function resolveStop(_, state, args, actionParams, {
|
|
|
141
141
|
};
|
|
142
142
|
delete children[resolvedActorRef.id];
|
|
143
143
|
}
|
|
144
|
-
return [
|
|
144
|
+
return [cloneMachineSnapshot(state, {
|
|
145
145
|
children
|
|
146
146
|
}), resolvedActorRef];
|
|
147
147
|
}
|
|
@@ -652,10 +652,9 @@ function getStateNodeByPath(stateNode, statePath) {
|
|
|
652
652
|
/**
|
|
653
653
|
* Returns the state nodes represented by the current state value.
|
|
654
654
|
*
|
|
655
|
-
* @param
|
|
655
|
+
* @param stateValue The state value or State instance
|
|
656
656
|
*/
|
|
657
|
-
function getStateNodes(stateNode,
|
|
658
|
-
const stateValue = state instanceof State ? state.value : toStateValue(state);
|
|
657
|
+
function getStateNodes(stateNode, stateValue) {
|
|
659
658
|
if (typeof stateValue === 'string') {
|
|
660
659
|
return [stateNode, stateNode.states[stateValue]];
|
|
661
660
|
}
|
|
@@ -876,7 +875,7 @@ function microstep(transitions, currentState, actorScope, event, isInitial, inte
|
|
|
876
875
|
if (historyValue === currentState.historyValue && areConfigurationsEqual(currentState.configuration, mutConfiguration)) {
|
|
877
876
|
return nextState;
|
|
878
877
|
}
|
|
879
|
-
return
|
|
878
|
+
return cloneMachineSnapshot(nextState, {
|
|
880
879
|
configuration: nextConfiguration,
|
|
881
880
|
historyValue
|
|
882
881
|
});
|
|
@@ -940,9 +939,9 @@ function enterStates(currentState, event, actorScope, filteredTransitions, mutCo
|
|
|
940
939
|
if (ancestorMarker) {
|
|
941
940
|
continue;
|
|
942
941
|
}
|
|
943
|
-
nextState =
|
|
942
|
+
nextState = cloneMachineSnapshot(nextState, {
|
|
944
943
|
status: 'done',
|
|
945
|
-
output: getMachineOutput(nextState, event, actorScope,
|
|
944
|
+
output: getMachineOutput(nextState, event, actorScope, nextState.machine.root, rootCompletionNode)
|
|
946
945
|
});
|
|
947
946
|
}
|
|
948
947
|
}
|
|
@@ -1143,7 +1142,7 @@ function macrostep(state, event, actorScope, internalQueue = []) {
|
|
|
1143
1142
|
|
|
1144
1143
|
// Handle stop event
|
|
1145
1144
|
if (event.type === XSTATE_STOP) {
|
|
1146
|
-
nextState =
|
|
1145
|
+
nextState = cloneMachineSnapshot(stopChildren(nextState, event, actorScope), {
|
|
1147
1146
|
status: 'stopped'
|
|
1148
1147
|
});
|
|
1149
1148
|
states.push(nextState);
|
|
@@ -1221,170 +1220,67 @@ function resolveStateValue(rootNode, stateValue) {
|
|
|
1221
1220
|
const configuration = getConfiguration(getStateNodes(rootNode, stateValue));
|
|
1222
1221
|
return getStateValue(rootNode, [...configuration]);
|
|
1223
1222
|
}
|
|
1224
|
-
function getInitialConfiguration(rootNode) {
|
|
1225
|
-
const configuration = [];
|
|
1226
|
-
const initialTransition = rootNode.initial;
|
|
1227
|
-
const statesToEnter = new Set();
|
|
1228
|
-
const statesForDefaultEntry = new Set([rootNode]);
|
|
1229
|
-
computeEntrySet([initialTransition], {}, statesForDefaultEntry, statesToEnter);
|
|
1230
|
-
for (const stateNodeToEnter of [...statesToEnter].sort((a, b) => a.order - b.order)) {
|
|
1231
|
-
configuration.push(stateNodeToEnter);
|
|
1232
|
-
}
|
|
1233
|
-
return configuration;
|
|
1234
|
-
}
|
|
1235
|
-
|
|
1236
|
-
class State {
|
|
1237
|
-
/**
|
|
1238
|
-
* Indicates whether the state is a final state.
|
|
1239
|
-
*/
|
|
1240
|
-
|
|
1241
|
-
/**
|
|
1242
|
-
* The output data of the top-level finite state.
|
|
1243
|
-
*/
|
|
1244
|
-
|
|
1245
|
-
/**
|
|
1246
|
-
* The enabled state nodes representative of the state value.
|
|
1247
|
-
*/
|
|
1248
|
-
|
|
1249
|
-
/**
|
|
1250
|
-
* An object mapping actor names to spawned/invoked actors.
|
|
1251
|
-
*/
|
|
1252
|
-
|
|
1253
|
-
/**
|
|
1254
|
-
* Creates a new State instance for the given `stateValue` and `context`.
|
|
1255
|
-
* @param stateValue
|
|
1256
|
-
* @param context
|
|
1257
|
-
*/
|
|
1258
|
-
static from(stateValue, context = {}, machine) {
|
|
1259
|
-
if (stateValue instanceof State) {
|
|
1260
|
-
if (stateValue.context !== context) {
|
|
1261
|
-
return new State({
|
|
1262
|
-
value: stateValue.value,
|
|
1263
|
-
context,
|
|
1264
|
-
meta: {},
|
|
1265
|
-
configuration: [],
|
|
1266
|
-
// TODO: fix,
|
|
1267
|
-
children: {},
|
|
1268
|
-
status: 'active'
|
|
1269
|
-
}, machine);
|
|
1270
|
-
}
|
|
1271
|
-
return stateValue;
|
|
1272
|
-
}
|
|
1273
|
-
const configuration = getConfiguration(getStateNodes(machine.root, stateValue));
|
|
1274
|
-
return new State({
|
|
1275
|
-
value: stateValue,
|
|
1276
|
-
context,
|
|
1277
|
-
meta: undefined,
|
|
1278
|
-
configuration: Array.from(configuration),
|
|
1279
|
-
children: {},
|
|
1280
|
-
status: 'active'
|
|
1281
|
-
}, machine);
|
|
1282
|
-
}
|
|
1283
|
-
|
|
1284
|
-
/**
|
|
1285
|
-
* Creates a new `State` instance that represents the current state of a running machine.
|
|
1286
|
-
*
|
|
1287
|
-
* @param config
|
|
1288
|
-
*/
|
|
1289
|
-
constructor(config, machine) {
|
|
1290
|
-
this.machine = machine;
|
|
1291
|
-
this.tags = void 0;
|
|
1292
|
-
this.value = void 0;
|
|
1293
|
-
this.status = void 0;
|
|
1294
|
-
this.error = void 0;
|
|
1295
|
-
this.context = void 0;
|
|
1296
|
-
this.historyValue = {};
|
|
1297
|
-
this.configuration = void 0;
|
|
1298
|
-
this.children = void 0;
|
|
1299
|
-
this.context = config.context;
|
|
1300
|
-
this.historyValue = config.historyValue || {};
|
|
1301
|
-
this.matches = this.matches.bind(this);
|
|
1302
|
-
this.toStrings = this.toStrings.bind(this);
|
|
1303
|
-
this.configuration = config.configuration ?? Array.from(getConfiguration(getStateNodes(machine.root, config.value)));
|
|
1304
|
-
this.children = config.children;
|
|
1305
|
-
this.value = getStateValue(machine.root, this.configuration);
|
|
1306
|
-
this.tags = new Set(flatten(this.configuration.map(sn => sn.tags)));
|
|
1307
|
-
this.status = config.status;
|
|
1308
|
-
this.output = config.output;
|
|
1309
|
-
this.error = config.error;
|
|
1310
|
-
}
|
|
1311
1223
|
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1224
|
+
function createMachineSnapshot(config, machine) {
|
|
1225
|
+
return {
|
|
1226
|
+
status: config.status,
|
|
1227
|
+
output: config.output,
|
|
1228
|
+
error: config.error,
|
|
1229
|
+
machine,
|
|
1230
|
+
context: config.context,
|
|
1231
|
+
configuration: config.configuration,
|
|
1232
|
+
value: getStateValue(machine.root, config.configuration),
|
|
1233
|
+
tags: new Set(flatten(config.configuration.map(sn => sn.tags))),
|
|
1234
|
+
children: config.children,
|
|
1235
|
+
historyValue: config.historyValue || {},
|
|
1236
|
+
matches(parentStateValue) {
|
|
1237
|
+
return matchesState(parentStateValue, this.value);
|
|
1238
|
+
},
|
|
1239
|
+
hasTag(tag) {
|
|
1240
|
+
return this.tags.has(tag);
|
|
1241
|
+
},
|
|
1242
|
+
can(event) {
|
|
1243
|
+
const transitionData = this.machine.getTransitionData(this, event);
|
|
1244
|
+
return !!transitionData?.length &&
|
|
1245
|
+
// Check that at least one transition is not forbidden
|
|
1246
|
+
transitionData.some(t => t.target !== undefined || t.actions.length);
|
|
1247
|
+
},
|
|
1248
|
+
get nextEvents() {
|
|
1249
|
+
return memo(this, 'nextEvents', () => {
|
|
1250
|
+
return [...new Set(flatten([...this.configuration.map(sn => sn.ownEvents)]))];
|
|
1251
|
+
});
|
|
1252
|
+
},
|
|
1253
|
+
get meta() {
|
|
1254
|
+
return this.configuration.reduce((acc, stateNode) => {
|
|
1255
|
+
if (stateNode.meta !== undefined) {
|
|
1256
|
+
acc[stateNode.id] = stateNode.meta;
|
|
1257
|
+
}
|
|
1258
|
+
return acc;
|
|
1259
|
+
}, {});
|
|
1260
|
+
},
|
|
1261
|
+
toJSON() {
|
|
1262
|
+
const {
|
|
1263
|
+
configuration,
|
|
1264
|
+
tags,
|
|
1265
|
+
machine,
|
|
1266
|
+
nextEvents,
|
|
1267
|
+
toJSON,
|
|
1268
|
+
can,
|
|
1269
|
+
hasTag,
|
|
1270
|
+
matches,
|
|
1271
|
+
...jsonValues
|
|
1272
|
+
} = this;
|
|
1273
|
+
return {
|
|
1274
|
+
...jsonValues,
|
|
1275
|
+
tags: Array.from(tags)
|
|
1276
|
+
};
|
|
1320
1277
|
}
|
|
1321
|
-
|
|
1322
|
-
return valueKeys.concat(...valueKeys.map(key => this.toStrings(stateValue[key]).map(s => key + STATE_DELIMITER + s)));
|
|
1323
|
-
}
|
|
1324
|
-
toJSON() {
|
|
1325
|
-
const {
|
|
1326
|
-
configuration,
|
|
1327
|
-
tags,
|
|
1328
|
-
machine,
|
|
1329
|
-
...jsonValues
|
|
1330
|
-
} = this;
|
|
1331
|
-
return {
|
|
1332
|
-
...jsonValues,
|
|
1333
|
-
tags: Array.from(tags),
|
|
1334
|
-
meta: this.meta
|
|
1335
|
-
};
|
|
1336
|
-
}
|
|
1337
|
-
|
|
1338
|
-
/**
|
|
1339
|
-
* Whether the current state value is a subset of the given parent state value.
|
|
1340
|
-
* @param parentStateValue
|
|
1341
|
-
*/
|
|
1342
|
-
matches(parentStateValue) {
|
|
1343
|
-
return matchesState(parentStateValue, this.value);
|
|
1344
|
-
}
|
|
1345
|
-
|
|
1346
|
-
/**
|
|
1347
|
-
* Whether the current state configuration has a state node with the specified `tag`.
|
|
1348
|
-
* @param tag
|
|
1349
|
-
*/
|
|
1350
|
-
hasTag(tag) {
|
|
1351
|
-
return this.tags.has(tag);
|
|
1352
|
-
}
|
|
1353
|
-
|
|
1354
|
-
/**
|
|
1355
|
-
* Determines whether sending the `event` will cause a non-forbidden transition
|
|
1356
|
-
* to be selected, even if the transitions have no actions nor
|
|
1357
|
-
* change the state value.
|
|
1358
|
-
*
|
|
1359
|
-
* @param event The event to test
|
|
1360
|
-
* @returns Whether the event will cause a transition
|
|
1361
|
-
*/
|
|
1362
|
-
can(event) {
|
|
1363
|
-
const transitionData = this.machine.getTransitionData(this, event);
|
|
1364
|
-
return !!transitionData?.length &&
|
|
1365
|
-
// Check that at least one transition is not forbidden
|
|
1366
|
-
transitionData.some(t => t.target !== undefined || t.actions.length);
|
|
1367
|
-
}
|
|
1368
|
-
|
|
1369
|
-
/**
|
|
1370
|
-
* The next events that will cause a transition from the current state.
|
|
1371
|
-
*/
|
|
1372
|
-
get nextEvents() {
|
|
1373
|
-
return memo(this, 'nextEvents', () => {
|
|
1374
|
-
return [...new Set(flatten([...this.configuration.map(sn => sn.ownEvents)]))];
|
|
1375
|
-
});
|
|
1376
|
-
}
|
|
1377
|
-
get meta() {
|
|
1378
|
-
return this.configuration.reduce((acc, stateNode) => {
|
|
1379
|
-
if (stateNode.meta !== undefined) {
|
|
1380
|
-
acc[stateNode.id] = stateNode.meta;
|
|
1381
|
-
}
|
|
1382
|
-
return acc;
|
|
1383
|
-
}, {});
|
|
1384
|
-
}
|
|
1278
|
+
};
|
|
1385
1279
|
}
|
|
1386
|
-
function
|
|
1387
|
-
return
|
|
1280
|
+
function cloneMachineSnapshot(state, config = {}) {
|
|
1281
|
+
return createMachineSnapshot(
|
|
1282
|
+
// TODO: it's wasteful that this spread triggers getters
|
|
1283
|
+
{
|
|
1388
1284
|
...state,
|
|
1389
1285
|
...config
|
|
1390
1286
|
}, state.machine);
|
|
@@ -1396,6 +1292,11 @@ function getPersistedState(state, options) {
|
|
|
1396
1292
|
machine,
|
|
1397
1293
|
children,
|
|
1398
1294
|
context,
|
|
1295
|
+
can,
|
|
1296
|
+
hasTag,
|
|
1297
|
+
matches,
|
|
1298
|
+
toJSON,
|
|
1299
|
+
nextEvents,
|
|
1399
1300
|
...jsonValues
|
|
1400
1301
|
} = state;
|
|
1401
1302
|
const childrenJson = {};
|
|
@@ -1493,4 +1394,4 @@ function raise(eventOrExpr, options) {
|
|
|
1493
1394
|
return raise;
|
|
1494
1395
|
}
|
|
1495
1396
|
|
|
1496
|
-
export { raise as A, stop as B, spawn as C,
|
|
1397
|
+
export { raise as A, stop as B, spawn as C, formatTransition as a, formatInitialTransition as b, getCandidates as c, getConfiguration as d, evaluateGuard as e, formatTransitions as f, getDelayedTransitions as g, getStateNodes as h, createMachineSnapshot as i, isInFinalState as j, cloneMachineSnapshot as k, macrostep as l, memo as m, resolveActionsAndContext as n, microstep as o, getInitialStateNodes as p, isStateId as q, resolveStateValue as r, getStateNodeByPath as s, transitionNode as t, getPersistedState as u, and as v, not as w, or as x, stateIn as y, cancel as z };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { P as ProcessingStatus, h as createErrorActorEvent, r as resolveReferencedActor, d as createActor, t as toArray,
|
|
1
|
+
import { k as cloneMachineSnapshot, e as evaluateGuard } from './raise-d2084327.esm.js';
|
|
2
|
+
import { P as ProcessingStatus, h as createErrorActorEvent, r as resolveReferencedActor, d as createActor, t as toArray, v as XSTATE_ERROR } from './interpreter-3d0c0ff2.esm.js';
|
|
3
3
|
|
|
4
4
|
function createSpawner(actorScope, {
|
|
5
5
|
machine,
|
|
@@ -110,7 +110,7 @@ function resolveAssign(actorScope, state, actionArgs, actionParams, {
|
|
|
110
110
|
}
|
|
111
111
|
}
|
|
112
112
|
const updatedContext = Object.assign({}, state.context, partialUpdate);
|
|
113
|
-
return [
|
|
113
|
+
return [cloneMachineSnapshot(state, {
|
|
114
114
|
context: updatedContext,
|
|
115
115
|
children: Object.keys(spawnedChildren).length ? {
|
|
116
116
|
...state.children,
|
|
@@ -245,6 +245,8 @@ function pure(getActions) {
|
|
|
245
245
|
|
|
246
246
|
// TODO: remove once TS fixes this type-widening issue
|
|
247
247
|
|
|
248
|
+
// TODO: replace with AnyMachineSnapshot
|
|
249
|
+
|
|
248
250
|
// TODO: possibly refactor this somehow, use even a simpler type, and maybe even make `machine.options` private or something
|
|
249
251
|
|
|
250
252
|
let SpecialTargets = /*#__PURE__*/function (SpecialTargets) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { P as ProcessingStatus, h as createErrorActorEvent, r as resolveReferencedActor, d as createActor, t as toArray,
|
|
1
|
+
import { k as cloneMachineSnapshot, e as evaluateGuard } from './raise-51ae36e5.development.esm.js';
|
|
2
|
+
import { P as ProcessingStatus, h as createErrorActorEvent, r as resolveReferencedActor, d as createActor, t as toArray, v as XSTATE_ERROR } from './interpreter-f2620ea7.development.esm.js';
|
|
3
3
|
|
|
4
4
|
function createSpawner(actorScope, {
|
|
5
5
|
machine,
|
|
@@ -110,7 +110,7 @@ function resolveAssign(actorScope, state, actionArgs, actionParams, {
|
|
|
110
110
|
}
|
|
111
111
|
}
|
|
112
112
|
const updatedContext = Object.assign({}, state.context, partialUpdate);
|
|
113
|
-
return [
|
|
113
|
+
return [cloneMachineSnapshot(state, {
|
|
114
114
|
context: updatedContext,
|
|
115
115
|
children: Object.keys(spawnedChildren).length ? {
|
|
116
116
|
...state.children,
|
|
@@ -257,6 +257,8 @@ function pure(getActions) {
|
|
|
257
257
|
|
|
258
258
|
// TODO: remove once TS fixes this type-widening issue
|
|
259
259
|
|
|
260
|
+
// TODO: replace with AnyMachineSnapshot
|
|
261
|
+
|
|
260
262
|
// TODO: possibly refactor this somehow, use even a simpler type, and maybe even make `machine.options` private or something
|
|
261
263
|
|
|
262
264
|
let SpecialTargets = /*#__PURE__*/function (SpecialTargets) {
|