xstate 4.26.0 → 4.28.0
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/CHANGELOG.md +78 -1
- package/dist/xstate.interpreter.js +1 -1
- package/dist/xstate.js +1 -1
- package/dist/xstate.web.js +2 -2
- package/es/Actor.js +5 -5
- package/es/State.d.ts +5 -2
- package/es/State.js +10 -3
- package/es/StateNode.d.ts +2 -1
- package/es/StateNode.js +54 -59
- package/es/_virtual/_tslib.js +8 -4
- package/es/actions.d.ts +18 -2
- package/es/actions.js +22 -8
- package/es/devTools.d.ts +1 -2
- package/es/devTools.js +4 -0
- package/es/index.d.ts +2 -1
- package/es/index.js +2 -1
- package/es/interpreter.d.ts +0 -5
- package/es/interpreter.js +35 -25
- package/es/registry.js +1 -1
- package/es/stateUtils.d.ts +1 -1
- package/es/stateUtils.js +1 -1
- package/es/types.d.ts +10 -14
- package/es/utils.d.ts +7 -1
- package/es/utils.js +17 -10
- package/lib/Actor.js +4 -4
- package/lib/SimulatedClock.js +9 -5
- package/lib/State.d.ts +5 -2
- package/lib/State.js +10 -3
- package/lib/StateNode.d.ts +2 -1
- package/lib/StateNode.js +52 -57
- package/lib/_virtual/_tslib.js +8 -4
- package/lib/actions.d.ts +18 -2
- package/lib/actions.js +22 -7
- package/lib/devTools.d.ts +1 -2
- package/lib/devTools.js +4 -0
- package/lib/index.d.ts +2 -1
- package/lib/index.js +1 -0
- package/lib/interpreter.d.ts +0 -5
- package/lib/interpreter.js +34 -24
- package/lib/json.js +7 -7
- package/lib/model.js +14 -10
- package/lib/patterns.js +2 -2
- package/lib/registry.js +1 -1
- package/lib/scxml.js +29 -25
- package/lib/stateUtils.d.ts +1 -1
- package/lib/stateUtils.js +1 -1
- package/lib/types.d.ts +10 -14
- package/lib/utils.d.ts +7 -1
- package/lib/utils.js +18 -9
- package/package.json +3 -3
package/es/StateNode.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { __assign,
|
|
1
|
+
import { __assign, __spreadArray, __read, __values, __rest } from './_virtual/_tslib.js';
|
|
2
2
|
import { STATE_DELIMITER } from './constants.js';
|
|
3
3
|
import { IS_PRODUCTION } from './environment.js';
|
|
4
|
-
import { isFunction, mapValues, isArray, flatten, keys, toArray, toStateValue, isString, getEventType, matchesState, path, evaluateGuard, mapContext,
|
|
4
|
+
import { isFunction, mapValues, isArray, flatten, keys, toArray, toStateValue, isString, getEventType, toSCXMLEvent, matchesState, path, evaluateGuard, mapContext, pathToStateValue, isBuiltInEvent, partition, updateHistoryValue, toStatePath, mapFilterValues, warn, toStatePaths, nestedPath, normalizeTarget, toGuard, toTransitionConfigArray, isMachine, createInvokeId } from './utils.js';
|
|
5
5
|
import { SpecialTargets } from './types.js';
|
|
6
6
|
import { getAllStateNodes, getConfiguration, isInFinalState, getTagsFromConfiguration, has, getChildren, getValue, isLeafNode } from './stateUtils.js';
|
|
7
7
|
import { start as start$1, stop as stop$1, invoke, update, nullEvent, raise as raise$1, send as send$1 } from './actionTypes.js';
|
|
@@ -33,8 +33,8 @@ var validateArrayifiedTransitions = function (stateNode, event, transitions) {
|
|
|
33
33
|
var hasNonLastUnguardedTarget = transitions.slice(0, -1).some(function (transition) {
|
|
34
34
|
return !('cond' in transition) && !('in' in transition) && (isString(transition.target) || isMachine(transition.target));
|
|
35
35
|
});
|
|
36
|
-
var eventText = event === NULL_EVENT ? 'the transient event' : "event '"
|
|
37
|
-
warn(!hasNonLastUnguardedTarget, "One or more transitions for "
|
|
36
|
+
var eventText = event === NULL_EVENT ? 'the transient event' : "event '".concat(event, "'");
|
|
37
|
+
warn(!hasNonLastUnguardedTarget, "One or more transitions for ".concat(eventText, " on state '").concat(stateNode.id, "' are unreachable. ") + "Make sure that the default transition is the last one defined.");
|
|
38
38
|
};
|
|
39
39
|
|
|
40
40
|
var StateNode =
|
|
@@ -86,14 +86,14 @@ function () {
|
|
|
86
86
|
this.machine = this.parent ? this.parent.machine : this;
|
|
87
87
|
this.path = this.parent ? this.parent.path.concat(this.key) : [];
|
|
88
88
|
this.delimiter = this.config.delimiter || (this.parent ? this.parent.delimiter : STATE_DELIMITER);
|
|
89
|
-
this.id = this.config.id || __spreadArray([this.machine.key], __read(this.path)).join(this.delimiter);
|
|
89
|
+
this.id = this.config.id || __spreadArray([this.machine.key], __read(this.path), false).join(this.delimiter);
|
|
90
90
|
this.version = this.parent ? this.parent.version : this.config.version;
|
|
91
91
|
this.type = this.config.type || (this.config.parallel ? 'parallel' : this.config.states && keys(this.config.states).length ? 'compound' : this.config.history ? 'history' : 'atomic');
|
|
92
92
|
this.schema = this.parent ? this.machine.schema : (_a = this.config.schema) !== null && _a !== void 0 ? _a : {};
|
|
93
93
|
this.description = this.config.description;
|
|
94
94
|
|
|
95
95
|
if (!IS_PRODUCTION) {
|
|
96
|
-
warn(!('parallel' in this.config), "The \"parallel\" property is deprecated and will be removed in version 4.1. "
|
|
96
|
+
warn(!('parallel' in this.config), "The \"parallel\" property is deprecated and will be removed in version 4.1. ".concat(this.config.parallel ? "Replace with `type: 'parallel'`" : "Use `type: '".concat(this.type, "'`"), " in the config for state node '").concat(this.id, "' instead."));
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
this.initial = this.config.initial;
|
|
@@ -155,29 +155,30 @@ function () {
|
|
|
155
155
|
var _a, _b;
|
|
156
156
|
|
|
157
157
|
if (isMachine(invokeConfig)) {
|
|
158
|
-
|
|
158
|
+
var invokeId = createInvokeId(_this.id, i);
|
|
159
|
+
_this.machine.options.services = __assign((_a = {}, _a[invokeId] = invokeConfig, _a), _this.machine.options.services);
|
|
159
160
|
return toInvokeDefinition({
|
|
160
|
-
src:
|
|
161
|
-
id:
|
|
161
|
+
src: invokeId,
|
|
162
|
+
id: invokeId
|
|
162
163
|
});
|
|
163
164
|
} else if (isString(invokeConfig.src)) {
|
|
165
|
+
var invokeId = invokeConfig.id || createInvokeId(_this.id, i);
|
|
164
166
|
return toInvokeDefinition(__assign(__assign({}, invokeConfig), {
|
|
165
|
-
id:
|
|
167
|
+
id: invokeId,
|
|
166
168
|
src: invokeConfig.src
|
|
167
169
|
}));
|
|
168
170
|
} else if (isMachine(invokeConfig.src) || isFunction(invokeConfig.src)) {
|
|
169
|
-
var
|
|
170
|
-
|
|
171
|
-
_this.machine.options.services = __assign((_b = {}, _b[invokeSrc] = invokeConfig.src, _b), _this.machine.options.services);
|
|
171
|
+
var invokeId = invokeConfig.id || createInvokeId(_this.id, i);
|
|
172
|
+
_this.machine.options.services = __assign((_b = {}, _b[invokeId] = invokeConfig.src, _b), _this.machine.options.services);
|
|
172
173
|
return toInvokeDefinition(__assign(__assign({
|
|
173
|
-
id:
|
|
174
|
+
id: invokeId
|
|
174
175
|
}, invokeConfig), {
|
|
175
|
-
src:
|
|
176
|
+
src: invokeId
|
|
176
177
|
}));
|
|
177
178
|
} else {
|
|
178
179
|
var invokeSource = invokeConfig.src;
|
|
179
180
|
return toInvokeDefinition(__assign(__assign({
|
|
180
|
-
id:
|
|
181
|
+
id: createInvokeId(_this.id, i)
|
|
181
182
|
}, invokeConfig), {
|
|
182
183
|
src: invokeSource
|
|
183
184
|
}));
|
|
@@ -347,7 +348,7 @@ function () {
|
|
|
347
348
|
}
|
|
348
349
|
|
|
349
350
|
var mutateEntryExit = function (delay, i) {
|
|
350
|
-
var delayRef = isFunction(delay) ? _this.id
|
|
351
|
+
var delayRef = isFunction(delay) ? "".concat(_this.id, ":delay[").concat(i, "]") : delay;
|
|
351
352
|
var eventType = after(delayRef, _this.id);
|
|
352
353
|
|
|
353
354
|
_this.onEntry.push(send(eventType, {
|
|
@@ -409,15 +410,11 @@ function () {
|
|
|
409
410
|
}
|
|
410
411
|
|
|
411
412
|
var subStateKeys = keys(stateValue);
|
|
412
|
-
var subStateNodes =
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
return subStateNodes
|
|
417
|
-
var subStateNode = _this.getStateNode(subStateKey).getStateNodes(stateValue[subStateKey]);
|
|
418
|
-
|
|
419
|
-
return allSubStateNodes.concat(subStateNode);
|
|
420
|
-
}, []));
|
|
413
|
+
var subStateNodes = [this];
|
|
414
|
+
subStateNodes.push.apply(subStateNodes, __spreadArray([], __read(flatten(subStateKeys.map(function (subStateKey) {
|
|
415
|
+
return _this.getStateNode(subStateKey).getStateNodes(stateValue[subStateKey]);
|
|
416
|
+
}))), false));
|
|
417
|
+
return subStateNodes;
|
|
421
418
|
};
|
|
422
419
|
/**
|
|
423
420
|
* Returns `true` if this state node explicitly handles the given event.
|
|
@@ -556,6 +553,10 @@ function () {
|
|
|
556
553
|
return this.transitionParallelNode(stateValue, state, _event);
|
|
557
554
|
};
|
|
558
555
|
|
|
556
|
+
StateNode.prototype.getTransitionData = function (state, event) {
|
|
557
|
+
return this._transition(state.value, state, toSCXMLEvent(event));
|
|
558
|
+
};
|
|
559
|
+
|
|
559
560
|
StateNode.prototype.next = function (state, _event) {
|
|
560
561
|
var e_3, _a;
|
|
561
562
|
|
|
@@ -580,7 +581,7 @@ function () {
|
|
|
580
581
|
try {
|
|
581
582
|
guardPassed = !cond || evaluateGuard(this.machine, cond, resolvedContext, _event, state);
|
|
582
583
|
} catch (err) {
|
|
583
|
-
throw new Error("Unable to evaluate guard '"
|
|
584
|
+
throw new Error("Unable to evaluate guard '".concat(cond.name || cond.type, "' in transition for event '").concat(eventName, "' in state node '").concat(this.id, "':\n").concat(err.message));
|
|
584
585
|
}
|
|
585
586
|
|
|
586
587
|
if (guardPassed && isInState) {
|
|
@@ -588,7 +589,7 @@ function () {
|
|
|
588
589
|
nextStateNodes = candidate.target;
|
|
589
590
|
}
|
|
590
591
|
|
|
591
|
-
actions.push.apply(actions, __spreadArray([], __read(candidate.actions)));
|
|
592
|
+
actions.push.apply(actions, __spreadArray([], __read(candidate.actions), false));
|
|
592
593
|
selectedTransition = candidate;
|
|
593
594
|
break;
|
|
594
595
|
}
|
|
@@ -724,12 +725,6 @@ function () {
|
|
|
724
725
|
}
|
|
725
726
|
}
|
|
726
727
|
|
|
727
|
-
if (!transition.source) {
|
|
728
|
-
transition.exitSet = []; // Ensure that root StateNode (machine) is entered
|
|
729
|
-
|
|
730
|
-
transition.entrySet.push(this);
|
|
731
|
-
}
|
|
732
|
-
|
|
733
728
|
var doneEvents = flatten(transition.entrySet.map(function (sn) {
|
|
734
729
|
var events = [];
|
|
735
730
|
|
|
@@ -769,11 +764,11 @@ function () {
|
|
|
769
764
|
var _c = __read([flatten(Array.from(entryStates).map(function (stateNode) {
|
|
770
765
|
return __spreadArray(__spreadArray([], __read(stateNode.activities.map(function (activity) {
|
|
771
766
|
return start(activity);
|
|
772
|
-
}))), __read(stateNode.onEntry));
|
|
767
|
+
})), false), __read(stateNode.onEntry), false);
|
|
773
768
|
})).concat(doneEvents.map(raise)), flatten(Array.from(exitStates).map(function (stateNode) {
|
|
774
|
-
return __spreadArray(__spreadArray([], __read(stateNode.onExit)), __read(stateNode.activities.map(function (activity) {
|
|
769
|
+
return __spreadArray(__spreadArray([], __read(stateNode.onExit), false), __read(stateNode.activities.map(function (activity) {
|
|
775
770
|
return stop(activity);
|
|
776
|
-
})));
|
|
771
|
+
})), false);
|
|
777
772
|
}))], 2),
|
|
778
773
|
entryActions = _c[0],
|
|
779
774
|
exitActions = _c[1];
|
|
@@ -808,12 +803,12 @@ function () {
|
|
|
808
803
|
}
|
|
809
804
|
|
|
810
805
|
if (!IS_PRODUCTION && _event.name === WILDCARD) {
|
|
811
|
-
throw new Error("An event cannot have the wildcard type ('"
|
|
806
|
+
throw new Error("An event cannot have the wildcard type ('".concat(WILDCARD, "')"));
|
|
812
807
|
}
|
|
813
808
|
|
|
814
809
|
if (this.strict) {
|
|
815
810
|
if (!this.events.includes(_event.name) && !isBuiltInEvent(_event.name)) {
|
|
816
|
-
throw new Error("Machine '"
|
|
811
|
+
throw new Error("Machine '".concat(this.id, "' does not accept event '").concat(_event.name, "'"));
|
|
817
812
|
}
|
|
818
813
|
}
|
|
819
814
|
|
|
@@ -827,7 +822,7 @@ function () {
|
|
|
827
822
|
};
|
|
828
823
|
var prevConfig = getConfiguration([], this.getStateNodes(currentState.value));
|
|
829
824
|
var resolvedConfig = stateTransition.configuration.length ? getConfiguration(prevConfig, stateTransition.configuration) : prevConfig;
|
|
830
|
-
stateTransition.configuration = __spreadArray([], __read(resolvedConfig));
|
|
825
|
+
stateTransition.configuration = __spreadArray([], __read(resolvedConfig), false);
|
|
831
826
|
return this.resolveTransition(stateTransition, currentState, _event);
|
|
832
827
|
};
|
|
833
828
|
|
|
@@ -841,7 +836,7 @@ function () {
|
|
|
841
836
|
state._event = originalEvent;
|
|
842
837
|
state.event = originalEvent.data;
|
|
843
838
|
|
|
844
|
-
(_a = state.actions).unshift.apply(_a, __spreadArray([], __read(currentActions)));
|
|
839
|
+
(_a = state.actions).unshift.apply(_a, __spreadArray([], __read(currentActions), false));
|
|
845
840
|
|
|
846
841
|
return state;
|
|
847
842
|
};
|
|
@@ -992,13 +987,13 @@ function () {
|
|
|
992
987
|
}
|
|
993
988
|
|
|
994
989
|
if (!this.states) {
|
|
995
|
-
throw new Error("Unable to retrieve child state '"
|
|
990
|
+
throw new Error("Unable to retrieve child state '".concat(stateKey, "' from '").concat(this.id, "'; no child states exist."));
|
|
996
991
|
}
|
|
997
992
|
|
|
998
993
|
var result = this.states[stateKey];
|
|
999
994
|
|
|
1000
995
|
if (!result) {
|
|
1001
|
-
throw new Error("Child state '"
|
|
996
|
+
throw new Error("Child state '".concat(stateKey, "' does not exist on '").concat(this.id, "'"));
|
|
1002
997
|
}
|
|
1003
998
|
|
|
1004
999
|
return result;
|
|
@@ -1020,7 +1015,7 @@ function () {
|
|
|
1020
1015
|
var stateNode = this.machine.idMap[resolvedStateId];
|
|
1021
1016
|
|
|
1022
1017
|
if (!stateNode) {
|
|
1023
|
-
throw new Error("Child state node '#"
|
|
1018
|
+
throw new Error("Child state node '#".concat(resolvedStateId, "' does not exist on machine '").concat(this.id, "'"));
|
|
1024
1019
|
}
|
|
1025
1020
|
|
|
1026
1021
|
return stateNode;
|
|
@@ -1107,7 +1102,7 @@ function () {
|
|
|
1107
1102
|
var stateNode = this.machine.idMap[stateIdentifier.slice(STATE_IDENTIFIER.length)];
|
|
1108
1103
|
|
|
1109
1104
|
if (!stateNode) {
|
|
1110
|
-
throw new Error("Unable to find state node '"
|
|
1105
|
+
throw new Error("Unable to find state node '".concat(stateIdentifier, "'"));
|
|
1111
1106
|
}
|
|
1112
1107
|
|
|
1113
1108
|
return stateNode.path;
|
|
@@ -1134,7 +1129,7 @@ function () {
|
|
|
1134
1129
|
});
|
|
1135
1130
|
} else if (this.initial !== undefined) {
|
|
1136
1131
|
if (!this.states[this.initial]) {
|
|
1137
|
-
throw new Error("Initial state '"
|
|
1132
|
+
throw new Error("Initial state '".concat(this.initial, "' not found on '").concat(this.key, "'"));
|
|
1138
1133
|
}
|
|
1139
1134
|
|
|
1140
1135
|
initialStateValue = isLeafNode(this.states[this.initial]) ? this.initial : (_a = {}, _a[this.initial] = this.states[this.initial].initialStateValue, _a);
|
|
@@ -1174,7 +1169,7 @@ function () {
|
|
|
1174
1169
|
var initialStateValue = this.initialStateValue;
|
|
1175
1170
|
|
|
1176
1171
|
if (!initialStateValue) {
|
|
1177
|
-
throw new Error("Cannot retrieve initial state from simple state '"
|
|
1172
|
+
throw new Error("Cannot retrieve initial state from simple state '".concat(this.id, "'."));
|
|
1178
1173
|
}
|
|
1179
1174
|
|
|
1180
1175
|
return this.getInitialState(initialStateValue);
|
|
@@ -1232,7 +1227,7 @@ function () {
|
|
|
1232
1227
|
|
|
1233
1228
|
if (this.type === 'compound' && !this.initial) {
|
|
1234
1229
|
if (!IS_PRODUCTION) {
|
|
1235
|
-
warn(false, "Compound state node '"
|
|
1230
|
+
warn(false, "Compound state node '".concat(this.id, "' has no initial state."));
|
|
1236
1231
|
}
|
|
1237
1232
|
|
|
1238
1233
|
return [this];
|
|
@@ -1263,7 +1258,7 @@ function () {
|
|
|
1263
1258
|
childStatePath = _a.slice(1);
|
|
1264
1259
|
|
|
1265
1260
|
if (!this.states) {
|
|
1266
|
-
throw new Error("Cannot retrieve subPath '"
|
|
1261
|
+
throw new Error("Cannot retrieve subPath '".concat(stateKey, "' from node with no states"));
|
|
1267
1262
|
}
|
|
1268
1263
|
|
|
1269
1264
|
var childStateNode = this.getStateNode(stateKey);
|
|
@@ -1273,7 +1268,7 @@ function () {
|
|
|
1273
1268
|
}
|
|
1274
1269
|
|
|
1275
1270
|
if (!this.states[stateKey]) {
|
|
1276
|
-
throw new Error("Child state '"
|
|
1271
|
+
throw new Error("Child state '".concat(stateKey, "' does not exist on '").concat(this.id, "'"));
|
|
1277
1272
|
}
|
|
1278
1273
|
|
|
1279
1274
|
return this.states[stateKey].getFromRelativePath(childStatePath);
|
|
@@ -1372,7 +1367,7 @@ function () {
|
|
|
1372
1367
|
try {
|
|
1373
1368
|
for (var _e = (e_8 = void 0, __values(state.events)), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
1374
1369
|
var event_1 = _f.value;
|
|
1375
|
-
events.add(""
|
|
1370
|
+
events.add("".concat(event_1));
|
|
1376
1371
|
}
|
|
1377
1372
|
} catch (e_8_1) {
|
|
1378
1373
|
e_8 = {
|
|
@@ -1451,7 +1446,7 @@ function () {
|
|
|
1451
1446
|
|
|
1452
1447
|
return targetStateNode;
|
|
1453
1448
|
} catch (err) {
|
|
1454
|
-
throw new Error("Invalid transition definition for state node '"
|
|
1449
|
+
throw new Error("Invalid transition definition for state node '".concat(_this.id, "':\n").concat(err.message));
|
|
1455
1450
|
}
|
|
1456
1451
|
} else {
|
|
1457
1452
|
return _this.getStateNodeByPath(resolvedTarget);
|
|
@@ -1479,9 +1474,9 @@ function () {
|
|
|
1479
1474
|
toJSON: function () {
|
|
1480
1475
|
return __assign(__assign({}, transition), {
|
|
1481
1476
|
target: transition.target ? transition.target.map(function (t) {
|
|
1482
|
-
return "#"
|
|
1477
|
+
return "#".concat(t.id);
|
|
1483
1478
|
}) : undefined,
|
|
1484
|
-
source: "#"
|
|
1479
|
+
source: "#".concat(_this.id)
|
|
1485
1480
|
});
|
|
1486
1481
|
}
|
|
1487
1482
|
});
|
|
@@ -1509,7 +1504,7 @@ function () {
|
|
|
1509
1504
|
|
|
1510
1505
|
onConfig = flatten(keys(strictTransitionConfigs_1).map(function (key) {
|
|
1511
1506
|
if (!IS_PRODUCTION && key === NULL_EVENT) {
|
|
1512
|
-
warn(false, "Empty string transition configs (e.g., `{ on: { '': ... }}`) for transient transitions are deprecated. Specify the transition in the `{ always: ... }` property instead. " +
|
|
1507
|
+
warn(false, "Empty string transition configs (e.g., `{ on: { '': ... }}`) for transient transitions are deprecated. Specify the transition in the `{ always: ... }` property instead. " + "Please check the `on` configuration for \"#".concat(_this.id, "\"."));
|
|
1513
1508
|
}
|
|
1514
1509
|
|
|
1515
1510
|
var transitionConfigArray = toTransitionConfigArray(key, strictTransitionConfigs_1[key]);
|
|
@@ -1526,24 +1521,24 @@ function () {
|
|
|
1526
1521
|
var doneConfig = this.config.onDone ? toTransitionConfigArray(String(done(this.id)), this.config.onDone) : [];
|
|
1527
1522
|
|
|
1528
1523
|
if (!IS_PRODUCTION) {
|
|
1529
|
-
warn(!(this.config.onDone && !this.parent), "Root nodes cannot have an \".onDone\" transition. Please check the config of \""
|
|
1524
|
+
warn(!(this.config.onDone && !this.parent), "Root nodes cannot have an \".onDone\" transition. Please check the config of \"".concat(this.id, "\"."));
|
|
1530
1525
|
}
|
|
1531
1526
|
|
|
1532
1527
|
var invokeConfig = flatten(this.invoke.map(function (invokeDef) {
|
|
1533
1528
|
var settleTransitions = [];
|
|
1534
1529
|
|
|
1535
1530
|
if (invokeDef.onDone) {
|
|
1536
|
-
settleTransitions.push.apply(settleTransitions, __spreadArray([], __read(toTransitionConfigArray(String(doneInvoke(invokeDef.id)), invokeDef.onDone))));
|
|
1531
|
+
settleTransitions.push.apply(settleTransitions, __spreadArray([], __read(toTransitionConfigArray(String(doneInvoke(invokeDef.id)), invokeDef.onDone)), false));
|
|
1537
1532
|
}
|
|
1538
1533
|
|
|
1539
1534
|
if (invokeDef.onError) {
|
|
1540
|
-
settleTransitions.push.apply(settleTransitions, __spreadArray([], __read(toTransitionConfigArray(String(error(invokeDef.id)), invokeDef.onError))));
|
|
1535
|
+
settleTransitions.push.apply(settleTransitions, __spreadArray([], __read(toTransitionConfigArray(String(error(invokeDef.id)), invokeDef.onError)), false));
|
|
1541
1536
|
}
|
|
1542
1537
|
|
|
1543
1538
|
return settleTransitions;
|
|
1544
1539
|
}));
|
|
1545
1540
|
var delayedTransitions = this.after;
|
|
1546
|
-
var formattedTransitions = flatten(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], __read(doneConfig)), __read(invokeConfig)), __read(onConfig)), __read(eventlessConfig)).map(function (transitionConfig) {
|
|
1541
|
+
var formattedTransitions = flatten(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], __read(doneConfig), false), __read(invokeConfig), false), __read(onConfig), false), __read(eventlessConfig), false).map(function (transitionConfig) {
|
|
1547
1542
|
return toArray(transitionConfig).map(function (transition) {
|
|
1548
1543
|
return _this.formatTransition(transition);
|
|
1549
1544
|
});
|
package/es/_virtual/_tslib.js
CHANGED
|
@@ -65,10 +65,14 @@ function __read(o, n) {
|
|
|
65
65
|
return ar;
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
function __spreadArray(to, from) {
|
|
69
|
-
for (var i = 0,
|
|
70
|
-
|
|
71
|
-
|
|
68
|
+
function __spreadArray(to, from, pack) {
|
|
69
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
70
|
+
if (ar || !(i in from)) {
|
|
71
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
72
|
+
ar[i] = from[i];
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
72
76
|
}
|
|
73
77
|
|
|
74
78
|
export { __assign, __read, __rest, __spreadArray, __values };
|
package/es/actions.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Action, Event, EventObject, SingleOrArray, SendAction, SendActionOptions, CancelAction, ActionObject, ActionType, Assigner, PropertyAssigner, AssignAction, ActionFunction, ActionFunctionMap, ActivityActionObject, ActionTypes, ActivityDefinition, RaiseAction, RaiseActionObject, DoneEvent, ErrorPlatformEvent, DoneEventObject, SendExpr, SendActionObject, PureAction, LogExpr, LogAction, LogActionObject, DelayFunctionMap, SCXML, ExprWithMeta, ChooseCondition, ChooseAction, AnyEventObject, Expr } from './types';
|
|
1
|
+
import { Action, Event, EventObject, SingleOrArray, SendAction, SendActionOptions, CancelAction, ActionObject, ActionType, Assigner, PropertyAssigner, AssignAction, ActionFunction, ActionFunctionMap, ActivityActionObject, ActionTypes, ActivityDefinition, RaiseAction, RaiseActionObject, DoneEvent, ErrorPlatformEvent, DoneEventObject, SendExpr, SendActionObject, PureAction, LogExpr, LogAction, LogActionObject, DelayFunctionMap, SCXML, ExprWithMeta, ChooseCondition, ChooseAction, AnyEventObject, Expr, Cast } from './types';
|
|
2
2
|
import * as actionTypes from './actionTypes';
|
|
3
3
|
import { State } from './State';
|
|
4
4
|
import { StateNode } from './StateNode';
|
|
5
|
-
import { StopAction, StopActionObject } from '.';
|
|
5
|
+
import { ActorRef, EventFrom, StopAction, StopActionObject } from '.';
|
|
6
6
|
export { actionTypes };
|
|
7
7
|
export declare const initEvent: SCXML.Event<{
|
|
8
8
|
type: ActionTypes;
|
|
@@ -38,6 +38,22 @@ export declare function resolveSend<TContext, TEvent extends EventObject, TSentE
|
|
|
38
38
|
* @param options Options to pass into the send event.
|
|
39
39
|
*/
|
|
40
40
|
export declare function sendParent<TContext, TEvent extends EventObject, TSentEvent extends EventObject = AnyEventObject>(event: Event<TSentEvent> | SendExpr<TContext, TEvent, TSentEvent>, options?: SendActionOptions<TContext, TEvent>): SendAction<TContext, TEvent, TSentEvent>;
|
|
41
|
+
declare type InferEvent<E extends EventObject> = {
|
|
42
|
+
[T in E['type']]: {
|
|
43
|
+
type: T;
|
|
44
|
+
} & Extract<E, {
|
|
45
|
+
type: T;
|
|
46
|
+
}>;
|
|
47
|
+
}[E['type']];
|
|
48
|
+
/**
|
|
49
|
+
* Sends an event to an actor.
|
|
50
|
+
*
|
|
51
|
+
* @param actor The `ActorRef` to send the event to.
|
|
52
|
+
* @param event The event to send, or an expression that evaluates to the event to send
|
|
53
|
+
* @param options Send action options
|
|
54
|
+
* @returns An XState send action object
|
|
55
|
+
*/
|
|
56
|
+
export declare function sendTo<TContext, TEvent extends EventObject, TActor extends ActorRef<EventObject>>(actor: (ctx: TContext) => TActor, event: EventFrom<TActor> | SendExpr<TContext, TEvent, InferEvent<Cast<EventFrom<TActor>, EventObject>>>, options?: SendActionOptions<TContext, TEvent>): SendAction<TContext, TEvent, any>;
|
|
41
57
|
/**
|
|
42
58
|
* Sends an update event to this machine's parent.
|
|
43
59
|
*/
|
package/es/actions.js
CHANGED
|
@@ -152,6 +152,20 @@ function sendParent(event, options) {
|
|
|
152
152
|
to: SpecialTargets.Parent
|
|
153
153
|
}));
|
|
154
154
|
}
|
|
155
|
+
/**
|
|
156
|
+
* Sends an event to an actor.
|
|
157
|
+
*
|
|
158
|
+
* @param actor The `ActorRef` to send the event to.
|
|
159
|
+
* @param event The event to send, or an expression that evaluates to the event to send
|
|
160
|
+
* @param options Send action options
|
|
161
|
+
* @returns An XState send action object
|
|
162
|
+
*/
|
|
163
|
+
|
|
164
|
+
function sendTo(actor, event, options) {
|
|
165
|
+
return send(event, __assign(__assign({}, options), {
|
|
166
|
+
to: actor
|
|
167
|
+
}));
|
|
168
|
+
}
|
|
155
169
|
/**
|
|
156
170
|
* Sends an update event to this machine's parent.
|
|
157
171
|
*/
|
|
@@ -283,8 +297,8 @@ var assign = function (assignment) {
|
|
|
283
297
|
*/
|
|
284
298
|
|
|
285
299
|
function after(delayRef, id) {
|
|
286
|
-
var idSuffix = id ? "#"
|
|
287
|
-
return ActionTypes.After
|
|
300
|
+
var idSuffix = id ? "#".concat(id) : '';
|
|
301
|
+
return "".concat(ActionTypes.After, "(").concat(delayRef, ")").concat(idSuffix);
|
|
288
302
|
}
|
|
289
303
|
/**
|
|
290
304
|
* Returns an event that represents that a final state node
|
|
@@ -295,7 +309,7 @@ function after(delayRef, id) {
|
|
|
295
309
|
*/
|
|
296
310
|
|
|
297
311
|
function done(id, data) {
|
|
298
|
-
var type = ActionTypes.DoneState
|
|
312
|
+
var type = "".concat(ActionTypes.DoneState, ".").concat(id);
|
|
299
313
|
var eventObject = {
|
|
300
314
|
type: type,
|
|
301
315
|
data: data
|
|
@@ -318,7 +332,7 @@ function done(id, data) {
|
|
|
318
332
|
*/
|
|
319
333
|
|
|
320
334
|
function doneInvoke(id, data) {
|
|
321
|
-
var type = ActionTypes.DoneInvoke
|
|
335
|
+
var type = "".concat(ActionTypes.DoneInvoke, ".").concat(id);
|
|
322
336
|
var eventObject = {
|
|
323
337
|
type: type,
|
|
324
338
|
data: data
|
|
@@ -331,7 +345,7 @@ function doneInvoke(id, data) {
|
|
|
331
345
|
return eventObject;
|
|
332
346
|
}
|
|
333
347
|
function error(id, data) {
|
|
334
|
-
var type = ActionTypes.ErrorPlatform
|
|
348
|
+
var type = "".concat(ActionTypes.ErrorPlatform, ".").concat(id);
|
|
335
349
|
var eventObject = {
|
|
336
350
|
type: type,
|
|
337
351
|
data: data
|
|
@@ -413,7 +427,7 @@ function resolveActions(machine, currentState, currentContext, _event, actions,
|
|
|
413
427
|
if (!IS_PRODUCTION) {
|
|
414
428
|
// warn after resolving as we can create better contextual message here
|
|
415
429
|
warn(!isString(actionObject.delay) || typeof sendAction.delay === 'number', // tslint:disable-next-line:max-line-length
|
|
416
|
-
"No delay reference for delay expression '"
|
|
430
|
+
"No delay reference for delay expression '".concat(actionObject.delay, "' was found on machine '").concat(machine.id, "'"));
|
|
417
431
|
}
|
|
418
432
|
|
|
419
433
|
return sendAction;
|
|
@@ -485,7 +499,7 @@ function resolveActions(machine, currentState, currentContext, _event, actions,
|
|
|
485
499
|
args[_i - 1] = arguments[_i];
|
|
486
500
|
}
|
|
487
501
|
|
|
488
|
-
exec_1.apply(void 0, __spreadArray([preservedContexts[contextIndex_1]], __read(args)));
|
|
502
|
+
exec_1.apply(void 0, __spreadArray([preservedContexts[contextIndex_1]], __read(args), false));
|
|
489
503
|
}
|
|
490
504
|
});
|
|
491
505
|
}
|
|
@@ -498,4 +512,4 @@ function resolveActions(machine, currentState, currentContext, _event, actions,
|
|
|
498
512
|
return [resolvedActions, updatedContext];
|
|
499
513
|
}
|
|
500
514
|
|
|
501
|
-
export { after, assign, cancel, choose, done, doneInvoke, error, escalate, forwardTo, getActionFunction, initEvent, log, pure, raise, resolveActions, resolveLog, resolveRaise, resolveSend, resolveStop, respond, send, sendParent, sendUpdate, start, stop, toActionObject, toActionObjects, toActivityDefinition };
|
|
515
|
+
export { after, assign, cancel, choose, done, doneInvoke, error, escalate, forwardTo, getActionFunction, initEvent, log, pure, raise, resolveActions, resolveLog, resolveRaise, resolveSend, resolveStop, respond, send, sendParent, sendTo, sendUpdate, start, stop, toActionObject, toActionObjects, toActivityDefinition };
|
package/es/devTools.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
1
|
import { Interpreter } from '.';
|
|
3
2
|
import { AnyInterpreter } from './types';
|
|
4
3
|
declare type ServiceListener = (service: AnyInterpreter) => void;
|
|
@@ -10,7 +9,7 @@ export interface XStateDevInterface {
|
|
|
10
9
|
};
|
|
11
10
|
services: Set<Interpreter<any>>;
|
|
12
11
|
}
|
|
13
|
-
export declare function getGlobal():
|
|
12
|
+
export declare function getGlobal(): typeof globalThis | undefined;
|
|
14
13
|
export declare function registerService(service: AnyInterpreter): void;
|
|
15
14
|
export {};
|
|
16
15
|
//# sourceMappingURL=devTools.d.ts.map
|
package/es/devTools.js
CHANGED
package/es/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { StateNode } from './StateNode';
|
|
|
4
4
|
import { State } from './State';
|
|
5
5
|
import { Machine, createMachine } from './Machine';
|
|
6
6
|
import { Actor } from './Actor';
|
|
7
|
-
import { raise, send, sendParent, sendUpdate, log, start, stop, assign, after, done, respond, doneInvoke, forwardTo, escalate, choose, pure } from './actions';
|
|
7
|
+
import { raise, send, sendParent, sendTo, sendUpdate, log, start, stop, assign, after, done, respond, doneInvoke, forwardTo, escalate, choose, pure } from './actions';
|
|
8
8
|
import { interpret, Interpreter, spawn, InterpreterStatus } from './interpreter';
|
|
9
9
|
import { matchState } from './match';
|
|
10
10
|
import { createSchema } from './schema';
|
|
@@ -12,6 +12,7 @@ declare const actions: {
|
|
|
12
12
|
raise: typeof raise;
|
|
13
13
|
send: typeof send;
|
|
14
14
|
sendParent: typeof sendParent;
|
|
15
|
+
sendTo: typeof sendTo;
|
|
15
16
|
sendUpdate: typeof sendUpdate;
|
|
16
17
|
log: typeof log;
|
|
17
18
|
cancel: (sendId: string | number) => import("./types").CancelAction;
|
package/es/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { matchesState } from './utils.js';
|
|
2
2
|
export { mapState } from './mapState.js';
|
|
3
3
|
export { ActionTypes, SpecialTargets } from './types.js';
|
|
4
|
-
import { raise, send, sendParent, sendUpdate, log, cancel, start, stop, assign, after, done, respond, forwardTo, escalate, choose, pure } from './actions.js';
|
|
4
|
+
import { raise, send, sendParent, sendTo, sendUpdate, log, cancel, start, stop, assign, after, done, respond, forwardTo, escalate, choose, pure } from './actions.js';
|
|
5
5
|
export { assign, doneInvoke, forwardTo, send, sendParent, sendUpdate } from './actions.js';
|
|
6
6
|
export { State } from './State.js';
|
|
7
7
|
export { StateNode } from './StateNode.js';
|
|
@@ -14,6 +14,7 @@ var actions = {
|
|
|
14
14
|
raise: raise,
|
|
15
15
|
send: send,
|
|
16
16
|
sendParent: sendParent,
|
|
17
|
+
sendTo: sendTo,
|
|
17
18
|
sendUpdate: sendUpdate,
|
|
18
19
|
log: log,
|
|
19
20
|
cancel: cancel,
|
package/es/interpreter.d.ts
CHANGED
|
@@ -21,11 +21,6 @@ export declare enum InterpreterStatus {
|
|
|
21
21
|
Running = 1,
|
|
22
22
|
Stopped = 2
|
|
23
23
|
}
|
|
24
|
-
declare global {
|
|
25
|
-
interface SymbolConstructor {
|
|
26
|
-
readonly observable: symbol;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
24
|
export declare class Interpreter<TContext, TStateSchema extends StateSchema = any, TEvent extends EventObject = EventObject, TTypestate extends Typestate<TContext> = {
|
|
30
25
|
value: any;
|
|
31
26
|
context: TContext;
|