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/State.js
CHANGED
|
@@ -1,245 +1,255 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
14
|
-
var t = {};
|
|
15
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
16
|
-
t[p] = s[p];
|
|
17
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
18
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
19
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
20
|
-
t[p[i]] = s[p[i]];
|
|
21
|
-
}
|
|
22
|
-
return t;
|
|
23
|
-
};
|
|
24
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
25
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
26
|
-
if (!m) return o;
|
|
27
|
-
var i = m.call(o), r, ar = [], e;
|
|
28
|
-
try {
|
|
29
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
30
|
-
}
|
|
31
|
-
catch (error) { e = { error: error }; }
|
|
32
|
-
finally {
|
|
33
|
-
try {
|
|
34
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
35
|
-
}
|
|
36
|
-
finally { if (e) throw e.error; }
|
|
37
|
-
}
|
|
38
|
-
return ar;
|
|
39
|
-
};
|
|
40
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from) {
|
|
41
|
-
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
|
|
42
|
-
to[j] = from[i];
|
|
43
|
-
return to;
|
|
44
|
-
};
|
|
45
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
46
|
-
exports.State = exports.bindActionToState = exports.isState = exports.stateValuesEqual = void 0;
|
|
47
|
-
var constants_1 = require("./constants");
|
|
48
|
-
var utils_1 = require("./utils");
|
|
49
|
-
var stateUtils_1 = require("./stateUtils");
|
|
50
|
-
var actions_1 = require("./actions");
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var _tslib = require('./_virtual/_tslib.js');
|
|
6
|
+
var constants = require('./constants.js');
|
|
7
|
+
var utils = require('./utils.js');
|
|
8
|
+
var stateUtils = require('./stateUtils.js');
|
|
9
|
+
var actions = require('./actions.js');
|
|
10
|
+
|
|
51
11
|
function stateValuesEqual(a, b) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
12
|
+
if (a === b) {
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (a === undefined || b === undefined) {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (utils.isString(a) || utils.isString(b)) {
|
|
21
|
+
return a === b;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
var aKeys = utils.keys(a);
|
|
25
|
+
var bKeys = utils.keys(b);
|
|
26
|
+
return aKeys.length === bKeys.length && aKeys.every(function (key) {
|
|
27
|
+
return stateValuesEqual(a[key], b[key]);
|
|
28
|
+
});
|
|
65
29
|
}
|
|
66
|
-
exports.stateValuesEqual = stateValuesEqual;
|
|
67
30
|
function isState(state) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
31
|
+
if (utils.isString(state)) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return 'value' in state && 'history' in state;
|
|
72
36
|
}
|
|
73
|
-
exports.isState = isState;
|
|
74
37
|
function bindActionToState(action, state) {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
38
|
+
var exec = action.exec;
|
|
39
|
+
|
|
40
|
+
var boundAction = _tslib.__assign(_tslib.__assign({}, action), {
|
|
41
|
+
exec: exec !== undefined ? function () {
|
|
42
|
+
return exec(state.context, state.event, {
|
|
43
|
+
action: action,
|
|
44
|
+
state: state,
|
|
45
|
+
_event: state._event
|
|
46
|
+
});
|
|
47
|
+
} : undefined
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
return boundAction;
|
|
86
51
|
}
|
|
87
|
-
|
|
88
|
-
var State =
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
activities: stateValue.activities,
|
|
149
|
-
meta: {},
|
|
150
|
-
events: [],
|
|
151
|
-
configuration: [],
|
|
152
|
-
transitions: [],
|
|
153
|
-
children: {}
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
return stateValue;
|
|
157
|
-
}
|
|
158
|
-
var _event = actions_1.initEvent;
|
|
52
|
+
|
|
53
|
+
var State =
|
|
54
|
+
/*#__PURE__*/
|
|
55
|
+
|
|
56
|
+
/** @class */
|
|
57
|
+
function () {
|
|
58
|
+
/**
|
|
59
|
+
* Creates a new State instance.
|
|
60
|
+
* @param value The state value
|
|
61
|
+
* @param context The extended state
|
|
62
|
+
* @param historyValue The tree representing historical values of the state nodes
|
|
63
|
+
* @param history The previous state
|
|
64
|
+
* @param actions An array of action objects to execute as side-effects
|
|
65
|
+
* @param activities A mapping of activities and whether they are started (`true`) or stopped (`false`).
|
|
66
|
+
* @param meta
|
|
67
|
+
* @param events Internal event queue. Should be empty with run-to-completion semantics.
|
|
68
|
+
* @param configuration
|
|
69
|
+
*/
|
|
70
|
+
function State(config) {
|
|
71
|
+
var _this = this;
|
|
72
|
+
|
|
73
|
+
var _a;
|
|
74
|
+
|
|
75
|
+
this.actions = [];
|
|
76
|
+
this.activities = constants.EMPTY_ACTIVITY_MAP;
|
|
77
|
+
this.meta = {};
|
|
78
|
+
this.events = [];
|
|
79
|
+
this.value = config.value;
|
|
80
|
+
this.context = config.context;
|
|
81
|
+
this._event = config._event;
|
|
82
|
+
this._sessionid = config._sessionid;
|
|
83
|
+
this.event = this._event.data;
|
|
84
|
+
this.historyValue = config.historyValue;
|
|
85
|
+
this.history = config.history;
|
|
86
|
+
this.actions = config.actions || [];
|
|
87
|
+
this.activities = config.activities || constants.EMPTY_ACTIVITY_MAP;
|
|
88
|
+
this.meta = stateUtils.getMeta(config.configuration);
|
|
89
|
+
this.events = config.events || [];
|
|
90
|
+
this.matches = this.matches.bind(this);
|
|
91
|
+
this.toStrings = this.toStrings.bind(this);
|
|
92
|
+
this.configuration = config.configuration;
|
|
93
|
+
this.transitions = config.transitions;
|
|
94
|
+
this.children = config.children;
|
|
95
|
+
this.done = !!config.done;
|
|
96
|
+
this.tags = (_a = config.tags) !== null && _a !== void 0 ? _a : new Set();
|
|
97
|
+
Object.defineProperty(this, 'nextEvents', {
|
|
98
|
+
get: function () {
|
|
99
|
+
return stateUtils.nextEvents(_this.configuration);
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Creates a new State instance for the given `stateValue` and `context`.
|
|
105
|
+
* @param stateValue
|
|
106
|
+
* @param context
|
|
107
|
+
*/
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
State.from = function (stateValue, context) {
|
|
111
|
+
if (stateValue instanceof State) {
|
|
112
|
+
if (stateValue.context !== context) {
|
|
159
113
|
return new State({
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
114
|
+
value: stateValue.value,
|
|
115
|
+
context: context,
|
|
116
|
+
_event: stateValue._event,
|
|
117
|
+
_sessionid: null,
|
|
118
|
+
historyValue: stateValue.historyValue,
|
|
119
|
+
history: stateValue.history,
|
|
120
|
+
actions: [],
|
|
121
|
+
activities: stateValue.activities,
|
|
122
|
+
meta: {},
|
|
123
|
+
events: [],
|
|
124
|
+
configuration: [],
|
|
125
|
+
transitions: [],
|
|
126
|
+
children: {}
|
|
173
127
|
});
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
State.
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return stateValue;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
var _event = actions.initEvent;
|
|
134
|
+
return new State({
|
|
135
|
+
value: stateValue,
|
|
136
|
+
context: context,
|
|
137
|
+
_event: _event,
|
|
138
|
+
_sessionid: null,
|
|
139
|
+
historyValue: undefined,
|
|
140
|
+
history: undefined,
|
|
141
|
+
actions: [],
|
|
142
|
+
activities: undefined,
|
|
143
|
+
meta: undefined,
|
|
144
|
+
events: [],
|
|
145
|
+
configuration: [],
|
|
146
|
+
transitions: [],
|
|
147
|
+
children: {}
|
|
148
|
+
});
|
|
149
|
+
};
|
|
150
|
+
/**
|
|
151
|
+
* Creates a new State instance for the given `config`.
|
|
152
|
+
* @param config The state config
|
|
153
|
+
*/
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
State.create = function (config) {
|
|
157
|
+
return new State(config);
|
|
158
|
+
};
|
|
159
|
+
/**
|
|
160
|
+
* Creates a new `State` instance for the given `stateValue` and `context` with no actions (side-effects).
|
|
161
|
+
* @param stateValue
|
|
162
|
+
* @param context
|
|
163
|
+
*/
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
State.inert = function (stateValue, context) {
|
|
167
|
+
if (stateValue instanceof State) {
|
|
168
|
+
if (!stateValue.actions.length) {
|
|
169
|
+
return stateValue;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
var _event = actions.initEvent;
|
|
173
|
+
return new State({
|
|
174
|
+
value: stateValue.value,
|
|
175
|
+
context: context,
|
|
176
|
+
_event: _event,
|
|
177
|
+
_sessionid: null,
|
|
178
|
+
historyValue: stateValue.historyValue,
|
|
179
|
+
history: stateValue.history,
|
|
180
|
+
activities: stateValue.activities,
|
|
181
|
+
configuration: stateValue.configuration,
|
|
182
|
+
transitions: [],
|
|
183
|
+
children: {}
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
return State.from(stateValue, context);
|
|
188
|
+
};
|
|
189
|
+
/**
|
|
190
|
+
* Returns an array of all the string leaf state node paths.
|
|
191
|
+
* @param stateValue
|
|
192
|
+
* @param delimiter The character(s) that separate each subpath in the string state node path.
|
|
193
|
+
*/
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
State.prototype.toStrings = function (stateValue, delimiter) {
|
|
197
|
+
var _this = this;
|
|
198
|
+
|
|
199
|
+
if (stateValue === void 0) {
|
|
200
|
+
stateValue = this.value;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
if (delimiter === void 0) {
|
|
204
|
+
delimiter = '.';
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
if (utils.isString(stateValue)) {
|
|
208
|
+
return [stateValue];
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
var valueKeys = utils.keys(stateValue);
|
|
212
|
+
return valueKeys.concat.apply(valueKeys, _tslib.__spreadArray([], _tslib.__read(valueKeys.map(function (key) {
|
|
213
|
+
return _this.toStrings(stateValue[key], delimiter).map(function (s) {
|
|
214
|
+
return key + delimiter + s;
|
|
215
|
+
});
|
|
216
|
+
}))));
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
State.prototype.toJSON = function () {
|
|
220
|
+
var _a = this,
|
|
221
|
+
configuration = _a.configuration,
|
|
222
|
+
transitions = _a.transitions,
|
|
223
|
+
tags = _a.tags,
|
|
224
|
+
jsonValues = _tslib.__rest(_a, ["configuration", "transitions", "tags"]);
|
|
225
|
+
|
|
226
|
+
return _tslib.__assign(_tslib.__assign({}, jsonValues), {
|
|
227
|
+
tags: Array.from(tags)
|
|
228
|
+
});
|
|
229
|
+
};
|
|
230
|
+
/**
|
|
231
|
+
* Whether the current state value is a subset of the given parent state value.
|
|
232
|
+
* @param parentStateValue
|
|
233
|
+
*/
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
State.prototype.matches = function (parentStateValue) {
|
|
237
|
+
return utils.matchesState(parentStateValue, this.value);
|
|
238
|
+
};
|
|
239
|
+
/**
|
|
240
|
+
* Whether the current state configuration has a state node with the specified `tag`.
|
|
241
|
+
* @param tag
|
|
242
|
+
*/
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
State.prototype.hasTag = function (tag) {
|
|
246
|
+
return this.tags.has(tag);
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
return State;
|
|
250
|
+
}();
|
|
251
|
+
|
|
245
252
|
exports.State = State;
|
|
253
|
+
exports.bindActionToState = bindActionToState;
|
|
254
|
+
exports.isState = isState;
|
|
255
|
+
exports.stateValuesEqual = stateValuesEqual;
|