xstate 4.20.0 → 4.23.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 +205 -0
- 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 +6 -5
- package/es/Actor.js +22 -7
- package/es/Machine.d.ts +10 -5
- package/es/Machine.js +3 -6
- package/es/State.js +3 -5
- package/es/StateNode.d.ts +4 -3
- package/es/StateNode.js +34 -28
- package/es/_virtual/_tslib.js +59 -73
- package/es/actionTypes.js +3 -2
- package/es/actions.d.ts +1 -1
- package/es/actions.js +51 -37
- package/es/behaviors.d.ts +37 -0
- package/es/behaviors.js +65 -0
- package/es/constants.js +2 -1
- package/es/devTools.js +1 -1
- package/es/environment.js +2 -1
- package/es/index.js +3 -1
- package/es/interpreter.d.ts +15 -8
- package/es/interpreter.js +48 -22
- package/es/invokeUtils.js +4 -3
- package/es/mapState.js +1 -1
- package/es/match.js +1 -1
- package/es/model.d.ts +2 -36
- package/es/model.types.d.ts +37 -0
- package/es/registry.js +2 -1
- package/es/scheduler.js +2 -1
- package/es/schema.js +1 -1
- package/es/serviceScope.js +1 -3
- package/es/stateUtils.d.ts +1 -0
- package/es/stateUtils.js +14 -8
- package/es/types.d.ts +35 -9
- package/es/types.js +1 -1
- package/es/utils.d.ts +3 -2
- package/es/utils.js +4 -40
- package/lib/Actor.d.ts +25 -24
- package/lib/Actor.js +87 -53
- package/lib/Machine.d.ts +17 -12
- package/lib/Machine.js +14 -14
- package/lib/SimulatedClock.d.ts +16 -16
- package/lib/State.d.ts +108 -108
- package/lib/State.js +246 -236
- package/lib/StateNode.d.ts +279 -278
- package/lib/StateNode.js +1535 -1350
- package/lib/_virtual/_tslib.js +81 -0
- package/lib/actionTypes.d.ts +19 -19
- package/lib/actionTypes.js +43 -23
- package/lib/actions.d.ts +138 -138
- package/lib/actions.js +465 -387
- package/lib/behaviors.d.ts +37 -0
- package/lib/behaviors.js +69 -0
- package/lib/constants.d.ts +5 -5
- package/lib/constants.js +13 -7
- package/lib/devTools.d.ts +15 -15
- package/lib/devTools.js +37 -26
- package/lib/each.d.ts +3 -3
- package/lib/environment.d.ts +1 -1
- package/lib/environment.js +7 -4
- package/lib/index.d.ts +30 -30
- package/lib/index.js +67 -57
- package/lib/interpreter.d.ts +205 -198
- package/lib/interpreter.js +1307 -1052
- package/lib/invoke.d.ts +10 -10
- package/lib/invokeUtils.d.ts +6 -6
- package/lib/invokeUtils.js +40 -37
- package/lib/json.d.ts +30 -30
- package/lib/mapState.d.ts +3 -3
- package/lib/mapState.js +31 -32
- package/lib/match.d.ts +8 -8
- package/lib/match.js +33 -47
- package/lib/model.d.ts +4 -38
- package/lib/model.js +5 -1
- package/lib/model.types.d.ts +37 -0
- package/lib/model.types.js +2 -0
- package/lib/patterns.d.ts +13 -13
- package/lib/registry.d.ts +8 -8
- package/lib/registry.js +21 -18
- package/lib/scheduler.d.ts +16 -16
- package/lib/scheduler.js +79 -70
- package/lib/schema.d.ts +1 -1
- package/lib/schema.js +6 -4
- package/lib/scxml.d.ts +5 -5
- package/lib/serviceScope.d.ts +3 -3
- package/lib/serviceScope.js +16 -12
- package/lib/stateUtils.d.ts +14 -13
- package/lib/stateUtils.js +232 -190
- package/lib/types.d.ts +928 -902
- package/lib/types.js +29 -29
- package/lib/utils.d.ts +68 -67
- package/lib/utils.js +530 -529
- package/package.json +5 -5
package/lib/stateUtils.js
CHANGED
|
@@ -1,227 +1,269 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
return { value: o && o[i++], done: !o };
|
|
9
|
-
}
|
|
10
|
-
};
|
|
11
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
12
|
-
};
|
|
13
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
14
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
15
|
-
if (!m) return o;
|
|
16
|
-
var i = m.call(o), r, ar = [], e;
|
|
17
|
-
try {
|
|
18
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
19
|
-
}
|
|
20
|
-
catch (error) { e = { error: error }; }
|
|
21
|
-
finally {
|
|
22
|
-
try {
|
|
23
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
24
|
-
}
|
|
25
|
-
finally { if (e) throw e.error; }
|
|
26
|
-
}
|
|
27
|
-
return ar;
|
|
28
|
-
};
|
|
29
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from) {
|
|
30
|
-
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
|
|
31
|
-
to[j] = from[i];
|
|
32
|
-
return to;
|
|
33
|
-
};
|
|
34
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
-
exports.isInFinalState = exports.nextEvents = exports.has = exports.getValue = exports.getAdjList = exports.getConfiguration = exports.getAllStateNodes = exports.getChildren = exports.isLeafNode = void 0;
|
|
36
|
-
var utils_1 = require("./utils");
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var _tslib = require('./_virtual/_tslib.js');
|
|
6
|
+
var utils = require('./utils.js');
|
|
7
|
+
|
|
37
8
|
var isLeafNode = function (stateNode) {
|
|
38
|
-
|
|
9
|
+
return stateNode.type === 'atomic' || stateNode.type === 'final';
|
|
39
10
|
};
|
|
40
|
-
exports.isLeafNode = isLeafNode;
|
|
41
11
|
function getChildren(stateNode) {
|
|
42
|
-
|
|
12
|
+
return utils.keys(stateNode.states).map(function (key) {
|
|
13
|
+
return stateNode.states[key];
|
|
14
|
+
});
|
|
43
15
|
}
|
|
44
|
-
exports.getChildren = getChildren;
|
|
45
16
|
function getAllStateNodes(stateNode) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
17
|
+
var stateNodes = [stateNode];
|
|
18
|
+
|
|
19
|
+
if (isLeafNode(stateNode)) {
|
|
20
|
+
return stateNodes;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return stateNodes.concat(utils.flatten(getChildren(stateNode).map(getAllStateNodes)));
|
|
51
24
|
}
|
|
52
|
-
exports.getAllStateNodes = getAllStateNodes;
|
|
53
25
|
function getConfiguration(prevStateNodes, stateNodes) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
26
|
+
var e_1, _a, e_2, _b, e_3, _c, e_4, _d;
|
|
27
|
+
|
|
28
|
+
var prevConfiguration = new Set(prevStateNodes);
|
|
29
|
+
var prevAdjList = getAdjList(prevConfiguration);
|
|
30
|
+
var configuration = new Set(stateNodes);
|
|
31
|
+
|
|
32
|
+
try {
|
|
33
|
+
// add all ancestors
|
|
34
|
+
for (var configuration_1 = _tslib.__values(configuration), configuration_1_1 = configuration_1.next(); !configuration_1_1.done; configuration_1_1 = configuration_1.next()) {
|
|
35
|
+
var s = configuration_1_1.value;
|
|
36
|
+
var m = s.parent;
|
|
37
|
+
|
|
38
|
+
while (m && !configuration.has(m)) {
|
|
39
|
+
configuration.add(m);
|
|
40
|
+
m = m.parent;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
} catch (e_1_1) {
|
|
44
|
+
e_1 = {
|
|
45
|
+
error: e_1_1
|
|
46
|
+
};
|
|
47
|
+
} finally {
|
|
58
48
|
try {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
var m = s.parent;
|
|
63
|
-
while (m && !configuration.has(m)) {
|
|
64
|
-
configuration.add(m);
|
|
65
|
-
m = m.parent;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
49
|
+
if (configuration_1_1 && !configuration_1_1.done && (_a = configuration_1.return)) _a.call(configuration_1);
|
|
50
|
+
} finally {
|
|
51
|
+
if (e_1) throw e_1.error;
|
|
68
52
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
var adjList = getAdjList(configuration);
|
|
56
|
+
|
|
57
|
+
try {
|
|
58
|
+
// add descendants
|
|
59
|
+
for (var configuration_2 = _tslib.__values(configuration), configuration_2_1 = configuration_2.next(); !configuration_2_1.done; configuration_2_1 = configuration_2.next()) {
|
|
60
|
+
var s = configuration_2_1.value; // if previously active, add existing child nodes
|
|
61
|
+
|
|
62
|
+
if (s.type === 'compound' && (!adjList.get(s) || !adjList.get(s).length)) {
|
|
63
|
+
if (prevAdjList.get(s)) {
|
|
64
|
+
prevAdjList.get(s).forEach(function (sn) {
|
|
65
|
+
return configuration.add(sn);
|
|
66
|
+
});
|
|
67
|
+
} else {
|
|
68
|
+
s.initialStateNodes.forEach(function (sn) {
|
|
69
|
+
return configuration.add(sn);
|
|
70
|
+
});
|
|
73
71
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
72
|
+
} else {
|
|
73
|
+
if (s.type === 'parallel') {
|
|
74
|
+
try {
|
|
75
|
+
for (var _e = (e_3 = void 0, _tslib.__values(getChildren(s))), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
76
|
+
var child = _f.value;
|
|
77
|
+
|
|
78
|
+
if (child.type === 'history') {
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (!configuration.has(child)) {
|
|
83
|
+
configuration.add(child);
|
|
84
|
+
|
|
85
|
+
if (prevAdjList.get(child)) {
|
|
86
|
+
prevAdjList.get(child).forEach(function (sn) {
|
|
87
|
+
return configuration.add(sn);
|
|
88
|
+
});
|
|
89
|
+
} else {
|
|
90
|
+
child.initialStateNodes.forEach(function (sn) {
|
|
91
|
+
return configuration.add(sn);
|
|
92
|
+
});
|
|
88
93
|
}
|
|
94
|
+
}
|
|
89
95
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
configuration.add(child);
|
|
100
|
-
if (prevAdjList.get(child)) {
|
|
101
|
-
prevAdjList.get(child).forEach(function (sn) { return configuration.add(sn); });
|
|
102
|
-
}
|
|
103
|
-
else {
|
|
104
|
-
child.initialStateNodes.forEach(function (sn) { return configuration.add(sn); });
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
110
|
-
finally {
|
|
111
|
-
try {
|
|
112
|
-
if (_f && !_f.done && (_c = _e.return)) _c.call(_e);
|
|
113
|
-
}
|
|
114
|
-
finally { if (e_3) throw e_3.error; }
|
|
115
|
-
}
|
|
116
|
-
}
|
|
96
|
+
} catch (e_3_1) {
|
|
97
|
+
e_3 = {
|
|
98
|
+
error: e_3_1
|
|
99
|
+
};
|
|
100
|
+
} finally {
|
|
101
|
+
try {
|
|
102
|
+
if (_f && !_f.done && (_c = _e.return)) _c.call(_e);
|
|
103
|
+
} finally {
|
|
104
|
+
if (e_3) throw e_3.error;
|
|
117
105
|
}
|
|
106
|
+
}
|
|
118
107
|
}
|
|
108
|
+
}
|
|
119
109
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
finally { if (e_2) throw e_2.error; }
|
|
126
|
-
}
|
|
110
|
+
} catch (e_2_1) {
|
|
111
|
+
e_2 = {
|
|
112
|
+
error: e_2_1
|
|
113
|
+
};
|
|
114
|
+
} finally {
|
|
127
115
|
try {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
var m = s.parent;
|
|
132
|
-
while (m && !configuration.has(m)) {
|
|
133
|
-
configuration.add(m);
|
|
134
|
-
m = m.parent;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
116
|
+
if (configuration_2_1 && !configuration_2_1.done && (_b = configuration_2.return)) _b.call(configuration_2);
|
|
117
|
+
} finally {
|
|
118
|
+
if (e_2) throw e_2.error;
|
|
137
119
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
try {
|
|
123
|
+
// add all ancestors
|
|
124
|
+
for (var configuration_3 = _tslib.__values(configuration), configuration_3_1 = configuration_3.next(); !configuration_3_1.done; configuration_3_1 = configuration_3.next()) {
|
|
125
|
+
var s = configuration_3_1.value;
|
|
126
|
+
var m = s.parent;
|
|
127
|
+
|
|
128
|
+
while (m && !configuration.has(m)) {
|
|
129
|
+
configuration.add(m);
|
|
130
|
+
m = m.parent;
|
|
131
|
+
}
|
|
144
132
|
}
|
|
145
|
-
|
|
133
|
+
} catch (e_4_1) {
|
|
134
|
+
e_4 = {
|
|
135
|
+
error: e_4_1
|
|
136
|
+
};
|
|
137
|
+
} finally {
|
|
138
|
+
try {
|
|
139
|
+
if (configuration_3_1 && !configuration_3_1.done && (_d = configuration_3.return)) _d.call(configuration_3);
|
|
140
|
+
} finally {
|
|
141
|
+
if (e_4) throw e_4.error;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return configuration;
|
|
146
146
|
}
|
|
147
|
-
|
|
147
|
+
|
|
148
148
|
function getValueFromAdj(baseNode, adjList) {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
149
|
+
var childStateNodes = adjList.get(baseNode);
|
|
150
|
+
|
|
151
|
+
if (!childStateNodes) {
|
|
152
|
+
return {}; // todo: fix?
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if (baseNode.type === 'compound') {
|
|
156
|
+
var childStateNode = childStateNodes[0];
|
|
157
|
+
|
|
158
|
+
if (childStateNode) {
|
|
159
|
+
if (isLeafNode(childStateNode)) {
|
|
160
|
+
return childStateNode.key;
|
|
161
|
+
}
|
|
162
|
+
} else {
|
|
163
|
+
return {};
|
|
152
164
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
else {
|
|
161
|
-
return {};
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
var stateValue = {};
|
|
165
|
-
childStateNodes.forEach(function (csn) {
|
|
166
|
-
stateValue[csn.key] = getValueFromAdj(csn, adjList);
|
|
167
|
-
});
|
|
168
|
-
return stateValue;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
var stateValue = {};
|
|
168
|
+
childStateNodes.forEach(function (csn) {
|
|
169
|
+
stateValue[csn.key] = getValueFromAdj(csn, adjList);
|
|
170
|
+
});
|
|
171
|
+
return stateValue;
|
|
169
172
|
}
|
|
173
|
+
|
|
170
174
|
function getAdjList(configuration) {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
175
|
+
var e_5, _a;
|
|
176
|
+
|
|
177
|
+
var adjList = new Map();
|
|
178
|
+
|
|
179
|
+
try {
|
|
180
|
+
for (var configuration_4 = _tslib.__values(configuration), configuration_4_1 = configuration_4.next(); !configuration_4_1.done; configuration_4_1 = configuration_4.next()) {
|
|
181
|
+
var s = configuration_4_1.value;
|
|
182
|
+
|
|
183
|
+
if (!adjList.has(s)) {
|
|
184
|
+
adjList.set(s, []);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
if (s.parent) {
|
|
188
|
+
if (!adjList.has(s.parent)) {
|
|
189
|
+
adjList.set(s.parent, []);
|
|
185
190
|
}
|
|
191
|
+
|
|
192
|
+
adjList.get(s.parent).push(s);
|
|
193
|
+
}
|
|
186
194
|
}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
195
|
+
} catch (e_5_1) {
|
|
196
|
+
e_5 = {
|
|
197
|
+
error: e_5_1
|
|
198
|
+
};
|
|
199
|
+
} finally {
|
|
200
|
+
try {
|
|
201
|
+
if (configuration_4_1 && !configuration_4_1.done && (_a = configuration_4.return)) _a.call(configuration_4);
|
|
202
|
+
} finally {
|
|
203
|
+
if (e_5) throw e_5.error;
|
|
193
204
|
}
|
|
194
|
-
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
return adjList;
|
|
195
208
|
}
|
|
196
|
-
exports.getAdjList = getAdjList;
|
|
197
209
|
function getValue(rootNode, configuration) {
|
|
198
|
-
|
|
199
|
-
|
|
210
|
+
var config = getConfiguration([rootNode], configuration);
|
|
211
|
+
return getValueFromAdj(rootNode, getAdjList(config));
|
|
200
212
|
}
|
|
201
|
-
exports.getValue = getValue;
|
|
202
213
|
function has(iterable, item) {
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
214
|
+
if (Array.isArray(iterable)) {
|
|
215
|
+
return iterable.some(function (member) {
|
|
216
|
+
return member === item;
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
if (iterable instanceof Set) {
|
|
221
|
+
return iterable.has(item);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
return false; // TODO: fix
|
|
210
225
|
}
|
|
211
|
-
exports.has = has;
|
|
212
226
|
function nextEvents(configuration) {
|
|
213
|
-
|
|
227
|
+
return _tslib.__spreadArray([], _tslib.__read(new Set(utils.flatten(_tslib.__spreadArray([], _tslib.__read(configuration.map(function (sn) {
|
|
228
|
+
return sn.ownEvents;
|
|
229
|
+
})))))));
|
|
214
230
|
}
|
|
215
|
-
exports.nextEvents = nextEvents;
|
|
216
231
|
function isInFinalState(configuration, stateNode) {
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
232
|
+
if (stateNode.type === 'compound') {
|
|
233
|
+
return getChildren(stateNode).some(function (s) {
|
|
234
|
+
return s.type === 'final' && has(configuration, s);
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
if (stateNode.type === 'parallel') {
|
|
239
|
+
return getChildren(stateNode).every(function (sn) {
|
|
240
|
+
return isInFinalState(configuration, sn);
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
return false;
|
|
245
|
+
}
|
|
246
|
+
function getMeta(configuration) {
|
|
247
|
+
if (configuration === void 0) {
|
|
248
|
+
configuration = [];
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
return configuration.reduce(function (acc, stateNode) {
|
|
252
|
+
if (stateNode.meta !== undefined) {
|
|
253
|
+
acc[stateNode.id] = stateNode.meta;
|
|
224
254
|
}
|
|
225
|
-
|
|
255
|
+
|
|
256
|
+
return acc;
|
|
257
|
+
}, {});
|
|
226
258
|
}
|
|
259
|
+
|
|
260
|
+
exports.getAdjList = getAdjList;
|
|
261
|
+
exports.getAllStateNodes = getAllStateNodes;
|
|
262
|
+
exports.getChildren = getChildren;
|
|
263
|
+
exports.getConfiguration = getConfiguration;
|
|
264
|
+
exports.getMeta = getMeta;
|
|
265
|
+
exports.getValue = getValue;
|
|
266
|
+
exports.has = has;
|
|
227
267
|
exports.isInFinalState = isInFinalState;
|
|
268
|
+
exports.isLeafNode = isLeafNode;
|
|
269
|
+
exports.nextEvents = nextEvents;
|