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/lib/StateNode.js
CHANGED
|
@@ -37,8 +37,8 @@ var validateArrayifiedTransitions = function (stateNode, event, transitions) {
|
|
|
37
37
|
var hasNonLastUnguardedTarget = transitions.slice(0, -1).some(function (transition) {
|
|
38
38
|
return !('cond' in transition) && !('in' in transition) && (utils.isString(transition.target) || utils.isMachine(transition.target));
|
|
39
39
|
});
|
|
40
|
-
var eventText = event === NULL_EVENT ? 'the transient event' : "event '"
|
|
41
|
-
utils.warn(!hasNonLastUnguardedTarget, "One or more transitions for "
|
|
40
|
+
var eventText = event === NULL_EVENT ? 'the transient event' : "event '".concat(event, "'");
|
|
41
|
+
utils.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.");
|
|
42
42
|
};
|
|
43
43
|
|
|
44
44
|
var StateNode =
|
|
@@ -90,14 +90,14 @@ function () {
|
|
|
90
90
|
this.machine = this.parent ? this.parent.machine : this;
|
|
91
91
|
this.path = this.parent ? this.parent.path.concat(this.key) : [];
|
|
92
92
|
this.delimiter = this.config.delimiter || (this.parent ? this.parent.delimiter : constants.STATE_DELIMITER);
|
|
93
|
-
this.id = this.config.id || _tslib.__spreadArray([this.machine.key], _tslib.__read(this.path)).join(this.delimiter);
|
|
93
|
+
this.id = this.config.id || _tslib.__spreadArray([this.machine.key], _tslib.__read(this.path), false).join(this.delimiter);
|
|
94
94
|
this.version = this.parent ? this.parent.version : this.config.version;
|
|
95
95
|
this.type = this.config.type || (this.config.parallel ? 'parallel' : this.config.states && utils.keys(this.config.states).length ? 'compound' : this.config.history ? 'history' : 'atomic');
|
|
96
96
|
this.schema = this.parent ? this.machine.schema : (_a = this.config.schema) !== null && _a !== void 0 ? _a : {};
|
|
97
97
|
this.description = this.config.description;
|
|
98
98
|
|
|
99
99
|
if (!environment.IS_PRODUCTION) {
|
|
100
|
-
utils.warn(!('parallel' in this.config), "The \"parallel\" property is deprecated and will be removed in version 4.1. "
|
|
100
|
+
utils.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."));
|
|
101
101
|
}
|
|
102
102
|
|
|
103
103
|
this.initial = this.config.initial;
|
|
@@ -159,29 +159,30 @@ function () {
|
|
|
159
159
|
var _a, _b;
|
|
160
160
|
|
|
161
161
|
if (utils.isMachine(invokeConfig)) {
|
|
162
|
-
|
|
162
|
+
var invokeId = utils.createInvokeId(_this.id, i);
|
|
163
|
+
_this.machine.options.services = _tslib.__assign((_a = {}, _a[invokeId] = invokeConfig, _a), _this.machine.options.services);
|
|
163
164
|
return invokeUtils.toInvokeDefinition({
|
|
164
|
-
src:
|
|
165
|
-
id:
|
|
165
|
+
src: invokeId,
|
|
166
|
+
id: invokeId
|
|
166
167
|
});
|
|
167
168
|
} else if (utils.isString(invokeConfig.src)) {
|
|
169
|
+
var invokeId = invokeConfig.id || utils.createInvokeId(_this.id, i);
|
|
168
170
|
return invokeUtils.toInvokeDefinition(_tslib.__assign(_tslib.__assign({}, invokeConfig), {
|
|
169
|
-
id:
|
|
171
|
+
id: invokeId,
|
|
170
172
|
src: invokeConfig.src
|
|
171
173
|
}));
|
|
172
174
|
} else if (utils.isMachine(invokeConfig.src) || utils.isFunction(invokeConfig.src)) {
|
|
173
|
-
var
|
|
174
|
-
|
|
175
|
-
_this.machine.options.services = _tslib.__assign((_b = {}, _b[invokeSrc] = invokeConfig.src, _b), _this.machine.options.services);
|
|
175
|
+
var invokeId = invokeConfig.id || utils.createInvokeId(_this.id, i);
|
|
176
|
+
_this.machine.options.services = _tslib.__assign((_b = {}, _b[invokeId] = invokeConfig.src, _b), _this.machine.options.services);
|
|
176
177
|
return invokeUtils.toInvokeDefinition(_tslib.__assign(_tslib.__assign({
|
|
177
|
-
id:
|
|
178
|
+
id: invokeId
|
|
178
179
|
}, invokeConfig), {
|
|
179
|
-
src:
|
|
180
|
+
src: invokeId
|
|
180
181
|
}));
|
|
181
182
|
} else {
|
|
182
183
|
var invokeSource = invokeConfig.src;
|
|
183
184
|
return invokeUtils.toInvokeDefinition(_tslib.__assign(_tslib.__assign({
|
|
184
|
-
id:
|
|
185
|
+
id: utils.createInvokeId(_this.id, i)
|
|
185
186
|
}, invokeConfig), {
|
|
186
187
|
src: invokeSource
|
|
187
188
|
}));
|
|
@@ -351,7 +352,7 @@ function () {
|
|
|
351
352
|
}
|
|
352
353
|
|
|
353
354
|
var mutateEntryExit = function (delay, i) {
|
|
354
|
-
var delayRef = utils.isFunction(delay) ? _this.id
|
|
355
|
+
var delayRef = utils.isFunction(delay) ? "".concat(_this.id, ":delay[").concat(i, "]") : delay;
|
|
355
356
|
var eventType = actions.after(delayRef, _this.id);
|
|
356
357
|
|
|
357
358
|
_this.onEntry.push(actions.send(eventType, {
|
|
@@ -413,15 +414,11 @@ function () {
|
|
|
413
414
|
}
|
|
414
415
|
|
|
415
416
|
var subStateKeys = utils.keys(stateValue);
|
|
416
|
-
var subStateNodes =
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
return subStateNodes
|
|
421
|
-
var subStateNode = _this.getStateNode(subStateKey).getStateNodes(stateValue[subStateKey]);
|
|
422
|
-
|
|
423
|
-
return allSubStateNodes.concat(subStateNode);
|
|
424
|
-
}, []));
|
|
417
|
+
var subStateNodes = [this];
|
|
418
|
+
subStateNodes.push.apply(subStateNodes, _tslib.__spreadArray([], _tslib.__read(utils.flatten(subStateKeys.map(function (subStateKey) {
|
|
419
|
+
return _this.getStateNode(subStateKey).getStateNodes(stateValue[subStateKey]);
|
|
420
|
+
}))), false));
|
|
421
|
+
return subStateNodes;
|
|
425
422
|
};
|
|
426
423
|
/**
|
|
427
424
|
* Returns `true` if this state node explicitly handles the given event.
|
|
@@ -560,6 +557,10 @@ function () {
|
|
|
560
557
|
return this.transitionParallelNode(stateValue, state, _event);
|
|
561
558
|
};
|
|
562
559
|
|
|
560
|
+
StateNode.prototype.getTransitionData = function (state, event) {
|
|
561
|
+
return this._transition(state.value, state, utils.toSCXMLEvent(event));
|
|
562
|
+
};
|
|
563
|
+
|
|
563
564
|
StateNode.prototype.next = function (state, _event) {
|
|
564
565
|
var e_3, _a;
|
|
565
566
|
|
|
@@ -584,7 +585,7 @@ function () {
|
|
|
584
585
|
try {
|
|
585
586
|
guardPassed = !cond || utils.evaluateGuard(this.machine, cond, resolvedContext, _event, state);
|
|
586
587
|
} catch (err) {
|
|
587
|
-
throw new Error("Unable to evaluate guard '"
|
|
588
|
+
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));
|
|
588
589
|
}
|
|
589
590
|
|
|
590
591
|
if (guardPassed && isInState) {
|
|
@@ -592,7 +593,7 @@ function () {
|
|
|
592
593
|
nextStateNodes = candidate.target;
|
|
593
594
|
}
|
|
594
595
|
|
|
595
|
-
actions.push.apply(actions, _tslib.__spreadArray([], _tslib.__read(candidate.actions)));
|
|
596
|
+
actions.push.apply(actions, _tslib.__spreadArray([], _tslib.__read(candidate.actions), false));
|
|
596
597
|
selectedTransition = candidate;
|
|
597
598
|
break;
|
|
598
599
|
}
|
|
@@ -728,12 +729,6 @@ function () {
|
|
|
728
729
|
}
|
|
729
730
|
}
|
|
730
731
|
|
|
731
|
-
if (!transition.source) {
|
|
732
|
-
transition.exitSet = []; // Ensure that root StateNode (machine) is entered
|
|
733
|
-
|
|
734
|
-
transition.entrySet.push(this);
|
|
735
|
-
}
|
|
736
|
-
|
|
737
732
|
var doneEvents = utils.flatten(transition.entrySet.map(function (sn) {
|
|
738
733
|
var events = [];
|
|
739
734
|
|
|
@@ -773,11 +768,11 @@ function () {
|
|
|
773
768
|
var _c = _tslib.__read([utils.flatten(Array.from(entryStates).map(function (stateNode) {
|
|
774
769
|
return _tslib.__spreadArray(_tslib.__spreadArray([], _tslib.__read(stateNode.activities.map(function (activity) {
|
|
775
770
|
return actions.start(activity);
|
|
776
|
-
}))), _tslib.__read(stateNode.onEntry));
|
|
771
|
+
})), false), _tslib.__read(stateNode.onEntry), false);
|
|
777
772
|
})).concat(doneEvents.map(actions.raise)), utils.flatten(Array.from(exitStates).map(function (stateNode) {
|
|
778
|
-
return _tslib.__spreadArray(_tslib.__spreadArray([], _tslib.__read(stateNode.onExit)), _tslib.__read(stateNode.activities.map(function (activity) {
|
|
773
|
+
return _tslib.__spreadArray(_tslib.__spreadArray([], _tslib.__read(stateNode.onExit), false), _tslib.__read(stateNode.activities.map(function (activity) {
|
|
779
774
|
return actions.stop(activity);
|
|
780
|
-
})));
|
|
775
|
+
})), false);
|
|
781
776
|
}))], 2),
|
|
782
777
|
entryActions = _c[0],
|
|
783
778
|
exitActions = _c[1];
|
|
@@ -812,12 +807,12 @@ function () {
|
|
|
812
807
|
}
|
|
813
808
|
|
|
814
809
|
if (!environment.IS_PRODUCTION && _event.name === WILDCARD) {
|
|
815
|
-
throw new Error("An event cannot have the wildcard type ('"
|
|
810
|
+
throw new Error("An event cannot have the wildcard type ('".concat(WILDCARD, "')"));
|
|
816
811
|
}
|
|
817
812
|
|
|
818
813
|
if (this.strict) {
|
|
819
814
|
if (!this.events.includes(_event.name) && !utils.isBuiltInEvent(_event.name)) {
|
|
820
|
-
throw new Error("Machine '"
|
|
815
|
+
throw new Error("Machine '".concat(this.id, "' does not accept event '").concat(_event.name, "'"));
|
|
821
816
|
}
|
|
822
817
|
}
|
|
823
818
|
|
|
@@ -831,7 +826,7 @@ function () {
|
|
|
831
826
|
};
|
|
832
827
|
var prevConfig = stateUtils.getConfiguration([], this.getStateNodes(currentState.value));
|
|
833
828
|
var resolvedConfig = stateTransition.configuration.length ? stateUtils.getConfiguration(prevConfig, stateTransition.configuration) : prevConfig;
|
|
834
|
-
stateTransition.configuration = _tslib.__spreadArray([], _tslib.__read(resolvedConfig));
|
|
829
|
+
stateTransition.configuration = _tslib.__spreadArray([], _tslib.__read(resolvedConfig), false);
|
|
835
830
|
return this.resolveTransition(stateTransition, currentState, _event);
|
|
836
831
|
};
|
|
837
832
|
|
|
@@ -845,7 +840,7 @@ function () {
|
|
|
845
840
|
state._event = originalEvent;
|
|
846
841
|
state.event = originalEvent.data;
|
|
847
842
|
|
|
848
|
-
(_a = state.actions).unshift.apply(_a, _tslib.__spreadArray([], _tslib.__read(currentActions)));
|
|
843
|
+
(_a = state.actions).unshift.apply(_a, _tslib.__spreadArray([], _tslib.__read(currentActions), false));
|
|
849
844
|
|
|
850
845
|
return state;
|
|
851
846
|
};
|
|
@@ -996,13 +991,13 @@ function () {
|
|
|
996
991
|
}
|
|
997
992
|
|
|
998
993
|
if (!this.states) {
|
|
999
|
-
throw new Error("Unable to retrieve child state '"
|
|
994
|
+
throw new Error("Unable to retrieve child state '".concat(stateKey, "' from '").concat(this.id, "'; no child states exist."));
|
|
1000
995
|
}
|
|
1001
996
|
|
|
1002
997
|
var result = this.states[stateKey];
|
|
1003
998
|
|
|
1004
999
|
if (!result) {
|
|
1005
|
-
throw new Error("Child state '"
|
|
1000
|
+
throw new Error("Child state '".concat(stateKey, "' does not exist on '").concat(this.id, "'"));
|
|
1006
1001
|
}
|
|
1007
1002
|
|
|
1008
1003
|
return result;
|
|
@@ -1024,7 +1019,7 @@ function () {
|
|
|
1024
1019
|
var stateNode = this.machine.idMap[resolvedStateId];
|
|
1025
1020
|
|
|
1026
1021
|
if (!stateNode) {
|
|
1027
|
-
throw new Error("Child state node '#"
|
|
1022
|
+
throw new Error("Child state node '#".concat(resolvedStateId, "' does not exist on machine '").concat(this.id, "'"));
|
|
1028
1023
|
}
|
|
1029
1024
|
|
|
1030
1025
|
return stateNode;
|
|
@@ -1111,7 +1106,7 @@ function () {
|
|
|
1111
1106
|
var stateNode = this.machine.idMap[stateIdentifier.slice(STATE_IDENTIFIER.length)];
|
|
1112
1107
|
|
|
1113
1108
|
if (!stateNode) {
|
|
1114
|
-
throw new Error("Unable to find state node '"
|
|
1109
|
+
throw new Error("Unable to find state node '".concat(stateIdentifier, "'"));
|
|
1115
1110
|
}
|
|
1116
1111
|
|
|
1117
1112
|
return stateNode.path;
|
|
@@ -1138,7 +1133,7 @@ function () {
|
|
|
1138
1133
|
});
|
|
1139
1134
|
} else if (this.initial !== undefined) {
|
|
1140
1135
|
if (!this.states[this.initial]) {
|
|
1141
|
-
throw new Error("Initial state '"
|
|
1136
|
+
throw new Error("Initial state '".concat(this.initial, "' not found on '").concat(this.key, "'"));
|
|
1142
1137
|
}
|
|
1143
1138
|
|
|
1144
1139
|
initialStateValue = stateUtils.isLeafNode(this.states[this.initial]) ? this.initial : (_a = {}, _a[this.initial] = this.states[this.initial].initialStateValue, _a);
|
|
@@ -1178,7 +1173,7 @@ function () {
|
|
|
1178
1173
|
var initialStateValue = this.initialStateValue;
|
|
1179
1174
|
|
|
1180
1175
|
if (!initialStateValue) {
|
|
1181
|
-
throw new Error("Cannot retrieve initial state from simple state '"
|
|
1176
|
+
throw new Error("Cannot retrieve initial state from simple state '".concat(this.id, "'."));
|
|
1182
1177
|
}
|
|
1183
1178
|
|
|
1184
1179
|
return this.getInitialState(initialStateValue);
|
|
@@ -1236,7 +1231,7 @@ function () {
|
|
|
1236
1231
|
|
|
1237
1232
|
if (this.type === 'compound' && !this.initial) {
|
|
1238
1233
|
if (!environment.IS_PRODUCTION) {
|
|
1239
|
-
utils.warn(false, "Compound state node '"
|
|
1234
|
+
utils.warn(false, "Compound state node '".concat(this.id, "' has no initial state."));
|
|
1240
1235
|
}
|
|
1241
1236
|
|
|
1242
1237
|
return [this];
|
|
@@ -1267,7 +1262,7 @@ function () {
|
|
|
1267
1262
|
childStatePath = _a.slice(1);
|
|
1268
1263
|
|
|
1269
1264
|
if (!this.states) {
|
|
1270
|
-
throw new Error("Cannot retrieve subPath '"
|
|
1265
|
+
throw new Error("Cannot retrieve subPath '".concat(stateKey, "' from node with no states"));
|
|
1271
1266
|
}
|
|
1272
1267
|
|
|
1273
1268
|
var childStateNode = this.getStateNode(stateKey);
|
|
@@ -1277,7 +1272,7 @@ function () {
|
|
|
1277
1272
|
}
|
|
1278
1273
|
|
|
1279
1274
|
if (!this.states[stateKey]) {
|
|
1280
|
-
throw new Error("Child state '"
|
|
1275
|
+
throw new Error("Child state '".concat(stateKey, "' does not exist on '").concat(this.id, "'"));
|
|
1281
1276
|
}
|
|
1282
1277
|
|
|
1283
1278
|
return this.states[stateKey].getFromRelativePath(childStatePath);
|
|
@@ -1376,7 +1371,7 @@ function () {
|
|
|
1376
1371
|
try {
|
|
1377
1372
|
for (var _e = (e_8 = void 0, _tslib.__values(state.events)), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
1378
1373
|
var event_1 = _f.value;
|
|
1379
|
-
events.add(""
|
|
1374
|
+
events.add("".concat(event_1));
|
|
1380
1375
|
}
|
|
1381
1376
|
} catch (e_8_1) {
|
|
1382
1377
|
e_8 = {
|
|
@@ -1455,7 +1450,7 @@ function () {
|
|
|
1455
1450
|
|
|
1456
1451
|
return targetStateNode;
|
|
1457
1452
|
} catch (err) {
|
|
1458
|
-
throw new Error("Invalid transition definition for state node '"
|
|
1453
|
+
throw new Error("Invalid transition definition for state node '".concat(_this.id, "':\n").concat(err.message));
|
|
1459
1454
|
}
|
|
1460
1455
|
} else {
|
|
1461
1456
|
return _this.getStateNodeByPath(resolvedTarget);
|
|
@@ -1483,9 +1478,9 @@ function () {
|
|
|
1483
1478
|
toJSON: function () {
|
|
1484
1479
|
return _tslib.__assign(_tslib.__assign({}, transition), {
|
|
1485
1480
|
target: transition.target ? transition.target.map(function (t) {
|
|
1486
|
-
return "#"
|
|
1481
|
+
return "#".concat(t.id);
|
|
1487
1482
|
}) : undefined,
|
|
1488
|
-
source: "#"
|
|
1483
|
+
source: "#".concat(_this.id)
|
|
1489
1484
|
});
|
|
1490
1485
|
}
|
|
1491
1486
|
});
|
|
@@ -1513,7 +1508,7 @@ function () {
|
|
|
1513
1508
|
|
|
1514
1509
|
onConfig = utils.flatten(utils.keys(strictTransitionConfigs_1).map(function (key) {
|
|
1515
1510
|
if (!environment.IS_PRODUCTION && key === NULL_EVENT) {
|
|
1516
|
-
utils.warn(false, "Empty string transition configs (e.g., `{ on: { '': ... }}`) for transient transitions are deprecated. Specify the transition in the `{ always: ... }` property instead. " +
|
|
1511
|
+
utils.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, "\"."));
|
|
1517
1512
|
}
|
|
1518
1513
|
|
|
1519
1514
|
var transitionConfigArray = utils.toTransitionConfigArray(key, strictTransitionConfigs_1[key]);
|
|
@@ -1530,24 +1525,24 @@ function () {
|
|
|
1530
1525
|
var doneConfig = this.config.onDone ? utils.toTransitionConfigArray(String(actions.done(this.id)), this.config.onDone) : [];
|
|
1531
1526
|
|
|
1532
1527
|
if (!environment.IS_PRODUCTION) {
|
|
1533
|
-
utils.warn(!(this.config.onDone && !this.parent), "Root nodes cannot have an \".onDone\" transition. Please check the config of \""
|
|
1528
|
+
utils.warn(!(this.config.onDone && !this.parent), "Root nodes cannot have an \".onDone\" transition. Please check the config of \"".concat(this.id, "\"."));
|
|
1534
1529
|
}
|
|
1535
1530
|
|
|
1536
1531
|
var invokeConfig = utils.flatten(this.invoke.map(function (invokeDef) {
|
|
1537
1532
|
var settleTransitions = [];
|
|
1538
1533
|
|
|
1539
1534
|
if (invokeDef.onDone) {
|
|
1540
|
-
settleTransitions.push.apply(settleTransitions, _tslib.__spreadArray([], _tslib.__read(utils.toTransitionConfigArray(String(actions.doneInvoke(invokeDef.id)), invokeDef.onDone))));
|
|
1535
|
+
settleTransitions.push.apply(settleTransitions, _tslib.__spreadArray([], _tslib.__read(utils.toTransitionConfigArray(String(actions.doneInvoke(invokeDef.id)), invokeDef.onDone)), false));
|
|
1541
1536
|
}
|
|
1542
1537
|
|
|
1543
1538
|
if (invokeDef.onError) {
|
|
1544
|
-
settleTransitions.push.apply(settleTransitions, _tslib.__spreadArray([], _tslib.__read(utils.toTransitionConfigArray(String(actions.error(invokeDef.id)), invokeDef.onError))));
|
|
1539
|
+
settleTransitions.push.apply(settleTransitions, _tslib.__spreadArray([], _tslib.__read(utils.toTransitionConfigArray(String(actions.error(invokeDef.id)), invokeDef.onError)), false));
|
|
1545
1540
|
}
|
|
1546
1541
|
|
|
1547
1542
|
return settleTransitions;
|
|
1548
1543
|
}));
|
|
1549
1544
|
var delayedTransitions = this.after;
|
|
1550
|
-
var formattedTransitions = utils.flatten(_tslib.__spreadArray(_tslib.__spreadArray(_tslib.__spreadArray(_tslib.__spreadArray([], _tslib.__read(doneConfig)), _tslib.__read(invokeConfig)), _tslib.__read(onConfig)), _tslib.__read(eventlessConfig)).map(function (transitionConfig) {
|
|
1545
|
+
var formattedTransitions = utils.flatten(_tslib.__spreadArray(_tslib.__spreadArray(_tslib.__spreadArray(_tslib.__spreadArray([], _tslib.__read(doneConfig), false), _tslib.__read(invokeConfig), false), _tslib.__read(onConfig), false), _tslib.__read(eventlessConfig), false).map(function (transitionConfig) {
|
|
1551
1546
|
return utils.toArray(transitionConfig).map(function (transition) {
|
|
1552
1547
|
return _this.formatTransition(transition);
|
|
1553
1548
|
});
|
package/lib/_virtual/_tslib.js
CHANGED
|
@@ -69,10 +69,14 @@ function __read(o, n) {
|
|
|
69
69
|
return ar;
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
function __spreadArray(to, from) {
|
|
73
|
-
for (var i = 0,
|
|
74
|
-
|
|
75
|
-
|
|
72
|
+
function __spreadArray(to, from, pack) {
|
|
73
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
74
|
+
if (ar || !(i in from)) {
|
|
75
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
76
|
+
ar[i] = from[i];
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
76
80
|
}
|
|
77
81
|
|
|
78
82
|
exports.__read = __read;
|
package/lib/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/lib/actions.js
CHANGED
|
@@ -156,6 +156,20 @@ function sendParent(event, options) {
|
|
|
156
156
|
to: types.SpecialTargets.Parent
|
|
157
157
|
}));
|
|
158
158
|
}
|
|
159
|
+
/**
|
|
160
|
+
* Sends an event to an actor.
|
|
161
|
+
*
|
|
162
|
+
* @param actor The `ActorRef` to send the event to.
|
|
163
|
+
* @param event The event to send, or an expression that evaluates to the event to send
|
|
164
|
+
* @param options Send action options
|
|
165
|
+
* @returns An XState send action object
|
|
166
|
+
*/
|
|
167
|
+
|
|
168
|
+
function sendTo(actor, event, options) {
|
|
169
|
+
return send(event, _tslib.__assign(_tslib.__assign({}, options), {
|
|
170
|
+
to: actor
|
|
171
|
+
}));
|
|
172
|
+
}
|
|
159
173
|
/**
|
|
160
174
|
* Sends an update event to this machine's parent.
|
|
161
175
|
*/
|
|
@@ -287,8 +301,8 @@ var assign = function (assignment) {
|
|
|
287
301
|
*/
|
|
288
302
|
|
|
289
303
|
function after(delayRef, id) {
|
|
290
|
-
var idSuffix = id ? "#"
|
|
291
|
-
return types.ActionTypes.After
|
|
304
|
+
var idSuffix = id ? "#".concat(id) : '';
|
|
305
|
+
return "".concat(types.ActionTypes.After, "(").concat(delayRef, ")").concat(idSuffix);
|
|
292
306
|
}
|
|
293
307
|
/**
|
|
294
308
|
* Returns an event that represents that a final state node
|
|
@@ -299,7 +313,7 @@ function after(delayRef, id) {
|
|
|
299
313
|
*/
|
|
300
314
|
|
|
301
315
|
function done(id, data) {
|
|
302
|
-
var type = types.ActionTypes.DoneState
|
|
316
|
+
var type = "".concat(types.ActionTypes.DoneState, ".").concat(id);
|
|
303
317
|
var eventObject = {
|
|
304
318
|
type: type,
|
|
305
319
|
data: data
|
|
@@ -322,7 +336,7 @@ function done(id, data) {
|
|
|
322
336
|
*/
|
|
323
337
|
|
|
324
338
|
function doneInvoke(id, data) {
|
|
325
|
-
var type = types.ActionTypes.DoneInvoke
|
|
339
|
+
var type = "".concat(types.ActionTypes.DoneInvoke, ".").concat(id);
|
|
326
340
|
var eventObject = {
|
|
327
341
|
type: type,
|
|
328
342
|
data: data
|
|
@@ -335,7 +349,7 @@ function doneInvoke(id, data) {
|
|
|
335
349
|
return eventObject;
|
|
336
350
|
}
|
|
337
351
|
function error(id, data) {
|
|
338
|
-
var type = types.ActionTypes.ErrorPlatform
|
|
352
|
+
var type = "".concat(types.ActionTypes.ErrorPlatform, ".").concat(id);
|
|
339
353
|
var eventObject = {
|
|
340
354
|
type: type,
|
|
341
355
|
data: data
|
|
@@ -417,7 +431,7 @@ function resolveActions(machine, currentState, currentContext, _event, actions,
|
|
|
417
431
|
if (!environment.IS_PRODUCTION) {
|
|
418
432
|
// warn after resolving as we can create better contextual message here
|
|
419
433
|
utils.warn(!utils.isString(actionObject.delay) || typeof sendAction.delay === 'number', // tslint:disable-next-line:max-line-length
|
|
420
|
-
"No delay reference for delay expression '"
|
|
434
|
+
"No delay reference for delay expression '".concat(actionObject.delay, "' was found on machine '").concat(machine.id, "'"));
|
|
421
435
|
}
|
|
422
436
|
|
|
423
437
|
return sendAction;
|
|
@@ -489,7 +503,7 @@ function resolveActions(machine, currentState, currentContext, _event, actions,
|
|
|
489
503
|
args[_i - 1] = arguments[_i];
|
|
490
504
|
}
|
|
491
505
|
|
|
492
|
-
exec_1.apply(void 0, _tslib.__spreadArray([preservedContexts[contextIndex_1]], _tslib.__read(args)));
|
|
506
|
+
exec_1.apply(void 0, _tslib.__spreadArray([preservedContexts[contextIndex_1]], _tslib.__read(args), false));
|
|
493
507
|
}
|
|
494
508
|
});
|
|
495
509
|
}
|
|
@@ -524,6 +538,7 @@ exports.resolveStop = resolveStop;
|
|
|
524
538
|
exports.respond = respond;
|
|
525
539
|
exports.send = send;
|
|
526
540
|
exports.sendParent = sendParent;
|
|
541
|
+
exports.sendTo = sendTo;
|
|
527
542
|
exports.sendUpdate = sendUpdate;
|
|
528
543
|
exports.start = start;
|
|
529
544
|
exports.stop = stop;
|
package/lib/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/lib/devTools.js
CHANGED
|
@@ -4,6 +4,10 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
// From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis
|
|
6
6
|
function getGlobal() {
|
|
7
|
+
if (typeof globalThis !== 'undefined') {
|
|
8
|
+
return globalThis;
|
|
9
|
+
}
|
|
10
|
+
|
|
7
11
|
if (typeof self !== 'undefined') {
|
|
8
12
|
return self;
|
|
9
13
|
}
|
package/lib/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/lib/index.js
CHANGED
package/lib/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;
|