xstate 5.0.0-beta.40 → 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 +1 -1
- package/actors/dist/xstate-actors.umd.min.js.map +1 -1
- package/dist/declarations/src/State.d.ts +36 -43
- package/dist/declarations/src/StateMachine.d.ts +13 -30
- package/dist/declarations/src/StateNode.d.ts +2 -2
- package/dist/declarations/src/index.d.ts +4 -5
- package/dist/declarations/src/interpreter.d.ts +14 -10
- package/dist/declarations/src/stateUtils.d.ts +7 -8
- package/dist/declarations/src/types.d.ts +114 -22
- package/dist/{interpreter-bae5c279.development.cjs.js → interpreter-23e4041c.development.cjs.js} +49 -42
- package/dist/{interpreter-ed0fac7e.esm.js → interpreter-3d0c0ff2.esm.js} +49 -40
- package/dist/{interpreter-586abde4.cjs.js → interpreter-b6bdd134.cjs.js} +49 -42
- package/dist/{interpreter-410d7ca9.development.esm.js → interpreter-f2620ea7.development.esm.js} +49 -40
- package/dist/{raise-37f9f3b8.development.esm.js → raise-51ae36e5.development.esm.js} +84 -183
- package/dist/{raise-27909189.cjs.js → raise-6b64c553.cjs.js} +81 -181
- package/dist/{raise-8325e2df.development.cjs.js → raise-8f482ce9.development.cjs.js} +85 -185
- package/dist/{raise-2b2fdec3.esm.js → raise-d2084327.esm.js} +80 -179
- package/dist/{send-59f66c58.esm.js → send-4e732fa5.esm.js} +7 -6
- package/dist/{send-f6b49072.development.esm.js → send-7a350091.development.esm.js} +7 -6
- package/dist/{send-4fdf275e.cjs.js → send-85b562d8.cjs.js} +7 -6
- package/dist/{send-c45d0d2c.development.cjs.js → send-cc8f864e.development.cjs.js} +7 -6
- package/dist/xstate.cjs.js +27 -56
- package/dist/xstate.cjs.mjs +0 -4
- package/dist/xstate.development.cjs.js +27 -56
- package/dist/xstate.development.cjs.mjs +0 -4
- package/dist/xstate.development.esm.js +31 -56
- package/dist/xstate.esm.js +31 -56
- 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,4 +1,4 @@
|
|
|
1
|
-
import { r as resolveReferencedActor, d as createActor,
|
|
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, W as WILDCARD, X as XSTATE_STOP, q as XSTATE_INIT, s as createAfterEvent, u as flatten, f as matchesState, $ as $$ACTOR_TYPE } from './interpreter-f2620ea7.development.esm.js';
|
|
2
2
|
|
|
3
3
|
const cache = new WeakMap();
|
|
4
4
|
function memo(object, key, fn) {
|
|
@@ -61,7 +61,7 @@ function resolveSpawn(actorScope, state, actionArgs, _actionParams, {
|
|
|
61
61
|
const configuredInput = input || referenced.input;
|
|
62
62
|
actorRef = createActor(referenced.src, {
|
|
63
63
|
id: resolvedId,
|
|
64
|
-
src
|
|
64
|
+
src,
|
|
65
65
|
parent: actorScope?.self,
|
|
66
66
|
systemId,
|
|
67
67
|
input: typeof configuredInput === 'function' ? configuredInput({
|
|
@@ -87,7 +87,7 @@ function resolveSpawn(actorScope, state, actionArgs, _actionParams, {
|
|
|
87
87
|
if (!actorRef) {
|
|
88
88
|
console.warn(`Actor type '${src}' not found in machine '${actorScope.id}'.`);
|
|
89
89
|
}
|
|
90
|
-
return [
|
|
90
|
+
return [cloneMachineSnapshot(state, {
|
|
91
91
|
children: {
|
|
92
92
|
...state.children,
|
|
93
93
|
[resolvedId]: actorRef
|
|
@@ -105,7 +105,7 @@ function executeSpawn(actorScope, {
|
|
|
105
105
|
return;
|
|
106
106
|
}
|
|
107
107
|
actorScope.defer(() => {
|
|
108
|
-
if (actorRef.
|
|
108
|
+
if (actorRef._processingStatus === ProcessingStatus.Stopped) {
|
|
109
109
|
return;
|
|
110
110
|
}
|
|
111
111
|
try {
|
|
@@ -150,7 +150,7 @@ function resolveStop(_, state, args, actionParams, {
|
|
|
150
150
|
};
|
|
151
151
|
delete children[resolvedActorRef.id];
|
|
152
152
|
}
|
|
153
|
-
return [
|
|
153
|
+
return [cloneMachineSnapshot(state, {
|
|
154
154
|
children
|
|
155
155
|
}), resolvedActorRef];
|
|
156
156
|
}
|
|
@@ -166,7 +166,7 @@ function executeStop(actorScope, actorRef) {
|
|
|
166
166
|
|
|
167
167
|
// this allows us to prevent an actor from being started if it gets stopped within the same macrostep
|
|
168
168
|
// this can happen, for example, when the invoking state is being exited immediately by an always transition
|
|
169
|
-
if (actorRef.
|
|
169
|
+
if (actorRef._processingStatus !== ProcessingStatus.Running) {
|
|
170
170
|
actorScope.stopChild(actorRef);
|
|
171
171
|
return;
|
|
172
172
|
}
|
|
@@ -683,10 +683,9 @@ function getStateNodeByPath(stateNode, statePath) {
|
|
|
683
683
|
/**
|
|
684
684
|
* Returns the state nodes represented by the current state value.
|
|
685
685
|
*
|
|
686
|
-
* @param
|
|
686
|
+
* @param stateValue The state value or State instance
|
|
687
687
|
*/
|
|
688
|
-
function getStateNodes(stateNode,
|
|
689
|
-
const stateValue = state instanceof State ? state.value : toStateValue(state);
|
|
688
|
+
function getStateNodes(stateNode, stateValue) {
|
|
690
689
|
if (typeof stateValue === 'string') {
|
|
691
690
|
return [stateNode, stateNode.states[stateValue]];
|
|
692
691
|
}
|
|
@@ -907,7 +906,7 @@ function microstep(transitions, currentState, actorScope, event, isInitial, inte
|
|
|
907
906
|
if (historyValue === currentState.historyValue && areConfigurationsEqual(currentState.configuration, mutConfiguration)) {
|
|
908
907
|
return nextState;
|
|
909
908
|
}
|
|
910
|
-
return
|
|
909
|
+
return cloneMachineSnapshot(nextState, {
|
|
911
910
|
configuration: nextConfiguration,
|
|
912
911
|
historyValue
|
|
913
912
|
});
|
|
@@ -971,9 +970,9 @@ function enterStates(currentState, event, actorScope, filteredTransitions, mutCo
|
|
|
971
970
|
if (ancestorMarker) {
|
|
972
971
|
continue;
|
|
973
972
|
}
|
|
974
|
-
nextState =
|
|
973
|
+
nextState = cloneMachineSnapshot(nextState, {
|
|
975
974
|
status: 'done',
|
|
976
|
-
output: getMachineOutput(nextState, event, actorScope,
|
|
975
|
+
output: getMachineOutput(nextState, event, actorScope, nextState.machine.root, rootCompletionNode)
|
|
977
976
|
});
|
|
978
977
|
}
|
|
979
978
|
}
|
|
@@ -1127,7 +1126,7 @@ function resolveActionsAndContextWorker(currentState, event, actorScope, actions
|
|
|
1127
1126
|
event
|
|
1128
1127
|
}) : action.params : undefined;
|
|
1129
1128
|
if (!('resolve' in resolvedAction)) {
|
|
1130
|
-
if (actorScope?.self.
|
|
1129
|
+
if (actorScope?.self._processingStatus === ProcessingStatus.Running) {
|
|
1131
1130
|
resolvedAction(actionArgs, actionParams);
|
|
1132
1131
|
} else {
|
|
1133
1132
|
actorScope?.defer(() => {
|
|
@@ -1145,7 +1144,7 @@ function resolveActionsAndContextWorker(currentState, event, actorScope, actions
|
|
|
1145
1144
|
retries?.push([builtinAction, params]);
|
|
1146
1145
|
}
|
|
1147
1146
|
if ('execute' in builtinAction) {
|
|
1148
|
-
if (actorScope?.self.
|
|
1147
|
+
if (actorScope?.self._processingStatus === ProcessingStatus.Running) {
|
|
1149
1148
|
builtinAction.execute(actorScope, params);
|
|
1150
1149
|
} else {
|
|
1151
1150
|
actorScope?.defer(builtinAction.execute.bind(null, actorScope, params));
|
|
@@ -1177,7 +1176,7 @@ function macrostep(state, event, actorScope, internalQueue = []) {
|
|
|
1177
1176
|
|
|
1178
1177
|
// Handle stop event
|
|
1179
1178
|
if (event.type === XSTATE_STOP) {
|
|
1180
|
-
nextState =
|
|
1179
|
+
nextState = cloneMachineSnapshot(stopChildren(nextState, event, actorScope), {
|
|
1181
1180
|
status: 'stopped'
|
|
1182
1181
|
});
|
|
1183
1182
|
states.push(nextState);
|
|
@@ -1255,194 +1254,96 @@ function resolveStateValue(rootNode, stateValue) {
|
|
|
1255
1254
|
const configuration = getConfiguration(getStateNodes(rootNode, stateValue));
|
|
1256
1255
|
return getStateValue(rootNode, [...configuration]);
|
|
1257
1256
|
}
|
|
1258
|
-
function getInitialConfiguration(rootNode) {
|
|
1259
|
-
const configuration = [];
|
|
1260
|
-
const initialTransition = rootNode.initial;
|
|
1261
|
-
const statesToEnter = new Set();
|
|
1262
|
-
const statesForDefaultEntry = new Set([rootNode]);
|
|
1263
|
-
computeEntrySet([initialTransition], {}, statesForDefaultEntry, statesToEnter);
|
|
1264
|
-
for (const stateNodeToEnter of [...statesToEnter].sort((a, b) => a.order - b.order)) {
|
|
1265
|
-
configuration.push(stateNodeToEnter);
|
|
1266
|
-
}
|
|
1267
|
-
return configuration;
|
|
1268
|
-
}
|
|
1269
|
-
|
|
1270
|
-
class State {
|
|
1271
|
-
/**
|
|
1272
|
-
* Indicates whether the state is a final state.
|
|
1273
|
-
*/
|
|
1274
|
-
|
|
1275
|
-
/**
|
|
1276
|
-
* The output data of the top-level finite state.
|
|
1277
|
-
*/
|
|
1278
|
-
|
|
1279
|
-
/**
|
|
1280
|
-
* The enabled state nodes representative of the state value.
|
|
1281
|
-
*/
|
|
1282
|
-
|
|
1283
|
-
/**
|
|
1284
|
-
* An object mapping actor names to spawned/invoked actors.
|
|
1285
|
-
*/
|
|
1286
|
-
|
|
1287
|
-
/**
|
|
1288
|
-
* Creates a new State instance for the given `stateValue` and `context`.
|
|
1289
|
-
* @param stateValue
|
|
1290
|
-
* @param context
|
|
1291
|
-
*/
|
|
1292
|
-
static from(stateValue, context = {}, machine) {
|
|
1293
|
-
if (stateValue instanceof State) {
|
|
1294
|
-
if (stateValue.context !== context) {
|
|
1295
|
-
return new State({
|
|
1296
|
-
value: stateValue.value,
|
|
1297
|
-
context,
|
|
1298
|
-
meta: {},
|
|
1299
|
-
configuration: [],
|
|
1300
|
-
// TODO: fix,
|
|
1301
|
-
children: {},
|
|
1302
|
-
status: 'active'
|
|
1303
|
-
}, machine);
|
|
1304
|
-
}
|
|
1305
|
-
return stateValue;
|
|
1306
|
-
}
|
|
1307
|
-
const configuration = getConfiguration(getStateNodes(machine.root, stateValue));
|
|
1308
|
-
return new State({
|
|
1309
|
-
value: stateValue,
|
|
1310
|
-
context,
|
|
1311
|
-
meta: undefined,
|
|
1312
|
-
configuration: Array.from(configuration),
|
|
1313
|
-
children: {},
|
|
1314
|
-
status: 'active'
|
|
1315
|
-
}, machine);
|
|
1316
|
-
}
|
|
1317
|
-
|
|
1318
|
-
/**
|
|
1319
|
-
* Creates a new `State` instance that represents the current state of a running machine.
|
|
1320
|
-
*
|
|
1321
|
-
* @param config
|
|
1322
|
-
*/
|
|
1323
|
-
constructor(config, machine) {
|
|
1324
|
-
this.machine = machine;
|
|
1325
|
-
this.tags = void 0;
|
|
1326
|
-
this.value = void 0;
|
|
1327
|
-
this.status = void 0;
|
|
1328
|
-
this.error = void 0;
|
|
1329
|
-
this.context = void 0;
|
|
1330
|
-
this.historyValue = {};
|
|
1331
|
-
this.configuration = void 0;
|
|
1332
|
-
this.children = void 0;
|
|
1333
|
-
this.context = config.context;
|
|
1334
|
-
this.historyValue = config.historyValue || {};
|
|
1335
|
-
this.matches = this.matches.bind(this);
|
|
1336
|
-
this.toStrings = this.toStrings.bind(this);
|
|
1337
|
-
this.configuration = config.configuration ?? Array.from(getConfiguration(getStateNodes(machine.root, config.value)));
|
|
1338
|
-
this.children = config.children;
|
|
1339
|
-
this.value = getStateValue(machine.root, this.configuration);
|
|
1340
|
-
this.tags = new Set(flatten(this.configuration.map(sn => sn.tags)));
|
|
1341
|
-
this.status = config.status;
|
|
1342
|
-
this.output = config.output;
|
|
1343
|
-
this.error = config.error;
|
|
1344
|
-
}
|
|
1345
|
-
|
|
1346
|
-
/**
|
|
1347
|
-
* Returns an array of all the string leaf state node paths.
|
|
1348
|
-
* @param stateValue
|
|
1349
|
-
* @param delimiter The character(s) that separate each subpath in the string state node path.
|
|
1350
|
-
*/
|
|
1351
|
-
toStrings(stateValue = this.value) {
|
|
1352
|
-
if (typeof stateValue === 'string') {
|
|
1353
|
-
return [stateValue];
|
|
1354
|
-
}
|
|
1355
|
-
const valueKeys = Object.keys(stateValue);
|
|
1356
|
-
return valueKeys.concat(...valueKeys.map(key => this.toStrings(stateValue[key]).map(s => key + STATE_DELIMITER + s)));
|
|
1357
|
-
}
|
|
1358
|
-
toJSON() {
|
|
1359
|
-
const {
|
|
1360
|
-
configuration,
|
|
1361
|
-
tags,
|
|
1362
|
-
machine,
|
|
1363
|
-
...jsonValues
|
|
1364
|
-
} = this;
|
|
1365
|
-
return {
|
|
1366
|
-
...jsonValues,
|
|
1367
|
-
tags: Array.from(tags),
|
|
1368
|
-
meta: this.meta
|
|
1369
|
-
};
|
|
1370
|
-
}
|
|
1371
|
-
|
|
1372
|
-
/**
|
|
1373
|
-
* Whether the current state value is a subset of the given parent state value.
|
|
1374
|
-
* @param parentStateValue
|
|
1375
|
-
*/
|
|
1376
|
-
matches(parentStateValue) {
|
|
1377
|
-
return matchesState(parentStateValue, this.value);
|
|
1378
|
-
}
|
|
1379
|
-
|
|
1380
|
-
/**
|
|
1381
|
-
* Whether the current state configuration has a state node with the specified `tag`.
|
|
1382
|
-
* @param tag
|
|
1383
|
-
*/
|
|
1384
|
-
hasTag(tag) {
|
|
1385
|
-
return this.tags.has(tag);
|
|
1386
|
-
}
|
|
1387
1257
|
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
}
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
get nextEvents() {
|
|
1410
|
-
return memo(this, 'nextEvents', () => {
|
|
1411
|
-
return [...new Set(flatten([...this.configuration.map(sn => sn.ownEvents)]))];
|
|
1412
|
-
});
|
|
1413
|
-
}
|
|
1414
|
-
get meta() {
|
|
1415
|
-
return this.configuration.reduce((acc, stateNode) => {
|
|
1416
|
-
if (stateNode.meta !== undefined) {
|
|
1417
|
-
acc[stateNode.id] = stateNode.meta;
|
|
1258
|
+
function createMachineSnapshot(config, machine) {
|
|
1259
|
+
return {
|
|
1260
|
+
status: config.status,
|
|
1261
|
+
output: config.output,
|
|
1262
|
+
error: config.error,
|
|
1263
|
+
machine,
|
|
1264
|
+
context: config.context,
|
|
1265
|
+
configuration: config.configuration,
|
|
1266
|
+
value: getStateValue(machine.root, config.configuration),
|
|
1267
|
+
tags: new Set(flatten(config.configuration.map(sn => sn.tags))),
|
|
1268
|
+
children: config.children,
|
|
1269
|
+
historyValue: config.historyValue || {},
|
|
1270
|
+
matches(parentStateValue) {
|
|
1271
|
+
return matchesState(parentStateValue, this.value);
|
|
1272
|
+
},
|
|
1273
|
+
hasTag(tag) {
|
|
1274
|
+
return this.tags.has(tag);
|
|
1275
|
+
},
|
|
1276
|
+
can(event) {
|
|
1277
|
+
if (!this.machine) {
|
|
1278
|
+
console.warn(`state.can(...) used outside of a machine-created State object; this will always return false.`);
|
|
1418
1279
|
}
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1280
|
+
const transitionData = this.machine.getTransitionData(this, event);
|
|
1281
|
+
return !!transitionData?.length &&
|
|
1282
|
+
// Check that at least one transition is not forbidden
|
|
1283
|
+
transitionData.some(t => t.target !== undefined || t.actions.length);
|
|
1284
|
+
},
|
|
1285
|
+
get nextEvents() {
|
|
1286
|
+
return memo(this, 'nextEvents', () => {
|
|
1287
|
+
return [...new Set(flatten([...this.configuration.map(sn => sn.ownEvents)]))];
|
|
1288
|
+
});
|
|
1289
|
+
},
|
|
1290
|
+
get meta() {
|
|
1291
|
+
return this.configuration.reduce((acc, stateNode) => {
|
|
1292
|
+
if (stateNode.meta !== undefined) {
|
|
1293
|
+
acc[stateNode.id] = stateNode.meta;
|
|
1294
|
+
}
|
|
1295
|
+
return acc;
|
|
1296
|
+
}, {});
|
|
1297
|
+
},
|
|
1298
|
+
toJSON() {
|
|
1299
|
+
const {
|
|
1300
|
+
configuration,
|
|
1301
|
+
tags,
|
|
1302
|
+
machine,
|
|
1303
|
+
nextEvents,
|
|
1304
|
+
toJSON,
|
|
1305
|
+
can,
|
|
1306
|
+
hasTag,
|
|
1307
|
+
matches,
|
|
1308
|
+
...jsonValues
|
|
1309
|
+
} = this;
|
|
1310
|
+
return {
|
|
1311
|
+
...jsonValues,
|
|
1312
|
+
tags: Array.from(tags)
|
|
1313
|
+
};
|
|
1314
|
+
}
|
|
1315
|
+
};
|
|
1422
1316
|
}
|
|
1423
|
-
function
|
|
1424
|
-
return
|
|
1317
|
+
function cloneMachineSnapshot(state, config = {}) {
|
|
1318
|
+
return createMachineSnapshot(
|
|
1319
|
+
// TODO: it's wasteful that this spread triggers getters
|
|
1320
|
+
{
|
|
1425
1321
|
...state,
|
|
1426
1322
|
...config
|
|
1427
1323
|
}, state.machine);
|
|
1428
1324
|
}
|
|
1429
|
-
function getPersistedState(state) {
|
|
1325
|
+
function getPersistedState(state, options) {
|
|
1430
1326
|
const {
|
|
1431
1327
|
configuration,
|
|
1432
1328
|
tags,
|
|
1433
1329
|
machine,
|
|
1434
1330
|
children,
|
|
1435
1331
|
context,
|
|
1332
|
+
can,
|
|
1333
|
+
hasTag,
|
|
1334
|
+
matches,
|
|
1335
|
+
toJSON,
|
|
1336
|
+
nextEvents,
|
|
1436
1337
|
...jsonValues
|
|
1437
1338
|
} = state;
|
|
1438
1339
|
const childrenJson = {};
|
|
1439
1340
|
for (const id in children) {
|
|
1440
1341
|
const child = children[id];
|
|
1441
|
-
if (typeof child.src !== 'string') {
|
|
1342
|
+
if (typeof child.src !== 'string' && (!options || !('__unsafeAllowInlineActors' in options))) {
|
|
1442
1343
|
throw new Error('An inline child actor cannot be persisted.');
|
|
1443
1344
|
}
|
|
1444
1345
|
childrenJson[id] = {
|
|
1445
|
-
state: child.getPersistedState(),
|
|
1346
|
+
state: child.getPersistedState(options),
|
|
1446
1347
|
src: child.src,
|
|
1447
1348
|
systemId: child._systemId
|
|
1448
1349
|
};
|
|
@@ -1536,4 +1437,4 @@ function raise(eventOrExpr, options) {
|
|
|
1536
1437
|
return raise;
|
|
1537
1438
|
}
|
|
1538
1439
|
|
|
1539
|
-
export { raise as A, stop as B, spawn as C,
|
|
1440
|
+
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 };
|