xstate 5.0.0-beta.41 → 5.0.0-beta.43
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 +45 -1
- package/actors/dist/xstate-actors.development.cjs.js +45 -1
- package/actors/dist/xstate-actors.development.esm.js +45 -1
- package/actors/dist/xstate-actors.esm.js +45 -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 +12 -29
- package/dist/declarations/src/StateNode.d.ts +2 -2
- package/dist/declarations/src/actions/spawn.d.ts +3 -3
- package/dist/declarations/src/actors/promise.d.ts +53 -0
- 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 +153 -21
- package/dist/declarations/src/utils.d.ts +2 -8
- package/dist/{interpreter-fb2829f1.cjs.js → interpreter-36d5556e.cjs.js} +25 -19
- package/dist/{interpreter-70ed981b.development.cjs.js → interpreter-4e8e2a0d.development.cjs.js} +25 -19
- package/dist/{interpreter-480db258.esm.js → interpreter-63c80754.esm.js} +26 -19
- package/dist/{interpreter-936da690.development.esm.js → interpreter-80eb3bec.development.esm.js} +26 -19
- package/dist/{raise-5ab465ed.development.cjs.js → raise-23dea0d7.development.cjs.js} +101 -188
- package/dist/{raise-9d6921da.esm.js → raise-8dc8e1aa.esm.js} +95 -181
- package/dist/{raise-beae3fd3.cjs.js → raise-e0fe5c2d.cjs.js} +96 -183
- package/dist/{raise-f757be00.development.esm.js → raise-f4ad5a87.development.esm.js} +100 -186
- package/dist/{send-fb87a01a.development.cjs.js → send-0174c155.development.cjs.js} +10 -10
- package/dist/{send-b26e3812.development.esm.js → send-5d129d95.development.esm.js} +10 -10
- package/dist/{send-a931d1b8.esm.js → send-84e2e742.esm.js} +10 -10
- package/dist/{send-ca5f706c.cjs.js → send-87bbaaab.cjs.js} +10 -10
- package/dist/xstate.cjs.js +24 -50
- package/dist/xstate.cjs.mjs +0 -2
- package/dist/xstate.development.cjs.js +24 -50
- package/dist/xstate.development.cjs.mjs +0 -2
- package/dist/xstate.development.esm.js +28 -52
- package/dist/xstate.esm.js +28 -52
- 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, 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, $ as $$ACTOR_TYPE, f as matchesState } from './interpreter-63c80754.esm.js';
|
|
2
2
|
|
|
3
3
|
const cache = new WeakMap();
|
|
4
4
|
function memo(object, key, fn) {
|
|
@@ -47,25 +47,20 @@ function resolveSpawn(actorScope, state, actionArgs, _actionParams, {
|
|
|
47
47
|
input,
|
|
48
48
|
syncSnapshot
|
|
49
49
|
}) {
|
|
50
|
-
const
|
|
51
|
-
src,
|
|
52
|
-
input: undefined
|
|
53
|
-
};
|
|
50
|
+
const logic = typeof src === 'string' ? resolveReferencedActor(state.machine, src) : src;
|
|
54
51
|
const resolvedId = typeof id === 'function' ? id(actionArgs) : id;
|
|
55
52
|
let actorRef;
|
|
56
|
-
if (
|
|
57
|
-
|
|
58
|
-
const configuredInput = input || referenced.input;
|
|
59
|
-
actorRef = createActor(referenced.src, {
|
|
53
|
+
if (logic) {
|
|
54
|
+
actorRef = createActor(logic, {
|
|
60
55
|
id: resolvedId,
|
|
61
56
|
src,
|
|
62
57
|
parent: actorScope?.self,
|
|
63
58
|
systemId,
|
|
64
|
-
input: typeof
|
|
59
|
+
input: typeof input === 'function' ? input({
|
|
65
60
|
context: state.context,
|
|
66
61
|
event: actionArgs.event,
|
|
67
62
|
self: actorScope?.self
|
|
68
|
-
}) :
|
|
63
|
+
}) : input
|
|
69
64
|
});
|
|
70
65
|
if (syncSnapshot) {
|
|
71
66
|
actorRef.subscribe({
|
|
@@ -81,7 +76,7 @@ function resolveSpawn(actorScope, state, actionArgs, _actionParams, {
|
|
|
81
76
|
});
|
|
82
77
|
}
|
|
83
78
|
}
|
|
84
|
-
return [
|
|
79
|
+
return [cloneMachineSnapshot(state, {
|
|
85
80
|
children: {
|
|
86
81
|
...state.children,
|
|
87
82
|
[resolvedId]: actorRef
|
|
@@ -141,7 +136,7 @@ function resolveStop(_, state, args, actionParams, {
|
|
|
141
136
|
};
|
|
142
137
|
delete children[resolvedActorRef.id];
|
|
143
138
|
}
|
|
144
|
-
return [
|
|
139
|
+
return [cloneMachineSnapshot(state, {
|
|
145
140
|
children
|
|
146
141
|
}), resolvedActorRef];
|
|
147
142
|
}
|
|
@@ -652,10 +647,9 @@ function getStateNodeByPath(stateNode, statePath) {
|
|
|
652
647
|
/**
|
|
653
648
|
* Returns the state nodes represented by the current state value.
|
|
654
649
|
*
|
|
655
|
-
* @param
|
|
650
|
+
* @param stateValue The state value or State instance
|
|
656
651
|
*/
|
|
657
|
-
function getStateNodes(stateNode,
|
|
658
|
-
const stateValue = state instanceof State ? state.value : toStateValue(state);
|
|
652
|
+
function getStateNodes(stateNode, stateValue) {
|
|
659
653
|
if (typeof stateValue === 'string') {
|
|
660
654
|
return [stateNode, stateNode.states[stateValue]];
|
|
661
655
|
}
|
|
@@ -876,7 +870,7 @@ function microstep(transitions, currentState, actorScope, event, isInitial, inte
|
|
|
876
870
|
if (historyValue === currentState.historyValue && areConfigurationsEqual(currentState.configuration, mutConfiguration)) {
|
|
877
871
|
return nextState;
|
|
878
872
|
}
|
|
879
|
-
return
|
|
873
|
+
return cloneMachineSnapshot(nextState, {
|
|
880
874
|
configuration: nextConfiguration,
|
|
881
875
|
historyValue
|
|
882
876
|
});
|
|
@@ -940,9 +934,9 @@ function enterStates(currentState, event, actorScope, filteredTransitions, mutCo
|
|
|
940
934
|
if (ancestorMarker) {
|
|
941
935
|
continue;
|
|
942
936
|
}
|
|
943
|
-
nextState =
|
|
937
|
+
nextState = cloneMachineSnapshot(nextState, {
|
|
944
938
|
status: 'done',
|
|
945
|
-
output: getMachineOutput(nextState, event, actorScope,
|
|
939
|
+
output: getMachineOutput(nextState, event, actorScope, nextState.machine.root, rootCompletionNode)
|
|
946
940
|
});
|
|
947
941
|
}
|
|
948
942
|
}
|
|
@@ -1143,7 +1137,7 @@ function macrostep(state, event, actorScope, internalQueue = []) {
|
|
|
1143
1137
|
|
|
1144
1138
|
// Handle stop event
|
|
1145
1139
|
if (event.type === XSTATE_STOP) {
|
|
1146
|
-
nextState =
|
|
1140
|
+
nextState = cloneMachineSnapshot(stopChildren(nextState, event, actorScope), {
|
|
1147
1141
|
status: 'stopped'
|
|
1148
1142
|
});
|
|
1149
1143
|
states.push(nextState);
|
|
@@ -1221,170 +1215,85 @@ function resolveStateValue(rootNode, stateValue) {
|
|
|
1221
1215
|
const configuration = getConfiguration(getStateNodes(rootNode, stateValue));
|
|
1222
1216
|
return getStateValue(rootNode, [...configuration]);
|
|
1223
1217
|
}
|
|
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
1218
|
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1219
|
+
const machineSnapshotMatches = function matches(testValue) {
|
|
1220
|
+
return matchesState(testValue, this.value);
|
|
1221
|
+
};
|
|
1222
|
+
const machineSnapshotHasTag = function hasTag(tag) {
|
|
1223
|
+
return this.tags.has(tag);
|
|
1224
|
+
};
|
|
1225
|
+
const machineSnapshotCan = function can(event) {
|
|
1226
|
+
const transitionData = this.machine.getTransitionData(this, event);
|
|
1227
|
+
return !!transitionData?.length &&
|
|
1228
|
+
// Check that at least one transition is not forbidden
|
|
1229
|
+
transitionData.some(t => t.target !== undefined || t.actions.length);
|
|
1230
|
+
};
|
|
1231
|
+
const machineSnapshotToJSON = function toJSON() {
|
|
1232
|
+
const {
|
|
1233
|
+
configuration,
|
|
1234
|
+
tags,
|
|
1235
|
+
machine,
|
|
1236
|
+
nextEvents,
|
|
1237
|
+
toJSON,
|
|
1238
|
+
can,
|
|
1239
|
+
hasTag,
|
|
1240
|
+
matches,
|
|
1241
|
+
...jsonValues
|
|
1242
|
+
} = this;
|
|
1243
|
+
return {
|
|
1244
|
+
...jsonValues,
|
|
1245
|
+
tags: Array.from(tags)
|
|
1246
|
+
};
|
|
1247
|
+
};
|
|
1248
|
+
const machineSnapshotNextEvents = function nextEvents() {
|
|
1249
|
+
return memo(this, 'nextEvents', () => {
|
|
1250
|
+
return [...new Set(flatten([...this.configuration.map(sn => sn.ownEvents)]))];
|
|
1251
|
+
});
|
|
1252
|
+
};
|
|
1253
|
+
const machineSnapshotMeta = function nextEvents() {
|
|
1254
|
+
return this.configuration.reduce((acc, stateNode) => {
|
|
1255
|
+
if (stateNode.meta !== undefined) {
|
|
1256
|
+
acc[stateNode.id] = stateNode.meta;
|
|
1272
1257
|
}
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
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
|
-
|
|
1312
|
-
/**
|
|
1313
|
-
* Returns an array of all the string leaf state node paths.
|
|
1314
|
-
* @param stateValue
|
|
1315
|
-
* @param delimiter The character(s) that separate each subpath in the string state node path.
|
|
1316
|
-
*/
|
|
1317
|
-
toStrings(stateValue = this.value) {
|
|
1318
|
-
if (typeof stateValue === 'string') {
|
|
1319
|
-
return [stateValue];
|
|
1258
|
+
return acc;
|
|
1259
|
+
}, {});
|
|
1260
|
+
};
|
|
1261
|
+
function createMachineSnapshot(config, machine) {
|
|
1262
|
+
const snapshot = {
|
|
1263
|
+
status: config.status,
|
|
1264
|
+
output: config.output,
|
|
1265
|
+
error: config.error,
|
|
1266
|
+
machine,
|
|
1267
|
+
context: config.context,
|
|
1268
|
+
configuration: config.configuration,
|
|
1269
|
+
value: getStateValue(machine.root, config.configuration),
|
|
1270
|
+
tags: new Set(flatten(config.configuration.map(sn => sn.tags))),
|
|
1271
|
+
children: config.children,
|
|
1272
|
+
historyValue: config.historyValue || {},
|
|
1273
|
+
// this one is generic in the target and it's hard to create a matching non-generic source signature
|
|
1274
|
+
matches: machineSnapshotMatches,
|
|
1275
|
+
hasTag: machineSnapshotHasTag,
|
|
1276
|
+
can: machineSnapshotCan,
|
|
1277
|
+
toJSON: machineSnapshotToJSON
|
|
1278
|
+
};
|
|
1279
|
+
Object.defineProperties(snapshot, {
|
|
1280
|
+
nextEvents: {
|
|
1281
|
+
get: machineSnapshotNextEvents,
|
|
1282
|
+
configurable: true,
|
|
1283
|
+
enumerable: true
|
|
1284
|
+
},
|
|
1285
|
+
meta: {
|
|
1286
|
+
get: machineSnapshotMeta,
|
|
1287
|
+
configurable: true,
|
|
1288
|
+
enumerable: true
|
|
1320
1289
|
}
|
|
1321
|
-
|
|
1322
|
-
|
|
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
|
-
}
|
|
1290
|
+
});
|
|
1291
|
+
return snapshot;
|
|
1385
1292
|
}
|
|
1386
|
-
function
|
|
1387
|
-
return
|
|
1293
|
+
function cloneMachineSnapshot(state, config = {}) {
|
|
1294
|
+
return createMachineSnapshot(
|
|
1295
|
+
// TODO: it's wasteful that this spread triggers getters
|
|
1296
|
+
{
|
|
1388
1297
|
...state,
|
|
1389
1298
|
...config
|
|
1390
1299
|
}, state.machine);
|
|
@@ -1396,6 +1305,11 @@ function getPersistedState(state, options) {
|
|
|
1396
1305
|
machine,
|
|
1397
1306
|
children,
|
|
1398
1307
|
context,
|
|
1308
|
+
can,
|
|
1309
|
+
hasTag,
|
|
1310
|
+
matches,
|
|
1311
|
+
toJSON,
|
|
1312
|
+
nextEvents,
|
|
1399
1313
|
...jsonValues
|
|
1400
1314
|
} = state;
|
|
1401
1315
|
const childrenJson = {};
|
|
@@ -1493,4 +1407,4 @@ function raise(eventOrExpr, options) {
|
|
|
1493
1407
|
return raise;
|
|
1494
1408
|
}
|
|
1495
1409
|
|
|
1496
|
-
export { raise as A, stop as B, spawn as C,
|
|
1410
|
+
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 };
|