xstate 4.27.0-pr2674-2021926101023 → 4.29.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 +210 -94
- package/README.md +5 -5
- 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/Machine.d.ts +4 -4
- package/es/State.d.ts +9 -6
- package/es/State.js +10 -3
- package/es/StateNode.d.ts +12 -11
- package/es/StateNode.js +61 -71
- 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 +4 -6
- package/es/devTools.js +4 -0
- package/es/index.d.ts +9 -3
- package/es/index.js +3 -2
- package/es/interpreter.d.ts +6 -10
- package/es/interpreter.js +40 -27
- package/es/model.types.d.ts +3 -3
- package/es/registry.js +1 -1
- package/es/schema.d.ts +1 -0
- package/es/schema.js +2 -1
- package/es/scxml.d.ts +1 -1
- package/es/stateUtils.d.ts +4 -4
- package/es/stateUtils.js +1 -1
- package/es/typegenTypes.d.ts +66 -37
- package/es/types.d.ts +42 -41
- package/es/utils.d.ts +6 -1
- package/es/utils.js +17 -10
- package/lib/Actor.js +4 -4
- package/lib/Machine.d.ts +4 -4
- package/lib/SimulatedClock.js +9 -5
- package/lib/State.d.ts +9 -6
- package/lib/State.js +10 -3
- package/lib/StateNode.d.ts +12 -11
- package/lib/StateNode.js +59 -69
- 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 +4 -6
- package/lib/devTools.js +4 -0
- package/lib/index.d.ts +9 -3
- package/lib/index.js +2 -0
- package/lib/interpreter.d.ts +6 -10
- package/lib/interpreter.js +38 -25
- package/lib/json.js +7 -7
- package/lib/model.js +14 -10
- package/lib/model.types.d.ts +3 -3
- package/lib/patterns.js +2 -2
- package/lib/registry.js +1 -1
- package/lib/schema.d.ts +1 -0
- package/lib/schema.js +2 -0
- package/lib/scxml.d.ts +1 -1
- package/lib/scxml.js +29 -25
- package/lib/stateUtils.d.ts +4 -4
- package/lib/stateUtils.js +1 -1
- package/lib/typegenTypes.d.ts +66 -37
- package/lib/types.d.ts +42 -41
- package/lib/utils.d.ts +6 -1
- package/lib/utils.js +18 -9
- package/package.json +7 -11
- package/dist/xstate.cjs.d.ts +0 -11
- package/dist/xstate.cjs.js +0 -16
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,8 +826,8 @@ 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));
|
|
835
|
-
return this.resolveTransition(stateTransition, currentState, _event);
|
|
829
|
+
stateTransition.configuration = _tslib.__spreadArray([], _tslib.__read(resolvedConfig), false);
|
|
830
|
+
return this.resolveTransition(stateTransition, currentState, currentState.context, _event);
|
|
836
831
|
};
|
|
837
832
|
|
|
838
833
|
StateNode.prototype.resolveRaisedTransition = function (state, _event, originalEvent) {
|
|
@@ -845,12 +840,12 @@ 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
|
};
|
|
852
847
|
|
|
853
|
-
StateNode.prototype.resolveTransition = function (stateTransition, currentState,
|
|
848
|
+
StateNode.prototype.resolveTransition = function (stateTransition, currentState, context, _event) {
|
|
854
849
|
var e_6, _a;
|
|
855
850
|
|
|
856
851
|
var _this = this;
|
|
@@ -859,10 +854,6 @@ function () {
|
|
|
859
854
|
_event = actions.initEvent;
|
|
860
855
|
}
|
|
861
856
|
|
|
862
|
-
if (context === void 0) {
|
|
863
|
-
context = this.machine.context;
|
|
864
|
-
}
|
|
865
|
-
|
|
866
857
|
var configuration = stateTransition.configuration; // Transition will "apply" if:
|
|
867
858
|
// - this is the initial state (there is no current state)
|
|
868
859
|
// - OR there are transitions
|
|
@@ -870,8 +861,7 @@ function () {
|
|
|
870
861
|
var willTransition = !currentState || stateTransition.transitions.length > 0;
|
|
871
862
|
var resolvedStateValue = willTransition ? stateUtils.getValue(this.machine, configuration) : undefined;
|
|
872
863
|
var historyValue = currentState ? currentState.historyValue ? currentState.historyValue : stateTransition.source ? this.machine.historyValue(currentState.value) : undefined : undefined;
|
|
873
|
-
var
|
|
874
|
-
var actions$1 = this.getActions(stateTransition, currentContext, _event, currentState);
|
|
864
|
+
var actions$1 = this.getActions(stateTransition, context, _event, currentState);
|
|
875
865
|
var activities = currentState ? _tslib.__assign({}, currentState.activities) : {};
|
|
876
866
|
|
|
877
867
|
try {
|
|
@@ -896,7 +886,7 @@ function () {
|
|
|
896
886
|
}
|
|
897
887
|
}
|
|
898
888
|
|
|
899
|
-
var _b = _tslib.__read(actions.resolveActions(this, currentState,
|
|
889
|
+
var _b = _tslib.__read(actions.resolveActions(this, currentState, context, _event, actions$1, this.machine.config.preserveActionOrder), 2),
|
|
900
890
|
resolvedActions = _b[0],
|
|
901
891
|
updatedContext = _b[1];
|
|
902
892
|
|
|
@@ -915,7 +905,7 @@ function () {
|
|
|
915
905
|
acc[action.activity.id] = Actor.createInvocableActor(action.activity, _this.machine, updatedContext, _event);
|
|
916
906
|
return acc;
|
|
917
907
|
}, currentState ? _tslib.__assign({}, currentState.children) : {});
|
|
918
|
-
var resolvedConfiguration =
|
|
908
|
+
var resolvedConfiguration = willTransition ? stateTransition.configuration : currentState ? currentState.configuration : [];
|
|
919
909
|
var isDone = stateUtils.isInFinalState(resolvedConfiguration, this);
|
|
920
910
|
var nextState = new State.State({
|
|
921
911
|
value: resolvedStateValue || currentState.value,
|
|
@@ -935,7 +925,7 @@ function () {
|
|
|
935
925
|
tags: currentState === null || currentState === void 0 ? void 0 : currentState.tags,
|
|
936
926
|
machine: this
|
|
937
927
|
});
|
|
938
|
-
var didUpdateContext =
|
|
928
|
+
var didUpdateContext = context !== updatedContext;
|
|
939
929
|
nextState.changed = _event.name === actionTypes.update || didUpdateContext; // Dispose of penultimate histories to prevent memory leaks
|
|
940
930
|
|
|
941
931
|
var history = nextState.history;
|
|
@@ -996,13 +986,13 @@ function () {
|
|
|
996
986
|
}
|
|
997
987
|
|
|
998
988
|
if (!this.states) {
|
|
999
|
-
throw new Error("Unable to retrieve child state '"
|
|
989
|
+
throw new Error("Unable to retrieve child state '".concat(stateKey, "' from '").concat(this.id, "'; no child states exist."));
|
|
1000
990
|
}
|
|
1001
991
|
|
|
1002
992
|
var result = this.states[stateKey];
|
|
1003
993
|
|
|
1004
994
|
if (!result) {
|
|
1005
|
-
throw new Error("Child state '"
|
|
995
|
+
throw new Error("Child state '".concat(stateKey, "' does not exist on '").concat(this.id, "'"));
|
|
1006
996
|
}
|
|
1007
997
|
|
|
1008
998
|
return result;
|
|
@@ -1024,7 +1014,7 @@ function () {
|
|
|
1024
1014
|
var stateNode = this.machine.idMap[resolvedStateId];
|
|
1025
1015
|
|
|
1026
1016
|
if (!stateNode) {
|
|
1027
|
-
throw new Error("Child state node '#"
|
|
1017
|
+
throw new Error("Child state node '#".concat(resolvedStateId, "' does not exist on machine '").concat(this.id, "'"));
|
|
1028
1018
|
}
|
|
1029
1019
|
|
|
1030
1020
|
return stateNode;
|
|
@@ -1111,7 +1101,7 @@ function () {
|
|
|
1111
1101
|
var stateNode = this.machine.idMap[stateIdentifier.slice(STATE_IDENTIFIER.length)];
|
|
1112
1102
|
|
|
1113
1103
|
if (!stateNode) {
|
|
1114
|
-
throw new Error("Unable to find state node '"
|
|
1104
|
+
throw new Error("Unable to find state node '".concat(stateIdentifier, "'"));
|
|
1115
1105
|
}
|
|
1116
1106
|
|
|
1117
1107
|
return stateNode.path;
|
|
@@ -1138,7 +1128,7 @@ function () {
|
|
|
1138
1128
|
});
|
|
1139
1129
|
} else if (this.initial !== undefined) {
|
|
1140
1130
|
if (!this.states[this.initial]) {
|
|
1141
|
-
throw new Error("Initial state '"
|
|
1131
|
+
throw new Error("Initial state '".concat(this.initial, "' not found on '").concat(this.key, "'"));
|
|
1142
1132
|
}
|
|
1143
1133
|
|
|
1144
1134
|
initialStateValue = stateUtils.isLeafNode(this.states[this.initial]) ? this.initial : (_a = {}, _a[this.initial] = this.states[this.initial].initialStateValue, _a);
|
|
@@ -1163,7 +1153,7 @@ function () {
|
|
|
1163
1153
|
transitions: [],
|
|
1164
1154
|
source: undefined,
|
|
1165
1155
|
actions: []
|
|
1166
|
-
}, undefined,
|
|
1156
|
+
}, undefined, context !== null && context !== void 0 ? context : this.machine.context, undefined);
|
|
1167
1157
|
};
|
|
1168
1158
|
|
|
1169
1159
|
Object.defineProperty(StateNode.prototype, "initialState", {
|
|
@@ -1178,7 +1168,7 @@ function () {
|
|
|
1178
1168
|
var initialStateValue = this.initialStateValue;
|
|
1179
1169
|
|
|
1180
1170
|
if (!initialStateValue) {
|
|
1181
|
-
throw new Error("Cannot retrieve initial state from simple state '"
|
|
1171
|
+
throw new Error("Cannot retrieve initial state from simple state '".concat(this.id, "'."));
|
|
1182
1172
|
}
|
|
1183
1173
|
|
|
1184
1174
|
return this.getInitialState(initialStateValue);
|
|
@@ -1236,7 +1226,7 @@ function () {
|
|
|
1236
1226
|
|
|
1237
1227
|
if (this.type === 'compound' && !this.initial) {
|
|
1238
1228
|
if (!environment.IS_PRODUCTION) {
|
|
1239
|
-
utils.warn(false, "Compound state node '"
|
|
1229
|
+
utils.warn(false, "Compound state node '".concat(this.id, "' has no initial state."));
|
|
1240
1230
|
}
|
|
1241
1231
|
|
|
1242
1232
|
return [this];
|
|
@@ -1267,7 +1257,7 @@ function () {
|
|
|
1267
1257
|
childStatePath = _a.slice(1);
|
|
1268
1258
|
|
|
1269
1259
|
if (!this.states) {
|
|
1270
|
-
throw new Error("Cannot retrieve subPath '"
|
|
1260
|
+
throw new Error("Cannot retrieve subPath '".concat(stateKey, "' from node with no states"));
|
|
1271
1261
|
}
|
|
1272
1262
|
|
|
1273
1263
|
var childStateNode = this.getStateNode(stateKey);
|
|
@@ -1277,7 +1267,7 @@ function () {
|
|
|
1277
1267
|
}
|
|
1278
1268
|
|
|
1279
1269
|
if (!this.states[stateKey]) {
|
|
1280
|
-
throw new Error("Child state '"
|
|
1270
|
+
throw new Error("Child state '".concat(stateKey, "' does not exist on '").concat(this.id, "'"));
|
|
1281
1271
|
}
|
|
1282
1272
|
|
|
1283
1273
|
return this.states[stateKey].getFromRelativePath(childStatePath);
|
|
@@ -1376,7 +1366,7 @@ function () {
|
|
|
1376
1366
|
try {
|
|
1377
1367
|
for (var _e = (e_8 = void 0, _tslib.__values(state.events)), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
1378
1368
|
var event_1 = _f.value;
|
|
1379
|
-
events.add(""
|
|
1369
|
+
events.add("".concat(event_1));
|
|
1380
1370
|
}
|
|
1381
1371
|
} catch (e_8_1) {
|
|
1382
1372
|
e_8 = {
|
|
@@ -1455,7 +1445,7 @@ function () {
|
|
|
1455
1445
|
|
|
1456
1446
|
return targetStateNode;
|
|
1457
1447
|
} catch (err) {
|
|
1458
|
-
throw new Error("Invalid transition definition for state node '"
|
|
1448
|
+
throw new Error("Invalid transition definition for state node '".concat(_this.id, "':\n").concat(err.message));
|
|
1459
1449
|
}
|
|
1460
1450
|
} else {
|
|
1461
1451
|
return _this.getStateNodeByPath(resolvedTarget);
|
|
@@ -1483,9 +1473,9 @@ function () {
|
|
|
1483
1473
|
toJSON: function () {
|
|
1484
1474
|
return _tslib.__assign(_tslib.__assign({}, transition), {
|
|
1485
1475
|
target: transition.target ? transition.target.map(function (t) {
|
|
1486
|
-
return "#"
|
|
1476
|
+
return "#".concat(t.id);
|
|
1487
1477
|
}) : undefined,
|
|
1488
|
-
source: "#"
|
|
1478
|
+
source: "#".concat(_this.id)
|
|
1489
1479
|
});
|
|
1490
1480
|
}
|
|
1491
1481
|
});
|
|
@@ -1513,7 +1503,7 @@ function () {
|
|
|
1513
1503
|
|
|
1514
1504
|
onConfig = utils.flatten(utils.keys(strictTransitionConfigs_1).map(function (key) {
|
|
1515
1505
|
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. " +
|
|
1506
|
+
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
1507
|
}
|
|
1518
1508
|
|
|
1519
1509
|
var transitionConfigArray = utils.toTransitionConfigArray(key, strictTransitionConfigs_1[key]);
|
|
@@ -1530,24 +1520,24 @@ function () {
|
|
|
1530
1520
|
var doneConfig = this.config.onDone ? utils.toTransitionConfigArray(String(actions.done(this.id)), this.config.onDone) : [];
|
|
1531
1521
|
|
|
1532
1522
|
if (!environment.IS_PRODUCTION) {
|
|
1533
|
-
utils.warn(!(this.config.onDone && !this.parent), "Root nodes cannot have an \".onDone\" transition. Please check the config of \""
|
|
1523
|
+
utils.warn(!(this.config.onDone && !this.parent), "Root nodes cannot have an \".onDone\" transition. Please check the config of \"".concat(this.id, "\"."));
|
|
1534
1524
|
}
|
|
1535
1525
|
|
|
1536
1526
|
var invokeConfig = utils.flatten(this.invoke.map(function (invokeDef) {
|
|
1537
1527
|
var settleTransitions = [];
|
|
1538
1528
|
|
|
1539
1529
|
if (invokeDef.onDone) {
|
|
1540
|
-
settleTransitions.push.apply(settleTransitions, _tslib.__spreadArray([], _tslib.__read(utils.toTransitionConfigArray(String(actions.doneInvoke(invokeDef.id)), invokeDef.onDone))));
|
|
1530
|
+
settleTransitions.push.apply(settleTransitions, _tslib.__spreadArray([], _tslib.__read(utils.toTransitionConfigArray(String(actions.doneInvoke(invokeDef.id)), invokeDef.onDone)), false));
|
|
1541
1531
|
}
|
|
1542
1532
|
|
|
1543
1533
|
if (invokeDef.onError) {
|
|
1544
|
-
settleTransitions.push.apply(settleTransitions, _tslib.__spreadArray([], _tslib.__read(utils.toTransitionConfigArray(String(actions.error(invokeDef.id)), invokeDef.onError))));
|
|
1534
|
+
settleTransitions.push.apply(settleTransitions, _tslib.__spreadArray([], _tslib.__read(utils.toTransitionConfigArray(String(actions.error(invokeDef.id)), invokeDef.onError)), false));
|
|
1545
1535
|
}
|
|
1546
1536
|
|
|
1547
1537
|
return settleTransitions;
|
|
1548
1538
|
}));
|
|
1549
1539
|
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) {
|
|
1540
|
+
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
1541
|
return utils.toArray(transitionConfig).map(function (transition) {
|
|
1552
1542
|
return _this.formatTransition(transition);
|
|
1553
1543
|
});
|
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,4 +1,4 @@
|
|
|
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, StopAction, StopActionObject } 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, StopAction, StopActionObject, Cast, ActorRef, EventFrom } from './types';
|
|
2
2
|
import * as actionTypes from './actionTypes';
|
|
3
3
|
import { State } from './State';
|
|
4
4
|
import { StateNode } from './StateNode';
|
|
@@ -37,6 +37,22 @@ export declare function resolveSend<TContext, TEvent extends EventObject, TSentE
|
|
|
37
37
|
* @param options Options to pass into the send event.
|
|
38
38
|
*/
|
|
39
39
|
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>;
|
|
40
|
+
declare type InferEvent<E extends EventObject> = {
|
|
41
|
+
[T in E['type']]: {
|
|
42
|
+
type: T;
|
|
43
|
+
} & Extract<E, {
|
|
44
|
+
type: T;
|
|
45
|
+
}>;
|
|
46
|
+
}[E['type']];
|
|
47
|
+
/**
|
|
48
|
+
* Sends an event to an actor.
|
|
49
|
+
*
|
|
50
|
+
* @param actor The `ActorRef` to send the event to.
|
|
51
|
+
* @param event The event to send, or an expression that evaluates to the event to send
|
|
52
|
+
* @param options Send action options
|
|
53
|
+
* @returns An XState send action object
|
|
54
|
+
*/
|
|
55
|
+
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>;
|
|
40
56
|
/**
|
|
41
57
|
* Sends an update event to this machine's parent.
|
|
42
58
|
*/
|
|
@@ -134,5 +150,5 @@ export declare function forwardTo<TContext, TEvent extends EventObject>(target:
|
|
|
134
150
|
*/
|
|
135
151
|
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
152
|
export declare function choose<TContext, TEvent extends EventObject>(conds: Array<ChooseCondition<TContext, TEvent>>): ChooseAction<TContext, TEvent>;
|
|
137
|
-
export declare function resolveActions<TContext, TEvent extends EventObject>(machine: StateNode<TContext, any, TEvent, any, any>, currentState: State<TContext, TEvent> | undefined, currentContext: TContext, _event: SCXML.Event<TEvent>, actions: Array<ActionObject<TContext, TEvent>>, preserveActionOrder?: boolean): [Array<ActionObject<TContext, TEvent>>, TContext];
|
|
153
|
+
export declare function resolveActions<TContext, TEvent extends EventObject>(machine: StateNode<TContext, any, TEvent, any, any, 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
154
|
//# sourceMappingURL=actions.d.ts.map
|
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,16 +1,14 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
1
|
import { AnyInterpreter } from './types';
|
|
3
|
-
import { Interpreter } from './interpreter';
|
|
4
2
|
declare type ServiceListener = (service: AnyInterpreter) => void;
|
|
5
3
|
export interface XStateDevInterface {
|
|
6
|
-
register: (service:
|
|
7
|
-
unregister: (service:
|
|
4
|
+
register: (service: AnyInterpreter) => void;
|
|
5
|
+
unregister: (service: AnyInterpreter) => void;
|
|
8
6
|
onRegister: (listener: ServiceListener) => {
|
|
9
7
|
unsubscribe: () => void;
|
|
10
8
|
};
|
|
11
|
-
services: Set<
|
|
9
|
+
services: Set<AnyInterpreter>;
|
|
12
10
|
}
|
|
13
|
-
export declare function getGlobal():
|
|
11
|
+
export declare function getGlobal(): typeof globalThis | undefined;
|
|
14
12
|
export declare function registerService(service: AnyInterpreter): void;
|
|
15
13
|
export {};
|
|
16
14
|
//# 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,14 +4,15 @@ 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
|
-
import { createSchema } from './schema';
|
|
10
|
+
import { createSchema, t } from './schema';
|
|
11
11
|
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;
|
|
@@ -26,7 +27,12 @@ declare const actions: {
|
|
|
26
27
|
choose: typeof choose;
|
|
27
28
|
pure: typeof pure;
|
|
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
|
+
export { Actor, Machine, StateNode, State, matchesState, mapState, actions, assign, send, sendParent, sendUpdate, forwardTo, interpret, Interpreter, InterpreterStatus, matchState, spawn, doneInvoke, createMachine, createSchema, t };
|
|
30
31
|
export * from './types';
|
|
31
32
|
export * from './typegenTypes';
|
|
33
|
+
declare global {
|
|
34
|
+
interface SymbolConstructor {
|
|
35
|
+
readonly observable: symbol;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
32
38
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.js
CHANGED
|
@@ -17,6 +17,7 @@ var actions = {
|
|
|
17
17
|
raise: actions$1.raise,
|
|
18
18
|
send: actions$1.send,
|
|
19
19
|
sendParent: actions$1.sendParent,
|
|
20
|
+
sendTo: actions$1.sendTo,
|
|
20
21
|
sendUpdate: actions$1.sendUpdate,
|
|
21
22
|
log: actions$1.log,
|
|
22
23
|
cancel: actions$1.cancel,
|
|
@@ -67,4 +68,5 @@ exports.interpret = interpreter.interpret;
|
|
|
67
68
|
exports.spawn = interpreter.spawn;
|
|
68
69
|
exports.matchState = match.matchState;
|
|
69
70
|
exports.createSchema = schema.createSchema;
|
|
71
|
+
exports.t = schema.t;
|
|
70
72
|
exports.actions = actions;
|