xstate 4.26.0-pr2674-20219515814 → 4.26.1
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 +37 -10
- package/dist/xstate.interpreter.js +1 -1
- package/dist/xstate.js +1 -1
- package/dist/xstate.web.js +2 -2
- package/es/Actor.d.ts +2 -1
- package/es/Machine.d.ts +4 -5
- package/es/State.d.ts +10 -12
- package/es/State.js +1 -1
- package/es/StateNode.d.ts +14 -15
- package/es/StateNode.js +39 -39
- package/es/_virtual/_tslib.js +8 -4
- package/es/actions.d.ts +5 -4
- package/es/actions.js +7 -7
- package/es/behaviors.d.ts +1 -1
- package/es/devTools.d.ts +2 -3
- package/es/devTools.js +4 -0
- package/es/each.d.ts +1 -1
- package/es/index.d.ts +0 -1
- package/es/interpreter.d.ts +25 -35
- package/es/interpreter.js +19 -17
- package/es/model.d.ts +2 -2
- package/es/model.types.d.ts +9 -8
- package/es/registry.js +1 -1
- package/es/scxml.d.ts +2 -2
- package/es/stateUtils.d.ts +6 -6
- package/es/stateUtils.js +8 -3
- package/es/types.d.ts +46 -60
- package/es/utils.d.ts +1 -1
- package/es/utils.js +10 -10
- package/lib/Actor.d.ts +2 -1
- package/lib/Machine.d.ts +4 -5
- package/lib/SimulatedClock.js +9 -5
- package/lib/State.d.ts +10 -12
- package/lib/State.js +1 -1
- package/lib/StateNode.d.ts +14 -15
- package/lib/StateNode.js +38 -38
- package/lib/_virtual/_tslib.js +8 -4
- package/lib/actions.d.ts +5 -4
- package/lib/actions.js +7 -7
- package/lib/behaviors.d.ts +1 -1
- package/lib/devTools.d.ts +2 -3
- package/lib/devTools.js +4 -0
- package/lib/each.d.ts +1 -1
- package/lib/index.d.ts +0 -1
- package/lib/interpreter.d.ts +25 -35
- package/lib/interpreter.js +19 -17
- package/lib/json.js +7 -7
- package/lib/model.d.ts +2 -2
- package/lib/model.js +14 -10
- package/lib/model.types.d.ts +9 -8
- package/lib/patterns.js +2 -2
- package/lib/registry.js +1 -1
- package/lib/scxml.d.ts +2 -2
- package/lib/scxml.js +29 -25
- package/lib/stateUtils.d.ts +6 -6
- package/lib/stateUtils.js +7 -1
- package/lib/types.d.ts +46 -60
- package/lib/utils.d.ts +1 -1
- package/lib/utils.js +10 -10
- package/package.json +4 -8
- package/dist/xstate.cjs.d.ts +0 -11
- package/dist/xstate.cjs.js +0 -16
- package/es/typegenTypes.d.ts +0 -78
- package/lib/typegenTypes.d.ts +0 -78
- package/lib/typegenTypes.js +0 -2
package/es/StateNode.js
CHANGED
|
@@ -3,7 +3,7 @@ import { STATE_DELIMITER } from './constants.js';
|
|
|
3
3
|
import { IS_PRODUCTION } from './environment.js';
|
|
4
4
|
import { isFunction, mapValues, isArray, flatten, keys, toArray, toStateValue, isString, getEventType, matchesState, path, evaluateGuard, mapContext, toSCXMLEvent, pathToStateValue, isBuiltInEvent, partition, updateHistoryValue, toStatePath, mapFilterValues, warn, toStatePaths, nestedPath, normalizeTarget, toGuard, toTransitionConfigArray, isMachine } from './utils.js';
|
|
5
5
|
import { SpecialTargets } from './types.js';
|
|
6
|
-
import { getAllStateNodes, getConfiguration, isInFinalState, has, getChildren, getValue, isLeafNode } from './stateUtils.js';
|
|
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';
|
|
8
8
|
import { done, start, raise, stop, toActionObjects, resolveActions, doneInvoke, error, toActionObject, toActivityDefinition, after, send, cancel, initEvent } from './actions.js';
|
|
9
9
|
import { State, stateValuesEqual } from './State.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;
|
|
@@ -166,7 +166,7 @@ function () {
|
|
|
166
166
|
src: invokeConfig.src
|
|
167
167
|
}));
|
|
168
168
|
} else if (isMachine(invokeConfig.src) || isFunction(invokeConfig.src)) {
|
|
169
|
-
var invokeSrc = _this.id
|
|
169
|
+
var invokeSrc = "".concat(_this.id, ":invocation[").concat(i, "]"); // TODO: util function
|
|
170
170
|
|
|
171
171
|
_this.machine.options.services = __assign((_b = {}, _b[invokeSrc] = invokeConfig.src, _b), _this.machine.options.services);
|
|
172
172
|
return toInvokeDefinition(__assign(__assign({
|
|
@@ -269,7 +269,8 @@ function () {
|
|
|
269
269
|
order: this.order || -1,
|
|
270
270
|
data: this.doneData,
|
|
271
271
|
invoke: this.invoke,
|
|
272
|
-
description: this.description
|
|
272
|
+
description: this.description,
|
|
273
|
+
tags: this.tags
|
|
273
274
|
};
|
|
274
275
|
},
|
|
275
276
|
enumerable: false,
|
|
@@ -346,7 +347,7 @@ function () {
|
|
|
346
347
|
}
|
|
347
348
|
|
|
348
349
|
var mutateEntryExit = function (delay, i) {
|
|
349
|
-
var delayRef = isFunction(delay) ? _this.id
|
|
350
|
+
var delayRef = isFunction(delay) ? "".concat(_this.id, ":delay[").concat(i, "]") : delay;
|
|
350
351
|
var eventType = after(delayRef, _this.id);
|
|
351
352
|
|
|
352
353
|
_this.onEntry.push(send(eventType, {
|
|
@@ -443,7 +444,8 @@ function () {
|
|
|
443
444
|
return new State(__assign(__assign({}, state), {
|
|
444
445
|
value: this.resolve(state.value),
|
|
445
446
|
configuration: configuration,
|
|
446
|
-
done: isInFinalState(configuration, this)
|
|
447
|
+
done: isInFinalState(configuration, this),
|
|
448
|
+
tags: getTagsFromConfiguration(configuration)
|
|
447
449
|
}));
|
|
448
450
|
};
|
|
449
451
|
|
|
@@ -578,7 +580,7 @@ function () {
|
|
|
578
580
|
try {
|
|
579
581
|
guardPassed = !cond || evaluateGuard(this.machine, cond, resolvedContext, _event, state);
|
|
580
582
|
} catch (err) {
|
|
581
|
-
throw new Error("Unable to evaluate guard '"
|
|
583
|
+
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));
|
|
582
584
|
}
|
|
583
585
|
|
|
584
586
|
if (guardPassed && isInState) {
|
|
@@ -586,7 +588,7 @@ function () {
|
|
|
586
588
|
nextStateNodes = candidate.target;
|
|
587
589
|
}
|
|
588
590
|
|
|
589
|
-
actions.push.apply(actions, __spreadArray([], __read(candidate.actions)));
|
|
591
|
+
actions.push.apply(actions, __spreadArray([], __read(candidate.actions), false));
|
|
590
592
|
selectedTransition = candidate;
|
|
591
593
|
break;
|
|
592
594
|
}
|
|
@@ -767,11 +769,11 @@ function () {
|
|
|
767
769
|
var _c = __read([flatten(Array.from(entryStates).map(function (stateNode) {
|
|
768
770
|
return __spreadArray(__spreadArray([], __read(stateNode.activities.map(function (activity) {
|
|
769
771
|
return start(activity);
|
|
770
|
-
}))), __read(stateNode.onEntry));
|
|
772
|
+
})), false), __read(stateNode.onEntry), false);
|
|
771
773
|
})).concat(doneEvents.map(raise)), flatten(Array.from(exitStates).map(function (stateNode) {
|
|
772
|
-
return __spreadArray(__spreadArray([], __read(stateNode.onExit)), __read(stateNode.activities.map(function (activity) {
|
|
774
|
+
return __spreadArray(__spreadArray([], __read(stateNode.onExit), false), __read(stateNode.activities.map(function (activity) {
|
|
773
775
|
return stop(activity);
|
|
774
|
-
})));
|
|
776
|
+
})), false);
|
|
775
777
|
}))], 2),
|
|
776
778
|
entryActions = _c[0],
|
|
777
779
|
exitActions = _c[1];
|
|
@@ -806,12 +808,12 @@ function () {
|
|
|
806
808
|
}
|
|
807
809
|
|
|
808
810
|
if (!IS_PRODUCTION && _event.name === WILDCARD) {
|
|
809
|
-
throw new Error("An event cannot have the wildcard type ('"
|
|
811
|
+
throw new Error("An event cannot have the wildcard type ('".concat(WILDCARD, "')"));
|
|
810
812
|
}
|
|
811
813
|
|
|
812
814
|
if (this.strict) {
|
|
813
815
|
if (!this.events.includes(_event.name) && !isBuiltInEvent(_event.name)) {
|
|
814
|
-
throw new Error("Machine '"
|
|
816
|
+
throw new Error("Machine '".concat(this.id, "' does not accept event '").concat(_event.name, "'"));
|
|
815
817
|
}
|
|
816
818
|
}
|
|
817
819
|
|
|
@@ -825,7 +827,7 @@ function () {
|
|
|
825
827
|
};
|
|
826
828
|
var prevConfig = getConfiguration([], this.getStateNodes(currentState.value));
|
|
827
829
|
var resolvedConfig = stateTransition.configuration.length ? getConfiguration(prevConfig, stateTransition.configuration) : prevConfig;
|
|
828
|
-
stateTransition.configuration = __spreadArray([], __read(resolvedConfig));
|
|
830
|
+
stateTransition.configuration = __spreadArray([], __read(resolvedConfig), false);
|
|
829
831
|
return this.resolveTransition(stateTransition, currentState, _event);
|
|
830
832
|
};
|
|
831
833
|
|
|
@@ -839,7 +841,7 @@ function () {
|
|
|
839
841
|
state._event = originalEvent;
|
|
840
842
|
state.event = originalEvent.data;
|
|
841
843
|
|
|
842
|
-
(_a = state.actions).unshift.apply(_a, __spreadArray([], __read(currentActions)));
|
|
844
|
+
(_a = state.actions).unshift.apply(_a, __spreadArray([], __read(currentActions), false));
|
|
843
845
|
|
|
844
846
|
return state;
|
|
845
847
|
};
|
|
@@ -976,9 +978,7 @@ function () {
|
|
|
976
978
|
maybeNextState.changed = changed; // Preserve original history after raised events
|
|
977
979
|
|
|
978
980
|
maybeNextState.history = history;
|
|
979
|
-
maybeNextState.tags =
|
|
980
|
-
return sn.tags;
|
|
981
|
-
})));
|
|
981
|
+
maybeNextState.tags = getTagsFromConfiguration(maybeNextState.configuration);
|
|
982
982
|
return maybeNextState;
|
|
983
983
|
};
|
|
984
984
|
/**
|
|
@@ -992,13 +992,13 @@ function () {
|
|
|
992
992
|
}
|
|
993
993
|
|
|
994
994
|
if (!this.states) {
|
|
995
|
-
throw new Error("Unable to retrieve child state '"
|
|
995
|
+
throw new Error("Unable to retrieve child state '".concat(stateKey, "' from '").concat(this.id, "'; no child states exist."));
|
|
996
996
|
}
|
|
997
997
|
|
|
998
998
|
var result = this.states[stateKey];
|
|
999
999
|
|
|
1000
1000
|
if (!result) {
|
|
1001
|
-
throw new Error("Child state '"
|
|
1001
|
+
throw new Error("Child state '".concat(stateKey, "' does not exist on '").concat(this.id, "'"));
|
|
1002
1002
|
}
|
|
1003
1003
|
|
|
1004
1004
|
return result;
|
|
@@ -1020,7 +1020,7 @@ function () {
|
|
|
1020
1020
|
var stateNode = this.machine.idMap[resolvedStateId];
|
|
1021
1021
|
|
|
1022
1022
|
if (!stateNode) {
|
|
1023
|
-
throw new Error("Child state node '#"
|
|
1023
|
+
throw new Error("Child state node '#".concat(resolvedStateId, "' does not exist on machine '").concat(this.id, "'"));
|
|
1024
1024
|
}
|
|
1025
1025
|
|
|
1026
1026
|
return stateNode;
|
|
@@ -1107,7 +1107,7 @@ function () {
|
|
|
1107
1107
|
var stateNode = this.machine.idMap[stateIdentifier.slice(STATE_IDENTIFIER.length)];
|
|
1108
1108
|
|
|
1109
1109
|
if (!stateNode) {
|
|
1110
|
-
throw new Error("Unable to find state node '"
|
|
1110
|
+
throw new Error("Unable to find state node '".concat(stateIdentifier, "'"));
|
|
1111
1111
|
}
|
|
1112
1112
|
|
|
1113
1113
|
return stateNode.path;
|
|
@@ -1134,7 +1134,7 @@ function () {
|
|
|
1134
1134
|
});
|
|
1135
1135
|
} else if (this.initial !== undefined) {
|
|
1136
1136
|
if (!this.states[this.initial]) {
|
|
1137
|
-
throw new Error("Initial state '"
|
|
1137
|
+
throw new Error("Initial state '".concat(this.initial, "' not found on '").concat(this.key, "'"));
|
|
1138
1138
|
}
|
|
1139
1139
|
|
|
1140
1140
|
initialStateValue = isLeafNode(this.states[this.initial]) ? this.initial : (_a = {}, _a[this.initial] = this.states[this.initial].initialStateValue, _a);
|
|
@@ -1174,7 +1174,7 @@ function () {
|
|
|
1174
1174
|
var initialStateValue = this.initialStateValue;
|
|
1175
1175
|
|
|
1176
1176
|
if (!initialStateValue) {
|
|
1177
|
-
throw new Error("Cannot retrieve initial state from simple state '"
|
|
1177
|
+
throw new Error("Cannot retrieve initial state from simple state '".concat(this.id, "'."));
|
|
1178
1178
|
}
|
|
1179
1179
|
|
|
1180
1180
|
return this.getInitialState(initialStateValue);
|
|
@@ -1232,7 +1232,7 @@ function () {
|
|
|
1232
1232
|
|
|
1233
1233
|
if (this.type === 'compound' && !this.initial) {
|
|
1234
1234
|
if (!IS_PRODUCTION) {
|
|
1235
|
-
warn(false, "Compound state node '"
|
|
1235
|
+
warn(false, "Compound state node '".concat(this.id, "' has no initial state."));
|
|
1236
1236
|
}
|
|
1237
1237
|
|
|
1238
1238
|
return [this];
|
|
@@ -1263,7 +1263,7 @@ function () {
|
|
|
1263
1263
|
childStatePath = _a.slice(1);
|
|
1264
1264
|
|
|
1265
1265
|
if (!this.states) {
|
|
1266
|
-
throw new Error("Cannot retrieve subPath '"
|
|
1266
|
+
throw new Error("Cannot retrieve subPath '".concat(stateKey, "' from node with no states"));
|
|
1267
1267
|
}
|
|
1268
1268
|
|
|
1269
1269
|
var childStateNode = this.getStateNode(stateKey);
|
|
@@ -1273,7 +1273,7 @@ function () {
|
|
|
1273
1273
|
}
|
|
1274
1274
|
|
|
1275
1275
|
if (!this.states[stateKey]) {
|
|
1276
|
-
throw new Error("Child state '"
|
|
1276
|
+
throw new Error("Child state '".concat(stateKey, "' does not exist on '").concat(this.id, "'"));
|
|
1277
1277
|
}
|
|
1278
1278
|
|
|
1279
1279
|
return this.states[stateKey].getFromRelativePath(childStatePath);
|
|
@@ -1372,7 +1372,7 @@ function () {
|
|
|
1372
1372
|
try {
|
|
1373
1373
|
for (var _e = (e_8 = void 0, __values(state.events)), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
1374
1374
|
var event_1 = _f.value;
|
|
1375
|
-
events.add(""
|
|
1375
|
+
events.add("".concat(event_1));
|
|
1376
1376
|
}
|
|
1377
1377
|
} catch (e_8_1) {
|
|
1378
1378
|
e_8 = {
|
|
@@ -1451,7 +1451,7 @@ function () {
|
|
|
1451
1451
|
|
|
1452
1452
|
return targetStateNode;
|
|
1453
1453
|
} catch (err) {
|
|
1454
|
-
throw new Error("Invalid transition definition for state node '"
|
|
1454
|
+
throw new Error("Invalid transition definition for state node '".concat(_this.id, "':\n").concat(err.message));
|
|
1455
1455
|
}
|
|
1456
1456
|
} else {
|
|
1457
1457
|
return _this.getStateNodeByPath(resolvedTarget);
|
|
@@ -1479,9 +1479,9 @@ function () {
|
|
|
1479
1479
|
toJSON: function () {
|
|
1480
1480
|
return __assign(__assign({}, transition), {
|
|
1481
1481
|
target: transition.target ? transition.target.map(function (t) {
|
|
1482
|
-
return "#"
|
|
1482
|
+
return "#".concat(t.id);
|
|
1483
1483
|
}) : undefined,
|
|
1484
|
-
source: "#"
|
|
1484
|
+
source: "#".concat(_this.id)
|
|
1485
1485
|
});
|
|
1486
1486
|
}
|
|
1487
1487
|
});
|
|
@@ -1509,7 +1509,7 @@ function () {
|
|
|
1509
1509
|
|
|
1510
1510
|
onConfig = flatten(keys(strictTransitionConfigs_1).map(function (key) {
|
|
1511
1511
|
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. " +
|
|
1512
|
+
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
1513
|
}
|
|
1514
1514
|
|
|
1515
1515
|
var transitionConfigArray = toTransitionConfigArray(key, strictTransitionConfigs_1[key]);
|
|
@@ -1526,24 +1526,24 @@ function () {
|
|
|
1526
1526
|
var doneConfig = this.config.onDone ? toTransitionConfigArray(String(done(this.id)), this.config.onDone) : [];
|
|
1527
1527
|
|
|
1528
1528
|
if (!IS_PRODUCTION) {
|
|
1529
|
-
warn(!(this.config.onDone && !this.parent), "Root nodes cannot have an \".onDone\" transition. Please check the config of \""
|
|
1529
|
+
warn(!(this.config.onDone && !this.parent), "Root nodes cannot have an \".onDone\" transition. Please check the config of \"".concat(this.id, "\"."));
|
|
1530
1530
|
}
|
|
1531
1531
|
|
|
1532
1532
|
var invokeConfig = flatten(this.invoke.map(function (invokeDef) {
|
|
1533
1533
|
var settleTransitions = [];
|
|
1534
1534
|
|
|
1535
1535
|
if (invokeDef.onDone) {
|
|
1536
|
-
settleTransitions.push.apply(settleTransitions, __spreadArray([], __read(toTransitionConfigArray(String(doneInvoke(invokeDef.id)), invokeDef.onDone))));
|
|
1536
|
+
settleTransitions.push.apply(settleTransitions, __spreadArray([], __read(toTransitionConfigArray(String(doneInvoke(invokeDef.id)), invokeDef.onDone)), false));
|
|
1537
1537
|
}
|
|
1538
1538
|
|
|
1539
1539
|
if (invokeDef.onError) {
|
|
1540
|
-
settleTransitions.push.apply(settleTransitions, __spreadArray([], __read(toTransitionConfigArray(String(error(invokeDef.id)), invokeDef.onError))));
|
|
1540
|
+
settleTransitions.push.apply(settleTransitions, __spreadArray([], __read(toTransitionConfigArray(String(error(invokeDef.id)), invokeDef.onError)), false));
|
|
1541
1541
|
}
|
|
1542
1542
|
|
|
1543
1543
|
return settleTransitions;
|
|
1544
1544
|
}));
|
|
1545
1545
|
var delayedTransitions = this.after;
|
|
1546
|
-
var formattedTransitions = flatten(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], __read(doneConfig)), __read(invokeConfig)), __read(onConfig)), __read(eventlessConfig)).map(function (transitionConfig) {
|
|
1546
|
+
var formattedTransitions = flatten(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], __read(doneConfig), false), __read(invokeConfig), false), __read(onConfig), false), __read(eventlessConfig), false).map(function (transitionConfig) {
|
|
1547
1547
|
return toArray(transitionConfig).map(function (transition) {
|
|
1548
1548
|
return _this.formatTransition(transition);
|
|
1549
1549
|
});
|
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,14 +1,15 @@
|
|
|
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,
|
|
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';
|
|
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
6
|
export { actionTypes };
|
|
6
7
|
export declare const initEvent: SCXML.Event<{
|
|
7
8
|
type: ActionTypes;
|
|
8
9
|
}>;
|
|
9
10
|
export declare function getActionFunction<TContext, TEvent extends EventObject>(actionType: ActionType, actionFunctionMap?: ActionFunctionMap<TContext, TEvent>): ActionObject<TContext, TEvent> | ActionFunction<TContext, TEvent> | undefined;
|
|
10
11
|
export declare function toActionObject<TContext, TEvent extends EventObject>(action: Action<TContext, TEvent>, actionFunctionMap?: ActionFunctionMap<TContext, TEvent>): ActionObject<TContext, TEvent>;
|
|
11
|
-
export declare const toActionObjects: <TContext, TEvent extends EventObject>(action?: SingleOrArray<Action<TContext, TEvent>> | undefined, actionFunctionMap?: ActionFunctionMap<TContext, TEvent,
|
|
12
|
+
export declare const toActionObjects: <TContext, TEvent extends EventObject>(action?: SingleOrArray<Action<TContext, TEvent>> | undefined, actionFunctionMap?: ActionFunctionMap<TContext, TEvent, ActionObject<TContext, TEvent>> | undefined) => ActionObject<TContext, TEvent>[];
|
|
12
13
|
export declare function toActivityDefinition<TContext, TEvent extends EventObject>(action: string | ActivityDefinition<TContext, TEvent>): ActivityDefinition<TContext, TEvent>;
|
|
13
14
|
/**
|
|
14
15
|
* Raises an event. This places the event in the internal event queue, so that
|
|
@@ -133,6 +134,6 @@ export declare function forwardTo<TContext, TEvent extends EventObject>(target:
|
|
|
133
134
|
* @param options Options to pass into the send action creator.
|
|
134
135
|
*/
|
|
135
136
|
export declare function escalate<TContext, TEvent extends EventObject, TErrorData = any>(errorData: TErrorData | ExprWithMeta<TContext, TEvent, TErrorData>, options?: SendActionOptions<TContext, TEvent>): SendAction<TContext, TEvent, AnyEventObject>;
|
|
136
|
-
export declare function choose<TContext, TEvent extends EventObject>(conds: Array<
|
|
137
|
-
export declare function resolveActions<TContext, TEvent extends EventObject>(machine: StateNode<TContext, any, TEvent, any
|
|
137
|
+
export declare function choose<TContext, TEvent extends EventObject>(conds: Array<ChooseCondition<TContext, TEvent>>): ChooseAction<TContext, TEvent>;
|
|
138
|
+
export declare function resolveActions<TContext, TEvent extends EventObject>(machine: StateNode<TContext, any, TEvent, any>, currentState: State<TContext, TEvent> | undefined, currentContext: TContext, _event: SCXML.Event<TEvent>, actions: Array<ActionObject<TContext, TEvent>>, preserveActionOrder?: boolean): [Array<ActionObject<TContext, TEvent>>, TContext];
|
|
138
139
|
//# sourceMappingURL=actions.d.ts.map
|
package/es/actions.js
CHANGED
|
@@ -283,8 +283,8 @@ var assign = function (assignment) {
|
|
|
283
283
|
*/
|
|
284
284
|
|
|
285
285
|
function after(delayRef, id) {
|
|
286
|
-
var idSuffix = id ? "#"
|
|
287
|
-
return ActionTypes.After
|
|
286
|
+
var idSuffix = id ? "#".concat(id) : '';
|
|
287
|
+
return "".concat(ActionTypes.After, "(").concat(delayRef, ")").concat(idSuffix);
|
|
288
288
|
}
|
|
289
289
|
/**
|
|
290
290
|
* Returns an event that represents that a final state node
|
|
@@ -295,7 +295,7 @@ function after(delayRef, id) {
|
|
|
295
295
|
*/
|
|
296
296
|
|
|
297
297
|
function done(id, data) {
|
|
298
|
-
var type = ActionTypes.DoneState
|
|
298
|
+
var type = "".concat(ActionTypes.DoneState, ".").concat(id);
|
|
299
299
|
var eventObject = {
|
|
300
300
|
type: type,
|
|
301
301
|
data: data
|
|
@@ -318,7 +318,7 @@ function done(id, data) {
|
|
|
318
318
|
*/
|
|
319
319
|
|
|
320
320
|
function doneInvoke(id, data) {
|
|
321
|
-
var type = ActionTypes.DoneInvoke
|
|
321
|
+
var type = "".concat(ActionTypes.DoneInvoke, ".").concat(id);
|
|
322
322
|
var eventObject = {
|
|
323
323
|
type: type,
|
|
324
324
|
data: data
|
|
@@ -331,7 +331,7 @@ function doneInvoke(id, data) {
|
|
|
331
331
|
return eventObject;
|
|
332
332
|
}
|
|
333
333
|
function error(id, data) {
|
|
334
|
-
var type = ActionTypes.ErrorPlatform
|
|
334
|
+
var type = "".concat(ActionTypes.ErrorPlatform, ".").concat(id);
|
|
335
335
|
var eventObject = {
|
|
336
336
|
type: type,
|
|
337
337
|
data: data
|
|
@@ -413,7 +413,7 @@ function resolveActions(machine, currentState, currentContext, _event, actions,
|
|
|
413
413
|
if (!IS_PRODUCTION) {
|
|
414
414
|
// warn after resolving as we can create better contextual message here
|
|
415
415
|
warn(!isString(actionObject.delay) || typeof sendAction.delay === 'number', // tslint:disable-next-line:max-line-length
|
|
416
|
-
"No delay reference for delay expression '"
|
|
416
|
+
"No delay reference for delay expression '".concat(actionObject.delay, "' was found on machine '").concat(machine.id, "'"));
|
|
417
417
|
}
|
|
418
418
|
|
|
419
419
|
return sendAction;
|
|
@@ -485,7 +485,7 @@ function resolveActions(machine, currentState, currentContext, _event, actions,
|
|
|
485
485
|
args[_i - 1] = arguments[_i];
|
|
486
486
|
}
|
|
487
487
|
|
|
488
|
-
exec_1.apply(void 0, __spreadArray([preservedContexts[contextIndex_1]], __read(args)));
|
|
488
|
+
exec_1.apply(void 0, __spreadArray([preservedContexts[contextIndex_1]], __read(args), false));
|
|
489
489
|
}
|
|
490
490
|
});
|
|
491
491
|
}
|
package/es/behaviors.d.ts
CHANGED
package/es/devTools.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import { Interpreter } from '.';
|
|
2
2
|
import { AnyInterpreter } from './types';
|
|
3
|
-
import { Interpreter } from './interpreter';
|
|
4
3
|
declare type ServiceListener = (service: AnyInterpreter) => void;
|
|
5
4
|
export interface XStateDevInterface {
|
|
6
5
|
register: (service: Interpreter<any>) => 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/each.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EventObject, SingleOrArray, ActionObject } from '
|
|
1
|
+
import { EventObject, SingleOrArray, ActionObject } from '.';
|
|
2
2
|
export declare function each<TContext, TEvent extends EventObject>(collection: keyof TContext, item: keyof TContext, actions: SingleOrArray<ActionObject<TContext, TEvent>>): ActionObject<TContext, TEvent>;
|
|
3
3
|
export declare function each<TContext, TEvent extends EventObject>(collection: keyof TContext, item: keyof TContext, index: keyof TContext, actions: SingleOrArray<ActionObject<TContext, TEvent>>): ActionObject<TContext, TEvent>;
|
|
4
4
|
//# sourceMappingURL=each.d.ts.map
|
package/es/index.d.ts
CHANGED
|
@@ -28,5 +28,4 @@ declare const actions: {
|
|
|
28
28
|
};
|
|
29
29
|
export { Actor, Machine, StateNode, State, matchesState, mapState, actions, assign, send, sendParent, sendUpdate, forwardTo, interpret, Interpreter, InterpreterStatus, matchState, spawn, doneInvoke, createMachine, createSchema };
|
|
30
30
|
export * from './types';
|
|
31
|
-
export * from './typegenTypes';
|
|
32
31
|
//# sourceMappingURL=index.d.ts.map
|
package/es/interpreter.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { StateMachine, Event, EventObject, DefaultContext, StateSchema, StateValue, InterpreterOptions, SingleOrArray, Subscribable, DoneEvent, MachineOptions, SCXML, EventData, Observer, Spawnable, Typestate, ActorRef, ActorRefFrom, Behavior, Subscription } from './types';
|
|
2
2
|
import { State } from './State';
|
|
3
|
-
import { AreAllImplementationsAssumedToBeProvided, TypegenDisabled } from './typegenTypes';
|
|
4
3
|
export declare type StateListener<TContext, TEvent extends EventObject, TStateSchema extends StateSchema<TContext> = any, TTypestate extends Typestate<TContext> = {
|
|
5
4
|
value: any;
|
|
6
5
|
context: TContext;
|
|
7
|
-
}
|
|
6
|
+
}> = (state: State<TContext, TEvent, TStateSchema, TTypestate>, event: TEvent) => void;
|
|
8
7
|
export declare type ContextListener<TContext = DefaultContext> = (context: TContext, prevContext: TContext | undefined) => void;
|
|
9
8
|
export declare type EventListener<TEvent extends EventObject = EventObject> = (event: TEvent) => void;
|
|
10
9
|
export declare type Listener = () => void;
|
|
@@ -30,24 +29,15 @@ declare global {
|
|
|
30
29
|
export declare class Interpreter<TContext, TStateSchema extends StateSchema = any, TEvent extends EventObject = EventObject, TTypestate extends Typestate<TContext> = {
|
|
31
30
|
value: any;
|
|
32
31
|
context: TContext;
|
|
33
|
-
}
|
|
34
|
-
machine: StateMachine<TContext, TStateSchema, TEvent, TTypestate
|
|
32
|
+
}> implements ActorRef<TEvent, State<TContext, TEvent, TStateSchema, TTypestate>> {
|
|
33
|
+
machine: StateMachine<TContext, TStateSchema, TEvent, TTypestate>;
|
|
35
34
|
/**
|
|
36
35
|
* The default interpreter options:
|
|
37
36
|
*
|
|
38
37
|
* - `clock` uses the global `setTimeout` and `clearTimeout` functions
|
|
39
38
|
* - `logger` uses the global `console.log()` method
|
|
40
39
|
*/
|
|
41
|
-
static defaultOptions:
|
|
42
|
-
execute: boolean;
|
|
43
|
-
deferEvents: boolean;
|
|
44
|
-
clock: {
|
|
45
|
-
setTimeout: (fn: any, ms: any) => number;
|
|
46
|
-
clearTimeout: (id: any) => void;
|
|
47
|
-
};
|
|
48
|
-
logger: any;
|
|
49
|
-
devTools: boolean;
|
|
50
|
-
};
|
|
40
|
+
static defaultOptions: InterpreterOptions;
|
|
51
41
|
/**
|
|
52
42
|
* The current state of the interpreted machine.
|
|
53
43
|
*/
|
|
@@ -87,9 +77,9 @@ export declare class Interpreter<TContext, TStateSchema extends StateSchema = an
|
|
|
87
77
|
* @param machine The machine to be interpreted
|
|
88
78
|
* @param options Interpreter options
|
|
89
79
|
*/
|
|
90
|
-
constructor(machine: StateMachine<TContext, TStateSchema, TEvent, TTypestate
|
|
91
|
-
get initialState(): State<TContext, TEvent, TStateSchema, TTypestate
|
|
92
|
-
get state(): State<TContext, TEvent, TStateSchema, TTypestate
|
|
80
|
+
constructor(machine: StateMachine<TContext, TStateSchema, TEvent, TTypestate>, options?: Partial<InterpreterOptions>);
|
|
81
|
+
get initialState(): State<TContext, TEvent, TStateSchema, TTypestate>;
|
|
82
|
+
get state(): State<TContext, TEvent, TStateSchema, TTypestate>;
|
|
93
83
|
static interpret: typeof interpret;
|
|
94
84
|
/**
|
|
95
85
|
* Executes the actions of the given state, with that state's `context` and `event`.
|
|
@@ -97,56 +87,56 @@ export declare class Interpreter<TContext, TStateSchema extends StateSchema = an
|
|
|
97
87
|
* @param state The state whose actions will be executed
|
|
98
88
|
* @param actionsConfig The action implementations to use
|
|
99
89
|
*/
|
|
100
|
-
execute(state: State<TContext, TEvent, TStateSchema, TTypestate
|
|
90
|
+
execute(state: State<TContext, TEvent, TStateSchema, TTypestate>, actionsConfig?: MachineOptions<TContext, TEvent>['actions']): void;
|
|
101
91
|
private update;
|
|
102
|
-
onTransition(listener: StateListener<TContext, TEvent, TStateSchema, TTypestate
|
|
103
|
-
subscribe(nextListener?: (state: State<TContext, TEvent, any, TTypestate
|
|
104
|
-
subscribe(observer: Observer<State<TContext, TEvent, any, TTypestate
|
|
92
|
+
onTransition(listener: StateListener<TContext, TEvent, TStateSchema, TTypestate>): this;
|
|
93
|
+
subscribe(nextListener?: (state: State<TContext, TEvent, any, TTypestate>) => void, errorListener?: (error: any) => void, completeListener?: () => void): Subscription;
|
|
94
|
+
subscribe(observer: Observer<State<TContext, TEvent, any, TTypestate>>): Subscription;
|
|
105
95
|
/**
|
|
106
96
|
* Adds an event listener that is notified whenever an event is sent to the running interpreter.
|
|
107
97
|
* @param listener The event listener
|
|
108
98
|
*/
|
|
109
|
-
onEvent(listener: EventListener):
|
|
99
|
+
onEvent(listener: EventListener): Interpreter<TContext, TStateSchema, TEvent, TTypestate>;
|
|
110
100
|
/**
|
|
111
101
|
* Adds an event listener that is notified whenever a `send` event occurs.
|
|
112
102
|
* @param listener The event listener
|
|
113
103
|
*/
|
|
114
|
-
onSend(listener: EventListener):
|
|
104
|
+
onSend(listener: EventListener): Interpreter<TContext, TStateSchema, TEvent, TTypestate>;
|
|
115
105
|
/**
|
|
116
106
|
* Adds a context listener that is notified whenever the state context changes.
|
|
117
107
|
* @param listener The context listener
|
|
118
108
|
*/
|
|
119
|
-
onChange(listener: ContextListener<TContext>):
|
|
109
|
+
onChange(listener: ContextListener<TContext>): Interpreter<TContext, TStateSchema, TEvent, TTypestate>;
|
|
120
110
|
/**
|
|
121
111
|
* Adds a listener that is notified when the machine is stopped.
|
|
122
112
|
* @param listener The listener
|
|
123
113
|
*/
|
|
124
|
-
onStop(listener: Listener):
|
|
114
|
+
onStop(listener: Listener): Interpreter<TContext, TStateSchema, TEvent, TTypestate>;
|
|
125
115
|
/**
|
|
126
116
|
* Adds a state listener that is notified when the statechart has reached its final state.
|
|
127
117
|
* @param listener The state listener
|
|
128
118
|
*/
|
|
129
|
-
onDone(listener: EventListener<DoneEvent>):
|
|
119
|
+
onDone(listener: EventListener<DoneEvent>): Interpreter<TContext, TStateSchema, TEvent, TTypestate>;
|
|
130
120
|
/**
|
|
131
121
|
* Removes a listener.
|
|
132
122
|
* @param listener The listener to remove
|
|
133
123
|
*/
|
|
134
|
-
off(listener: (...args: any[]) => void):
|
|
124
|
+
off(listener: (...args: any[]) => void): Interpreter<TContext, TStateSchema, TEvent, TTypestate>;
|
|
135
125
|
/**
|
|
136
126
|
* Alias for Interpreter.prototype.start
|
|
137
127
|
*/
|
|
138
|
-
init: (initialState?: StateValue | State<TContext, TEvent, TStateSchema, TTypestate
|
|
128
|
+
init: (initialState?: StateValue | State<TContext, TEvent, TStateSchema, TTypestate> | undefined) => Interpreter<TContext, TStateSchema, TEvent, TTypestate>;
|
|
139
129
|
/**
|
|
140
130
|
* Starts the interpreter from the given state, or the initial state.
|
|
141
131
|
* @param initialState The state to start the statechart from
|
|
142
132
|
*/
|
|
143
|
-
start(initialState?: State<TContext, TEvent, TStateSchema, TTypestate
|
|
133
|
+
start(initialState?: State<TContext, TEvent, TStateSchema, TTypestate> | StateValue): Interpreter<TContext, TStateSchema, TEvent, TTypestate>;
|
|
144
134
|
/**
|
|
145
135
|
* Stops the interpreter and unsubscribe all listeners.
|
|
146
136
|
*
|
|
147
137
|
* This will also notify the `onStop` listeners.
|
|
148
138
|
*/
|
|
149
|
-
stop():
|
|
139
|
+
stop(): Interpreter<TContext, TStateSchema, TEvent, TTypestate>;
|
|
150
140
|
/**
|
|
151
141
|
* Sends an event to the running interpreter to trigger a transition.
|
|
152
142
|
*
|
|
@@ -156,7 +146,7 @@ export declare class Interpreter<TContext, TStateSchema extends StateSchema = an
|
|
|
156
146
|
*
|
|
157
147
|
* @param event The event(s) to send
|
|
158
148
|
*/
|
|
159
|
-
send: (event: SingleOrArray<Event<TEvent>> | SCXML.Event<TEvent>, payload?: EventData | undefined) => State<TContext, TEvent, TStateSchema, TTypestate
|
|
149
|
+
send: (event: SingleOrArray<Event<TEvent>> | SCXML.Event<TEvent>, payload?: EventData | undefined) => State<TContext, TEvent, TStateSchema, TTypestate>;
|
|
160
150
|
private batch;
|
|
161
151
|
/**
|
|
162
152
|
* Returns a send function bound to this interpreter instance.
|
|
@@ -172,7 +162,7 @@ export declare class Interpreter<TContext, TStateSchema extends StateSchema = an
|
|
|
172
162
|
*
|
|
173
163
|
* @param event The event to determine the next state
|
|
174
164
|
*/
|
|
175
|
-
nextState(event: Event<TEvent> | SCXML.Event<TEvent>): State<TContext, TEvent, TStateSchema, TTypestate
|
|
165
|
+
nextState(event: Event<TEvent> | SCXML.Event<TEvent>): State<TContext, TEvent, TStateSchema, TTypestate>;
|
|
176
166
|
private forward;
|
|
177
167
|
private defer;
|
|
178
168
|
private cancel;
|
|
@@ -196,8 +186,8 @@ export declare class Interpreter<TContext, TStateSchema extends StateSchema = an
|
|
|
196
186
|
toJSON(): {
|
|
197
187
|
id: string;
|
|
198
188
|
};
|
|
199
|
-
[Symbol.observable](): Subscribable<State<TContext, TEvent, TStateSchema, TTypestate
|
|
200
|
-
getSnapshot(): State<TContext, TEvent, TStateSchema, TTypestate
|
|
189
|
+
[Symbol.observable](): Subscribable<State<TContext, TEvent, TStateSchema, TTypestate>>;
|
|
190
|
+
getSnapshot(): State<TContext, TEvent, TStateSchema, TTypestate>;
|
|
201
191
|
}
|
|
202
192
|
export declare function spawn<T extends Behavior<any, any>>(entity: T, nameOrOptions?: string | SpawnOptions): ActorRefFrom<T>;
|
|
203
193
|
export declare function spawn<TC, TE extends EventObject>(entity: StateMachine<TC, any, TE>, nameOrOptions?: string | SpawnOptions): ActorRefFrom<StateMachine<TC, any, TE>>;
|
|
@@ -211,6 +201,6 @@ export declare function spawn(entity: Spawnable, nameOrOptions?: string | SpawnO
|
|
|
211
201
|
export declare function interpret<TContext = DefaultContext, TStateSchema extends StateSchema = any, TEvent extends EventObject = EventObject, TTypestate extends Typestate<TContext> = {
|
|
212
202
|
value: any;
|
|
213
203
|
context: TContext;
|
|
214
|
-
}
|
|
204
|
+
}>(machine: StateMachine<TContext, TStateSchema, TEvent, TTypestate>, options?: Partial<InterpreterOptions>): Interpreter<TContext, TStateSchema, TEvent, TTypestate>;
|
|
215
205
|
export {};
|
|
216
206
|
//# sourceMappingURL=interpreter.d.ts.map
|