xstate 4.26.0 → 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 +8 -0
- package/dist/xstate.interpreter.js +1 -1
- package/dist/xstate.js +1 -1
- package/dist/xstate.web.js +1 -1
- package/es/State.d.ts +1 -1
- package/es/State.js +1 -1
- package/es/StateNode.js +33 -33
- package/es/_virtual/_tslib.js +8 -4
- package/es/actions.js +7 -7
- package/es/devTools.d.ts +1 -2
- package/es/devTools.js +4 -0
- package/es/interpreter.js +17 -16
- package/es/registry.js +1 -1
- package/es/stateUtils.js +1 -1
- package/es/types.d.ts +0 -8
- package/es/utils.js +9 -9
- package/lib/SimulatedClock.js +9 -5
- package/lib/State.d.ts +1 -1
- package/lib/State.js +1 -1
- package/lib/StateNode.js +33 -33
- package/lib/_virtual/_tslib.js +8 -4
- package/lib/actions.js +7 -7
- package/lib/devTools.d.ts +1 -2
- package/lib/devTools.js +4 -0
- package/lib/interpreter.js +17 -16
- 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.js +1 -1
- package/lib/types.d.ts +0 -8
- package/lib/utils.js +9 -9
- package/package.json +3 -3
package/lib/interpreter.js
CHANGED
|
@@ -90,14 +90,15 @@ function () {
|
|
|
90
90
|
if (_this.status === exports.InterpreterStatus.Stopped) {
|
|
91
91
|
// do nothing
|
|
92
92
|
if (!environment.IS_PRODUCTION) {
|
|
93
|
-
utils.warn(false, "Event \""
|
|
93
|
+
utils.warn(false, "Event \"".concat(_event.name, "\" was sent to stopped service \"").concat(_this.machine.id, "\". This service has already reached its final state, and will not transition.\nEvent: ").concat(JSON.stringify(_event.data)));
|
|
94
94
|
}
|
|
95
95
|
|
|
96
96
|
return _this.state;
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
if (_this.status !== exports.InterpreterStatus.Running && !_this.options.deferEvents) {
|
|
100
|
-
throw new Error("Event \""
|
|
100
|
+
throw new Error("Event \"".concat(_event.name, "\" was sent to uninitialized service \"").concat(_this.machine.id // tslint:disable-next-line:max-line-length
|
|
101
|
+
, "\". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.\nEvent: ").concat(JSON.stringify(_event.data)));
|
|
101
102
|
}
|
|
102
103
|
|
|
103
104
|
_this.scheduler.schedule(function () {
|
|
@@ -119,12 +120,12 @@ function () {
|
|
|
119
120
|
|
|
120
121
|
if (!target) {
|
|
121
122
|
if (!isParent) {
|
|
122
|
-
throw new Error("Unable to send event to child '"
|
|
123
|
+
throw new Error("Unable to send event to child '".concat(to, "' from service '").concat(_this.id, "'."));
|
|
123
124
|
} // tslint:disable-next-line:no-console
|
|
124
125
|
|
|
125
126
|
|
|
126
127
|
if (!environment.IS_PRODUCTION) {
|
|
127
|
-
utils.warn(false, "Service '"
|
|
128
|
+
utils.warn(false, "Service '".concat(_this.id, "' has no parent: unable to send event ").concat(event.type));
|
|
128
129
|
}
|
|
129
130
|
|
|
130
131
|
return;
|
|
@@ -133,7 +134,7 @@ function () {
|
|
|
133
134
|
if ('machine' in target) {
|
|
134
135
|
// Send SCXML events to machines
|
|
135
136
|
target.send(_tslib.__assign(_tslib.__assign({}, event), {
|
|
136
|
-
name: event.name === actionTypes.error ? ""
|
|
137
|
+
name: event.name === actionTypes.error ? "".concat(actions.error(_this.id)) : event.name,
|
|
137
138
|
origin: _this.sessionId
|
|
138
139
|
}));
|
|
139
140
|
} else {
|
|
@@ -179,7 +180,7 @@ function () {
|
|
|
179
180
|
Object.defineProperty(Interpreter.prototype, "state", {
|
|
180
181
|
get: function () {
|
|
181
182
|
if (!environment.IS_PRODUCTION) {
|
|
182
|
-
utils.warn(this.status !== exports.InterpreterStatus.NotStarted, "Attempted to read state from uninitialized service '"
|
|
183
|
+
utils.warn(this.status !== exports.InterpreterStatus.NotStarted, "Attempted to read state from uninitialized service '".concat(this.id, "'. Make sure the service is started first."));
|
|
183
184
|
}
|
|
184
185
|
|
|
185
186
|
return this._state;
|
|
@@ -619,11 +620,11 @@ function () {
|
|
|
619
620
|
if (this.status === exports.InterpreterStatus.NotStarted && this.options.deferEvents) {
|
|
620
621
|
// tslint:disable-next-line:no-console
|
|
621
622
|
if (!environment.IS_PRODUCTION) {
|
|
622
|
-
utils.warn(false, events.length
|
|
623
|
+
utils.warn(false, "".concat(events.length, " event(s) were sent to uninitialized service \"").concat(this.machine.id, "\" and are deferred. Make sure .start() is called for this service.\nEvent: ").concat(JSON.stringify(event)));
|
|
623
624
|
}
|
|
624
625
|
} else if (this.status !== exports.InterpreterStatus.Running) {
|
|
625
626
|
throw new Error( // tslint:disable-next-line:max-line-length
|
|
626
|
-
events.length
|
|
627
|
+
"".concat(events.length, " event(s) were sent to uninitialized service \"").concat(this.machine.id, "\". Make sure .start() is called for this service, or set { deferEvents: true } in the service options."));
|
|
627
628
|
}
|
|
628
629
|
|
|
629
630
|
this.scheduler.schedule(function () {
|
|
@@ -643,7 +644,7 @@ function () {
|
|
|
643
644
|
});
|
|
644
645
|
batchedActions.push.apply(batchedActions, _tslib.__spreadArray([], _tslib.__read(nextState.actions.map(function (a) {
|
|
645
646
|
return State.bindActionToState(a, nextState);
|
|
646
|
-
}))));
|
|
647
|
+
})), false));
|
|
647
648
|
batchChanged = batchChanged || !!nextState.changed;
|
|
648
649
|
};
|
|
649
650
|
|
|
@@ -716,7 +717,7 @@ function () {
|
|
|
716
717
|
var child = this.children.get(id);
|
|
717
718
|
|
|
718
719
|
if (!child) {
|
|
719
|
-
throw new Error("Unable to forward event '"
|
|
720
|
+
throw new Error("Unable to forward event '".concat(event, "' from interpreter '").concat(this.id, "' to nonexistant child '").concat(id, "'."));
|
|
720
721
|
}
|
|
721
722
|
|
|
722
723
|
child.send(event);
|
|
@@ -820,7 +821,7 @@ function () {
|
|
|
820
821
|
|
|
821
822
|
if (!environment.IS_PRODUCTION) {
|
|
822
823
|
utils.warn(!('forward' in activity), // tslint:disable-next-line:max-line-length
|
|
823
|
-
"`forward` property is deprecated (found in invocation of '"
|
|
824
|
+
"`forward` property is deprecated (found in invocation of '".concat(activity.src, "' in in machine '").concat(this.machine.id, "'). ") + "Please use `autoForward` instead.");
|
|
824
825
|
}
|
|
825
826
|
|
|
826
827
|
var autoForward = 'autoForward' in activity ? activity.autoForward : !!activity.forward;
|
|
@@ -828,7 +829,7 @@ function () {
|
|
|
828
829
|
if (!serviceCreator) {
|
|
829
830
|
// tslint:disable-next-line:no-console
|
|
830
831
|
if (!environment.IS_PRODUCTION) {
|
|
831
|
-
utils.warn(false, "No service found for invocation '"
|
|
832
|
+
utils.warn(false, "No service found for invocation '".concat(activity.src, "' in machine '").concat(this.machine.id, "'."));
|
|
832
833
|
}
|
|
833
834
|
|
|
834
835
|
return;
|
|
@@ -889,7 +890,7 @@ function () {
|
|
|
889
890
|
|
|
890
891
|
default:
|
|
891
892
|
if (!environment.IS_PRODUCTION) {
|
|
892
|
-
utils.warn(false, "No implementation found for action type '"
|
|
893
|
+
utils.warn(false, "No implementation found for action type '".concat(action.type, "'"));
|
|
893
894
|
}
|
|
894
895
|
|
|
895
896
|
break;
|
|
@@ -938,7 +939,7 @@ function () {
|
|
|
938
939
|
} else if (utils.isBehavior(entity)) {
|
|
939
940
|
return this.spawnBehavior(entity, name);
|
|
940
941
|
} else {
|
|
941
|
-
throw new Error("Unable to spawn entity \""
|
|
942
|
+
throw new Error("Unable to spawn entity \"".concat(name, "\" of type \"").concat(typeof entity, "\"."));
|
|
942
943
|
}
|
|
943
944
|
};
|
|
944
945
|
|
|
@@ -1214,7 +1215,7 @@ function () {
|
|
|
1214
1215
|
|
|
1215
1216
|
if (!implementation) {
|
|
1216
1217
|
if (!environment.IS_PRODUCTION) {
|
|
1217
|
-
utils.warn(false, "No implementation found for activity '"
|
|
1218
|
+
utils.warn(false, "No implementation found for activity '".concat(activity.type, "'"));
|
|
1218
1219
|
} // tslint:disable-next-line:no-console
|
|
1219
1220
|
|
|
1220
1221
|
|
|
@@ -1346,7 +1347,7 @@ function spawn(entity, nameOrOptions) {
|
|
|
1346
1347
|
return serviceScope.consume(function (service) {
|
|
1347
1348
|
if (!environment.IS_PRODUCTION) {
|
|
1348
1349
|
var isLazyEntity = utils.isMachine(entity) || utils.isFunction(entity);
|
|
1349
|
-
utils.warn(!!service || isLazyEntity, "Attempted to spawn an Actor (ID: \""
|
|
1350
|
+
utils.warn(!!service || isLazyEntity, "Attempted to spawn an Actor (ID: \"".concat(utils.isMachine(entity) ? entity.id : 'undefined', "\") outside of a service. This will have no effect."));
|
|
1350
1351
|
}
|
|
1351
1352
|
|
|
1352
1353
|
if (service) {
|
package/lib/json.js
CHANGED
|
@@ -10,7 +10,7 @@ function stringifyFunction(fn) {
|
|
|
10
10
|
}
|
|
11
11
|
exports.stringifyFunction = stringifyFunction;
|
|
12
12
|
function getStateNodeId(stateNode) {
|
|
13
|
-
return "#"
|
|
13
|
+
return "#".concat(stateNode.id);
|
|
14
14
|
}
|
|
15
15
|
// derive config from machine
|
|
16
16
|
function machineToJSON(stateNode) {
|
|
@@ -21,7 +21,7 @@ function machineToJSON(stateNode) {
|
|
|
21
21
|
key: stateNode.key,
|
|
22
22
|
entry: stateNode.onEntry,
|
|
23
23
|
exit: stateNode.onExit,
|
|
24
|
-
on: utils_1.mapValues(stateNode.on, function (transition) {
|
|
24
|
+
on: (0, utils_1.mapValues)(stateNode.on, function (transition) {
|
|
25
25
|
return transition.map(function (t) {
|
|
26
26
|
return {
|
|
27
27
|
target: t.target ? t.target.map(getStateNodeId) : [],
|
|
@@ -43,7 +43,7 @@ function machineToJSON(stateNode) {
|
|
|
43
43
|
exports.machineToJSON = machineToJSON;
|
|
44
44
|
function stringify(machine) {
|
|
45
45
|
return JSON.stringify(machineToJSON(machine), function (_, value) {
|
|
46
|
-
if (utils_1.isFunction(value)) {
|
|
46
|
+
if ((0, utils_1.isFunction)(value)) {
|
|
47
47
|
return { $function: value.toString() };
|
|
48
48
|
}
|
|
49
49
|
return value;
|
|
@@ -63,14 +63,14 @@ exports.parse = parse;
|
|
|
63
63
|
function jsonify(value) {
|
|
64
64
|
Object.defineProperty(value, 'toJSON', {
|
|
65
65
|
value: function () {
|
|
66
|
-
return utils_1.mapValues(value, function (subValue) {
|
|
67
|
-
if (utils_1.isFunction(subValue)) {
|
|
66
|
+
return (0, utils_1.mapValues)(value, function (subValue) {
|
|
67
|
+
if ((0, utils_1.isFunction)(subValue)) {
|
|
68
68
|
return stringifyFunction(subValue);
|
|
69
69
|
}
|
|
70
70
|
else if (typeof subValue === 'object' && !Array.isArray(subValue)) {
|
|
71
71
|
// mostly for assignments
|
|
72
|
-
return utils_1.mapValues(subValue, function (subSubValue) {
|
|
73
|
-
if (utils_1.isFunction(subSubValue)) {
|
|
72
|
+
return (0, utils_1.mapValues)(subValue, function (subSubValue) {
|
|
73
|
+
if ((0, utils_1.isFunction)(subSubValue)) {
|
|
74
74
|
return stringifyFunction(subSubValue);
|
|
75
75
|
}
|
|
76
76
|
return subSubValue;
|
package/lib/model.js
CHANGED
|
@@ -26,10 +26,14 @@ var __read = (this && this.__read) || function (o, n) {
|
|
|
26
26
|
}
|
|
27
27
|
return ar;
|
|
28
28
|
};
|
|
29
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from) {
|
|
30
|
-
for (var i = 0,
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
30
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
31
|
+
if (ar || !(i in from)) {
|
|
32
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
33
|
+
ar[i] = from[i];
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
33
37
|
};
|
|
34
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
39
|
exports.createModel = void 0;
|
|
@@ -43,26 +47,26 @@ function createModel(initialContext, creators) {
|
|
|
43
47
|
initialContext: initialContext,
|
|
44
48
|
assign: actions_1.assign,
|
|
45
49
|
events: (eventCreators
|
|
46
|
-
? utils_1.mapValues(eventCreators, function (fn, eventType) { return function () {
|
|
50
|
+
? (0, utils_1.mapValues)(eventCreators, function (fn, eventType) { return function () {
|
|
47
51
|
var args = [];
|
|
48
52
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
49
53
|
args[_i] = arguments[_i];
|
|
50
54
|
}
|
|
51
|
-
return (__assign(__assign({}, fn.apply(void 0, __spreadArray([], __read(args)))), { type: eventType }));
|
|
55
|
+
return (__assign(__assign({}, fn.apply(void 0, __spreadArray([], __read(args), false))), { type: eventType }));
|
|
52
56
|
}; })
|
|
53
57
|
: undefined),
|
|
54
58
|
actions: actionCreators
|
|
55
|
-
? utils_1.mapValues(actionCreators, function (fn, actionType) { return function () {
|
|
59
|
+
? (0, utils_1.mapValues)(actionCreators, function (fn, actionType) { return function () {
|
|
56
60
|
var args = [];
|
|
57
61
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
58
62
|
args[_i] = arguments[_i];
|
|
59
63
|
}
|
|
60
|
-
return (__assign(__assign({}, fn.apply(void 0, __spreadArray([], __read(args)))), { type: actionType }));
|
|
64
|
+
return (__assign(__assign({}, fn.apply(void 0, __spreadArray([], __read(args), false))), { type: actionType }));
|
|
61
65
|
}; })
|
|
62
66
|
: undefined,
|
|
63
|
-
reset: function () { return actions_1.assign(initialContext); },
|
|
67
|
+
reset: function () { return (0, actions_1.assign)(initialContext); },
|
|
64
68
|
createMachine: function (config, implementations) {
|
|
65
|
-
return Machine_1.createMachine('context' in config ? config : __assign(__assign({}, config), { context: initialContext }), implementations);
|
|
69
|
+
return (0, Machine_1.createMachine)('context' in config ? config : __assign(__assign({}, config), { context: initialContext }), implementations);
|
|
66
70
|
}
|
|
67
71
|
};
|
|
68
72
|
return model;
|
package/lib/patterns.js
CHANGED
|
@@ -34,10 +34,10 @@ function sequence(items, options) {
|
|
|
34
34
|
var states = {};
|
|
35
35
|
var nextEventObject = resolvedOptions.nextEvent === undefined
|
|
36
36
|
? undefined
|
|
37
|
-
: utils_1.toEventObject(resolvedOptions.nextEvent);
|
|
37
|
+
: (0, utils_1.toEventObject)(resolvedOptions.nextEvent);
|
|
38
38
|
var prevEventObject = resolvedOptions.prevEvent === undefined
|
|
39
39
|
? undefined
|
|
40
|
-
: utils_1.toEventObject(resolvedOptions.prevEvent);
|
|
40
|
+
: (0, utils_1.toEventObject)(resolvedOptions.prevEvent);
|
|
41
41
|
items.forEach(function (item, i) {
|
|
42
42
|
var state = {
|
|
43
43
|
on: {}
|
package/lib/registry.js
CHANGED
package/lib/scxml.js
CHANGED
|
@@ -26,10 +26,14 @@ var __read = (this && this.__read) || function (o, n) {
|
|
|
26
26
|
}
|
|
27
27
|
return ar;
|
|
28
28
|
};
|
|
29
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from) {
|
|
30
|
-
for (var i = 0,
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
30
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
31
|
+
if (ar || !(i in from)) {
|
|
32
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
33
|
+
ar[i] = from[i];
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
33
37
|
};
|
|
34
38
|
var __values = (this && this.__values) || function(o) {
|
|
35
39
|
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
@@ -53,7 +57,7 @@ function getAttribute(element, attribute) {
|
|
|
53
57
|
}
|
|
54
58
|
function indexedRecord(items, identifier) {
|
|
55
59
|
var record = {};
|
|
56
|
-
var identifierFn = utils_1.isString(identifier)
|
|
60
|
+
var identifierFn = (0, utils_1.isString)(identifier)
|
|
57
61
|
? function (item) { return item[identifier]; }
|
|
58
62
|
: identifier;
|
|
59
63
|
items.forEach(function (item) {
|
|
@@ -71,7 +75,7 @@ function executableContent(elements) {
|
|
|
71
75
|
function getTargets(targetAttr) {
|
|
72
76
|
// return targetAttr ? [`#${targetAttr}`] : undefined;
|
|
73
77
|
return targetAttr
|
|
74
|
-
?
|
|
78
|
+
? "".concat(targetAttr).split(/\s+/).map(function (target) { return "#".concat(target); })
|
|
75
79
|
: undefined;
|
|
76
80
|
}
|
|
77
81
|
function delayToMs(delay) {
|
|
@@ -96,29 +100,29 @@ function delayToMs(delay) {
|
|
|
96
100
|
: 0;
|
|
97
101
|
var millisecondsPart = parseInt(secondsMatch[3].padEnd(3, '0'), 10);
|
|
98
102
|
if (millisecondsPart >= 1000) {
|
|
99
|
-
throw new Error("Can't parse \""
|
|
103
|
+
throw new Error("Can't parse \"".concat(delay, " delay.\""));
|
|
100
104
|
}
|
|
101
105
|
return secondsPart + millisecondsPart;
|
|
102
106
|
}
|
|
103
|
-
throw new Error("Can't parse \""
|
|
107
|
+
throw new Error("Can't parse \"".concat(delay, " delay.\""));
|
|
104
108
|
}
|
|
105
109
|
var evaluateExecutableContent = function (context, _ev, meta, body) {
|
|
106
110
|
var datamodel = context
|
|
107
|
-
? utils_1.keys(context)
|
|
108
|
-
.map(function (key) { return "const "
|
|
111
|
+
? (0, utils_1.keys)(context)
|
|
112
|
+
.map(function (key) { return "const ".concat(key, " = context['").concat(key, "'];"); })
|
|
109
113
|
.join('\n')
|
|
110
114
|
: '';
|
|
111
115
|
var scope = ['const _sessionid = "NOT_IMPLEMENTED";', datamodel]
|
|
112
116
|
.filter(Boolean)
|
|
113
117
|
.join('\n');
|
|
114
118
|
var args = ['context', '_event'];
|
|
115
|
-
var fnBody = "\n "
|
|
116
|
-
var fn = new (Function.bind.apply(Function, __spreadArray(__spreadArray([void 0], __read(args)), [fnBody])))();
|
|
119
|
+
var fnBody = "\n ".concat(scope, "\n ").concat(body, "\n ");
|
|
120
|
+
var fn = new (Function.bind.apply(Function, __spreadArray(__spreadArray([void 0], __read(args), false), [fnBody], false)))();
|
|
117
121
|
return fn(context, meta._event);
|
|
118
122
|
};
|
|
119
123
|
function createCond(cond) {
|
|
120
124
|
return function (context, _event, meta) {
|
|
121
|
-
return evaluateExecutableContent(context, _event, meta, "return "
|
|
125
|
+
return evaluateExecutableContent(context, _event, meta, "return ".concat(cond, ";"));
|
|
122
126
|
};
|
|
123
127
|
}
|
|
124
128
|
function mapAction(element) {
|
|
@@ -129,7 +133,7 @@ function mapAction(element) {
|
|
|
129
133
|
}
|
|
130
134
|
case 'assign': {
|
|
131
135
|
return actions.assign(function (context, e, meta) {
|
|
132
|
-
var fnBody = "\n return {'"
|
|
136
|
+
var fnBody = "\n return {'".concat(element.attributes.location, "': ").concat(element.attributes.expr, "};\n ");
|
|
133
137
|
return evaluateExecutableContent(context, e, meta, fnBody);
|
|
134
138
|
});
|
|
135
139
|
}
|
|
@@ -142,14 +146,14 @@ function mapAction(element) {
|
|
|
142
146
|
if (child.name === 'content') {
|
|
143
147
|
throw new Error('Conversion of <content/> inside <send/> not implemented.');
|
|
144
148
|
}
|
|
145
|
-
return ""
|
|
149
|
+
return "".concat(acc).concat(child.attributes.name, ":").concat(child.attributes.expr, ",\n");
|
|
146
150
|
}, '');
|
|
147
151
|
if (event_1 && !params_1) {
|
|
148
152
|
convertedEvent = event_1;
|
|
149
153
|
}
|
|
150
154
|
else {
|
|
151
155
|
convertedEvent = function (context, _ev, meta) {
|
|
152
|
-
var fnBody = "\n return { type: "
|
|
156
|
+
var fnBody = "\n return { type: ".concat(event_1 ? "\"".concat(event_1, "\"") : eventexpr_1, ", ").concat(params_1 ? params_1 : '', " }\n ");
|
|
153
157
|
return evaluateExecutableContent(context, _ev, meta, fnBody);
|
|
154
158
|
};
|
|
155
159
|
}
|
|
@@ -158,7 +162,7 @@ function mapAction(element) {
|
|
|
158
162
|
}
|
|
159
163
|
else if (element.attributes.delayexpr) {
|
|
160
164
|
convertedDelay = function (context, _ev, meta) {
|
|
161
|
-
var fnBody = "\n return ("
|
|
165
|
+
var fnBody = "\n return (".concat(delayToMs, ")(").concat(element.attributes.delayexpr, ");\n ");
|
|
162
166
|
return evaluateExecutableContent(context, _ev, meta, fnBody);
|
|
163
167
|
};
|
|
164
168
|
}
|
|
@@ -170,7 +174,7 @@ function mapAction(element) {
|
|
|
170
174
|
case 'log': {
|
|
171
175
|
var label = element.attributes.label;
|
|
172
176
|
return actions.log(function (context, e, meta) {
|
|
173
|
-
var fnBody = "\n return "
|
|
177
|
+
var fnBody = "\n return ".concat(element.attributes.expr, ";\n ");
|
|
174
178
|
return evaluateExecutableContent(context, e, meta, fnBody);
|
|
175
179
|
}, label !== undefined ? String(label) : undefined);
|
|
176
180
|
}
|
|
@@ -215,7 +219,7 @@ function mapAction(element) {
|
|
|
215
219
|
return actions.choose(conds);
|
|
216
220
|
}
|
|
217
221
|
default:
|
|
218
|
-
throw new Error("Conversion of \""
|
|
222
|
+
throw new Error("Conversion of \"".concat(element.name, "\" elements is not implemented yet."));
|
|
219
223
|
}
|
|
220
224
|
}
|
|
221
225
|
function mapActions(elements) {
|
|
@@ -257,7 +261,7 @@ function toConfig(nodeJson, id, options) {
|
|
|
257
261
|
return {
|
|
258
262
|
id: id,
|
|
259
263
|
history: history_1,
|
|
260
|
-
target: target ? "#"
|
|
264
|
+
target: target ? "#".concat(target) : undefined
|
|
261
265
|
};
|
|
262
266
|
}
|
|
263
267
|
case 'final': {
|
|
@@ -277,7 +281,7 @@ function toConfig(nodeJson, id, options) {
|
|
|
277
281
|
var invokeElements = nodeJson.elements.filter(function (element) { return element.name === 'invoke'; });
|
|
278
282
|
var onEntryElement = nodeJson.elements.find(function (element) { return element.name === 'onentry'; });
|
|
279
283
|
var onExitElement = nodeJson.elements.find(function (element) { return element.name === 'onexit'; });
|
|
280
|
-
var states = indexedRecord(stateElements, function (item) { return ""
|
|
284
|
+
var states = indexedRecord(stateElements, function (item) { return "".concat(item.attributes.id); });
|
|
281
285
|
var initialElement = !initial
|
|
282
286
|
? nodeJson.elements.find(function (element) { return element.name === 'initial'; })
|
|
283
287
|
: undefined;
|
|
@@ -312,7 +316,7 @@ function toConfig(nodeJson, id, options) {
|
|
|
312
316
|
});
|
|
313
317
|
return __assign(__assign(__assign(__assign(__assign(__assign(__assign({ id: id }, (initial ? { initial: initial } : undefined)), (parallel ? { type: 'parallel' } : undefined)), (stateElements.length
|
|
314
318
|
? {
|
|
315
|
-
states: utils_1.mapValues(states, function (state, key) {
|
|
319
|
+
states: (0, utils_1.mapValues)(states, function (state, key) {
|
|
316
320
|
return toConfig(state, key, options);
|
|
317
321
|
})
|
|
318
322
|
}
|
|
@@ -332,15 +336,15 @@ function scxmlToMachine(scxmlJson, options) {
|
|
|
332
336
|
}
|
|
333
337
|
acc[element.attributes.id] = element.attributes.expr
|
|
334
338
|
? // tslint:disable-next-line:no-eval
|
|
335
|
-
eval("("
|
|
339
|
+
eval("(".concat(element.attributes.expr, ")"))
|
|
336
340
|
: undefined;
|
|
337
341
|
return acc;
|
|
338
342
|
}, {})
|
|
339
343
|
: undefined;
|
|
340
|
-
return index_1.Machine(__assign(__assign({}, toConfig(machineElement, '(machine)', options)), { context: extState, delimiter: options.delimiter }));
|
|
344
|
+
return (0, index_1.Machine)(__assign(__assign({}, toConfig(machineElement, '(machine)', options)), { context: extState, delimiter: options.delimiter }));
|
|
341
345
|
}
|
|
342
346
|
function toMachine(xml, options) {
|
|
343
|
-
var json = xml_js_1.xml2js(xml);
|
|
347
|
+
var json = (0, xml_js_1.xml2js)(xml);
|
|
344
348
|
return scxmlToMachine(json, options);
|
|
345
349
|
}
|
|
346
350
|
exports.toMachine = toMachine;
|
package/lib/stateUtils.js
CHANGED
|
@@ -226,7 +226,7 @@ function has(iterable, item) {
|
|
|
226
226
|
function nextEvents(configuration) {
|
|
227
227
|
return _tslib.__spreadArray([], _tslib.__read(new Set(utils.flatten(_tslib.__spreadArray([], _tslib.__read(configuration.map(function (sn) {
|
|
228
228
|
return sn.ownEvents;
|
|
229
|
-
})))))));
|
|
229
|
+
})), false)))), false);
|
|
230
230
|
}
|
|
231
231
|
function isInFinalState(configuration, stateNode) {
|
|
232
232
|
if (stateNode.type === 'compound') {
|
package/lib/types.d.ts
CHANGED
|
@@ -81,14 +81,6 @@ export interface StateValueMap {
|
|
|
81
81
|
* - For complex state nodes, this is an object, e.g., `{ success: "someChildState" }`.
|
|
82
82
|
*/
|
|
83
83
|
export declare type StateValue = string | StateValueMap;
|
|
84
|
-
declare type KeysWithStates<TStates extends Record<string, StateSchema> | undefined> = TStates extends object ? {
|
|
85
|
-
[K in keyof TStates]-?: TStates[K] extends {
|
|
86
|
-
states: object;
|
|
87
|
-
} ? K : never;
|
|
88
|
-
}[keyof TStates] : never;
|
|
89
|
-
export declare type ExtractStateValue<TSchema extends Required<Pick<StateSchema<any>, 'states'>>> = keyof TSchema['states'] | (KeysWithStates<TSchema['states']> extends never ? never : {
|
|
90
|
-
[K in KeysWithStates<TSchema['states']>]?: ExtractStateValue<TSchema['states'][K]>;
|
|
91
|
-
});
|
|
92
84
|
export interface HistoryValue {
|
|
93
85
|
states: Record<string, HistoryValue | undefined>;
|
|
94
86
|
current: StateValue | undefined;
|
package/lib/utils.js
CHANGED
|
@@ -40,7 +40,7 @@ function matchesState(parentStateId, childStateId, delimiter) {
|
|
|
40
40
|
}
|
|
41
41
|
function getEventType(event) {
|
|
42
42
|
try {
|
|
43
|
-
return isString(event) || typeof event === 'number' ? ""
|
|
43
|
+
return isString(event) || typeof event === 'number' ? "".concat(event) : event.type;
|
|
44
44
|
} catch (e) {
|
|
45
45
|
throw new Error('Events must be strings or objects with a string event.type property.');
|
|
46
46
|
}
|
|
@@ -53,7 +53,7 @@ function toStatePath(stateId, delimiter) {
|
|
|
53
53
|
|
|
54
54
|
return stateId.toString().split(delimiter);
|
|
55
55
|
} catch (e) {
|
|
56
|
-
throw new Error("'"
|
|
56
|
+
throw new Error("'".concat(stateId, "' is not a valid state path."));
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
function isStateLike(state) {
|
|
@@ -222,7 +222,7 @@ function toStatePaths(stateValue) {
|
|
|
222
222
|
function flatten(array) {
|
|
223
223
|
var _a;
|
|
224
224
|
|
|
225
|
-
return (_a = []).concat.apply(_a, _tslib.__spreadArray([], _tslib.__read(array)));
|
|
225
|
+
return (_a = []).concat.apply(_a, _tslib.__spreadArray([], _tslib.__read(array), false));
|
|
226
226
|
}
|
|
227
227
|
function toArrayStrict(value) {
|
|
228
228
|
if (isArray(value)) {
|
|
@@ -399,7 +399,7 @@ if (!environment.IS_PRODUCTION) {
|
|
|
399
399
|
}
|
|
400
400
|
|
|
401
401
|
if (console !== undefined) {
|
|
402
|
-
var args = ["Warning: "
|
|
402
|
+
var args = ["Warning: ".concat(message)];
|
|
403
403
|
|
|
404
404
|
if (error) {
|
|
405
405
|
args.push(error);
|
|
@@ -528,15 +528,15 @@ function normalizeTarget(target) {
|
|
|
528
528
|
}
|
|
529
529
|
function reportUnhandledExceptionOnInvocation(originalError, currentError, id) {
|
|
530
530
|
if (!environment.IS_PRODUCTION) {
|
|
531
|
-
var originalStackTrace = originalError.stack ? " Stacktrace was '"
|
|
531
|
+
var originalStackTrace = originalError.stack ? " Stacktrace was '".concat(originalError.stack, "'") : '';
|
|
532
532
|
|
|
533
533
|
if (originalError === currentError) {
|
|
534
534
|
// tslint:disable-next-line:no-console
|
|
535
|
-
console.error("Missing onError handler for invocation '"
|
|
535
|
+
console.error("Missing onError handler for invocation '".concat(id, "', error was '").concat(originalError, "'.").concat(originalStackTrace));
|
|
536
536
|
} else {
|
|
537
|
-
var stackTrace = currentError.stack ? " Stacktrace was '"
|
|
537
|
+
var stackTrace = currentError.stack ? " Stacktrace was '".concat(currentError.stack, "'") : ''; // tslint:disable-next-line:no-console
|
|
538
538
|
|
|
539
|
-
console.error("Missing onError handler and/or unhandled exception/promise rejection for invocation '"
|
|
539
|
+
console.error("Missing onError handler and/or unhandled exception/promise rejection for invocation '".concat(id, "'. ") + "Original error: '".concat(originalError, "'. ").concat(originalStackTrace, " Current error is '").concat(currentError, "'.").concat(stackTrace));
|
|
540
540
|
}
|
|
541
541
|
}
|
|
542
542
|
}
|
|
@@ -555,7 +555,7 @@ function evaluateGuard(machine, guard, context, _event, state) {
|
|
|
555
555
|
var condFn = guards[guard.type];
|
|
556
556
|
|
|
557
557
|
if (!condFn) {
|
|
558
|
-
throw new Error("Guard '"
|
|
558
|
+
throw new Error("Guard '".concat(guard.type, "' is not implemented on machine '").concat(machine.id, "'."));
|
|
559
559
|
}
|
|
560
560
|
|
|
561
561
|
return condFn(context, _event.data, guardMeta);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "xstate",
|
|
3
|
-
"version": "4.26.
|
|
3
|
+
"version": "4.26.1",
|
|
4
4
|
"description": "Finite State Machines and Statecharts for the Modern Web.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "es/index.js",
|
|
@@ -61,8 +61,8 @@
|
|
|
61
61
|
"rollup-plugin-uglify": "^6.0.2",
|
|
62
62
|
"rxjs": "^7.1.0",
|
|
63
63
|
"ts-jest": "^26.5.6",
|
|
64
|
-
"tslib": "^2.
|
|
65
|
-
"typescript": "^4.
|
|
64
|
+
"tslib": "^2.3.1",
|
|
65
|
+
"typescript": "^4.5.2",
|
|
66
66
|
"xml-js": "^1.6.11"
|
|
67
67
|
}
|
|
68
68
|
}
|