xstate 4.20.1 → 4.23.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.
Files changed (92) hide show
  1. package/CHANGELOG.md +134 -0
  2. package/dist/xstate.interpreter.js +1 -1
  3. package/dist/xstate.js +1 -1
  4. package/dist/xstate.web.js +2 -2
  5. package/es/Actor.js +17 -5
  6. package/es/Machine.d.ts +6 -3
  7. package/es/Machine.js +3 -6
  8. package/es/State.js +1 -3
  9. package/es/StateNode.d.ts +4 -3
  10. package/es/StateNode.js +34 -20
  11. package/es/_virtual/_tslib.js +59 -73
  12. package/es/actionTypes.js +3 -2
  13. package/es/actions.d.ts +1 -1
  14. package/es/actions.js +51 -37
  15. package/es/behaviors.d.ts +37 -0
  16. package/es/behaviors.js +65 -0
  17. package/es/constants.js +2 -1
  18. package/es/devTools.js +1 -1
  19. package/es/environment.js +2 -1
  20. package/es/index.js +3 -1
  21. package/es/interpreter.d.ts +10 -3
  22. package/es/interpreter.js +44 -22
  23. package/es/invokeUtils.js +4 -3
  24. package/es/mapState.js +1 -1
  25. package/es/match.js +1 -1
  26. package/es/model.d.ts +2 -36
  27. package/es/model.types.d.ts +37 -0
  28. package/es/registry.js +2 -1
  29. package/es/scheduler.js +2 -1
  30. package/es/schema.js +1 -1
  31. package/es/serviceScope.js +1 -3
  32. package/es/stateUtils.js +1 -9
  33. package/es/types.d.ts +26 -5
  34. package/es/types.js +1 -1
  35. package/es/utils.d.ts +3 -2
  36. package/es/utils.js +4 -40
  37. package/lib/Actor.d.ts +25 -25
  38. package/lib/Actor.js +85 -66
  39. package/lib/Machine.d.ts +17 -14
  40. package/lib/Machine.js +14 -14
  41. package/lib/SimulatedClock.d.ts +16 -16
  42. package/lib/State.d.ts +108 -108
  43. package/lib/State.js +246 -236
  44. package/lib/StateNode.d.ts +279 -278
  45. package/lib/StateNode.js +1535 -1339
  46. package/lib/_virtual/_tslib.js +81 -0
  47. package/lib/actionTypes.d.ts +19 -19
  48. package/lib/actionTypes.js +43 -23
  49. package/lib/actions.d.ts +138 -138
  50. package/lib/actions.js +465 -387
  51. package/lib/behaviors.d.ts +37 -0
  52. package/lib/behaviors.js +69 -0
  53. package/lib/constants.d.ts +5 -5
  54. package/lib/constants.js +13 -7
  55. package/lib/devTools.d.ts +15 -15
  56. package/lib/devTools.js +37 -26
  57. package/lib/each.d.ts +3 -3
  58. package/lib/environment.d.ts +1 -1
  59. package/lib/environment.js +7 -4
  60. package/lib/index.d.ts +30 -30
  61. package/lib/index.js +67 -57
  62. package/lib/interpreter.d.ts +205 -198
  63. package/lib/interpreter.js +1306 -1054
  64. package/lib/invoke.d.ts +10 -10
  65. package/lib/invokeUtils.d.ts +6 -6
  66. package/lib/invokeUtils.js +40 -37
  67. package/lib/json.d.ts +30 -30
  68. package/lib/mapState.d.ts +3 -3
  69. package/lib/mapState.js +31 -32
  70. package/lib/match.d.ts +8 -8
  71. package/lib/match.js +33 -47
  72. package/lib/model.d.ts +4 -38
  73. package/lib/model.js +5 -1
  74. package/lib/model.types.d.ts +37 -0
  75. package/lib/model.types.js +2 -0
  76. package/lib/patterns.d.ts +13 -13
  77. package/lib/registry.d.ts +8 -8
  78. package/lib/registry.js +21 -18
  79. package/lib/scheduler.d.ts +16 -16
  80. package/lib/scheduler.js +79 -70
  81. package/lib/schema.d.ts +1 -1
  82. package/lib/schema.js +6 -4
  83. package/lib/scxml.d.ts +5 -5
  84. package/lib/serviceScope.d.ts +3 -3
  85. package/lib/serviceScope.js +16 -12
  86. package/lib/stateUtils.d.ts +14 -14
  87. package/lib/stateUtils.js +231 -199
  88. package/lib/types.d.ts +928 -907
  89. package/lib/types.js +29 -29
  90. package/lib/utils.d.ts +68 -67
  91. package/lib/utils.js +530 -529
  92. package/package.json +6 -6
package/lib/utils.js CHANGED
@@ -1,472 +1,425 @@
1
- "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- var __values = (this && this.__values) || function(o) {
14
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
15
- if (m) return m.call(o);
16
- if (o && typeof o.length === "number") return {
17
- next: function () {
18
- if (o && i >= o.length) o = void 0;
19
- return { value: o && o[i++], done: !o };
20
- }
21
- };
22
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
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.toObserver = exports.toInvokeSource = exports.evaluateGuard = exports.reportUnhandledExceptionOnInvocation = exports.normalizeTarget = exports.toTransitionConfigArray = exports.toSCXMLEvent = exports.toEventObject = exports.uniqueId = exports.isActor = exports.isMachine = exports.symbolObservable = exports.isObservable = exports.toGuard = exports.isString = exports.isFunction = exports.isArray = exports.warn = exports.updateContext = exports.updateHistoryValue = exports.updateHistoryStates = exports.partition = exports.isPromiseLike = exports.isBuiltInEvent = exports.mapContext = exports.toArray = exports.toArrayStrict = exports.flatten = exports.pathsToStateValue = exports.toStatePaths = exports.nestedPath = exports.path = exports.mapFilterValues = exports.mapValues = exports.pathToStateValue = exports.toStateValue = exports.isStateLike = exports.toStatePath = exports.getActionType = exports.getEventType = exports.matchesState = exports.keys = void 0;
47
- var constants_1 = require("./constants");
48
- var environment_1 = require("./environment");
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 environment = require('./environment.js');
8
+
49
9
  function keys(value) {
50
- return Object.keys(value);
10
+ return Object.keys(value);
51
11
  }
52
- exports.keys = keys;
53
12
  function matchesState(parentStateId, childStateId, delimiter) {
54
- if (delimiter === void 0) { delimiter = constants_1.STATE_DELIMITER; }
55
- var parentStateValue = toStateValue(parentStateId, delimiter);
56
- var childStateValue = toStateValue(childStateId, delimiter);
57
- if (isString(childStateValue)) {
58
- if (isString(parentStateValue)) {
59
- return childStateValue === parentStateValue;
60
- }
61
- // Parent more specific than child
62
- return false;
63
- }
13
+ if (delimiter === void 0) {
14
+ delimiter = constants.STATE_DELIMITER;
15
+ }
16
+
17
+ var parentStateValue = toStateValue(parentStateId, delimiter);
18
+ var childStateValue = toStateValue(childStateId, delimiter);
19
+
20
+ if (isString(childStateValue)) {
64
21
  if (isString(parentStateValue)) {
65
- return parentStateValue in childStateValue;
66
- }
67
- return keys(parentStateValue).every(function (key) {
68
- if (!(key in childStateValue)) {
69
- return false;
70
- }
71
- return matchesState(parentStateValue[key], childStateValue[key]);
72
- });
22
+ return childStateValue === parentStateValue;
23
+ } // Parent more specific than child
24
+
25
+
26
+ return false;
27
+ }
28
+
29
+ if (isString(parentStateValue)) {
30
+ return parentStateValue in childStateValue;
31
+ }
32
+
33
+ return keys(parentStateValue).every(function (key) {
34
+ if (!(key in childStateValue)) {
35
+ return false;
36
+ }
37
+
38
+ return matchesState(parentStateValue[key], childStateValue[key]);
39
+ });
73
40
  }
74
- exports.matchesState = matchesState;
75
41
  function getEventType(event) {
76
- try {
77
- return isString(event) || typeof event === 'number'
78
- ? "" + event
79
- : event.type;
80
- }
81
- catch (e) {
82
- throw new Error('Events must be strings or objects with a string event.type property.');
83
- }
84
- }
85
- exports.getEventType = getEventType;
86
- function getActionType(action) {
87
- try {
88
- return isString(action) || typeof action === 'number'
89
- ? "" + action
90
- : isFunction(action)
91
- ? action.name
92
- : action.type;
93
- }
94
- catch (e) {
95
- throw new Error('Actions must be strings or objects with a string action.type property.');
96
- }
42
+ try {
43
+ return isString(event) || typeof event === 'number' ? "" + event : event.type;
44
+ } catch (e) {
45
+ throw new Error('Events must be strings or objects with a string event.type property.');
46
+ }
97
47
  }
98
- exports.getActionType = getActionType;
99
48
  function toStatePath(stateId, delimiter) {
100
- try {
101
- if (isArray(stateId)) {
102
- return stateId;
103
- }
104
- return stateId.toString().split(delimiter);
105
- }
106
- catch (e) {
107
- throw new Error("'" + stateId + "' is not a valid state path.");
49
+ try {
50
+ if (isArray(stateId)) {
51
+ return stateId;
108
52
  }
53
+
54
+ return stateId.toString().split(delimiter);
55
+ } catch (e) {
56
+ throw new Error("'" + stateId + "' is not a valid state path.");
57
+ }
109
58
  }
110
- exports.toStatePath = toStatePath;
111
59
  function isStateLike(state) {
112
- return (typeof state === 'object' &&
113
- 'value' in state &&
114
- 'context' in state &&
115
- 'event' in state &&
116
- '_event' in state);
60
+ return typeof state === 'object' && 'value' in state && 'context' in state && 'event' in state && '_event' in state;
117
61
  }
118
- exports.isStateLike = isStateLike;
119
62
  function toStateValue(stateValue, delimiter) {
120
- if (isStateLike(stateValue)) {
121
- return stateValue.value;
122
- }
123
- if (isArray(stateValue)) {
124
- return pathToStateValue(stateValue);
125
- }
126
- if (typeof stateValue !== 'string') {
127
- return stateValue;
128
- }
129
- var statePath = toStatePath(stateValue, delimiter);
130
- return pathToStateValue(statePath);
63
+ if (isStateLike(stateValue)) {
64
+ return stateValue.value;
65
+ }
66
+
67
+ if (isArray(stateValue)) {
68
+ return pathToStateValue(stateValue);
69
+ }
70
+
71
+ if (typeof stateValue !== 'string') {
72
+ return stateValue;
73
+ }
74
+
75
+ var statePath = toStatePath(stateValue, delimiter);
76
+ return pathToStateValue(statePath);
131
77
  }
132
- exports.toStateValue = toStateValue;
133
78
  function pathToStateValue(statePath) {
134
- if (statePath.length === 1) {
135
- return statePath[0];
136
- }
137
- var value = {};
138
- var marker = value;
139
- for (var i = 0; i < statePath.length - 1; i++) {
140
- if (i === statePath.length - 2) {
141
- marker[statePath[i]] = statePath[i + 1];
142
- }
143
- else {
144
- marker[statePath[i]] = {};
145
- marker = marker[statePath[i]];
146
- }
147
- }
148
- return value;
79
+ if (statePath.length === 1) {
80
+ return statePath[0];
81
+ }
82
+
83
+ var value = {};
84
+ var marker = value;
85
+
86
+ for (var i = 0; i < statePath.length - 1; i++) {
87
+ if (i === statePath.length - 2) {
88
+ marker[statePath[i]] = statePath[i + 1];
89
+ } else {
90
+ marker[statePath[i]] = {};
91
+ marker = marker[statePath[i]];
92
+ }
93
+ }
94
+
95
+ return value;
149
96
  }
150
- exports.pathToStateValue = pathToStateValue;
151
97
  function mapValues(collection, iteratee) {
152
- var result = {};
153
- var collectionKeys = keys(collection);
154
- for (var i = 0; i < collectionKeys.length; i++) {
155
- var key = collectionKeys[i];
156
- result[key] = iteratee(collection[key], key, collection, i);
157
- }
158
- return result;
98
+ var result = {};
99
+ var collectionKeys = keys(collection);
100
+
101
+ for (var i = 0; i < collectionKeys.length; i++) {
102
+ var key = collectionKeys[i];
103
+ result[key] = iteratee(collection[key], key, collection, i);
104
+ }
105
+
106
+ return result;
159
107
  }
160
- exports.mapValues = mapValues;
161
108
  function mapFilterValues(collection, iteratee, predicate) {
162
- var e_1, _a;
163
- var result = {};
109
+ var e_1, _a;
110
+
111
+ var result = {};
112
+
113
+ try {
114
+ for (var _b = _tslib.__values(keys(collection)), _c = _b.next(); !_c.done; _c = _b.next()) {
115
+ var key = _c.value;
116
+ var item = collection[key];
117
+
118
+ if (!predicate(item)) {
119
+ continue;
120
+ }
121
+
122
+ result[key] = iteratee(item, key, collection);
123
+ }
124
+ } catch (e_1_1) {
125
+ e_1 = {
126
+ error: e_1_1
127
+ };
128
+ } finally {
164
129
  try {
165
- for (var _b = __values(keys(collection)), _c = _b.next(); !_c.done; _c = _b.next()) {
166
- var key = _c.value;
167
- var item = collection[key];
168
- if (!predicate(item)) {
169
- continue;
170
- }
171
- result[key] = iteratee(item, key, collection);
172
- }
173
- }
174
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
175
- finally {
176
- try {
177
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
178
- }
179
- finally { if (e_1) throw e_1.error; }
130
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
131
+ } finally {
132
+ if (e_1) throw e_1.error;
180
133
  }
181
- return result;
134
+ }
135
+
136
+ return result;
182
137
  }
183
- exports.mapFilterValues = mapFilterValues;
184
- /**
185
- * Retrieves a value at the given path.
186
- * @param props The deep path to the prop of the desired value
138
+ /**
139
+ * Retrieves a value at the given path.
140
+ * @param props The deep path to the prop of the desired value
187
141
  */
188
- var path = function (props) { return function (object) {
142
+
143
+ var path = function (props) {
144
+ return function (object) {
189
145
  var e_2, _a;
146
+
190
147
  var result = object;
148
+
191
149
  try {
192
- for (var props_1 = __values(props), props_1_1 = props_1.next(); !props_1_1.done; props_1_1 = props_1.next()) {
193
- var prop = props_1_1.value;
194
- result = result[prop];
195
- }
196
- }
197
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
198
- finally {
199
- try {
200
- if (props_1_1 && !props_1_1.done && (_a = props_1.return)) _a.call(props_1);
201
- }
202
- finally { if (e_2) throw e_2.error; }
203
- }
150
+ for (var props_1 = _tslib.__values(props), props_1_1 = props_1.next(); !props_1_1.done; props_1_1 = props_1.next()) {
151
+ var prop = props_1_1.value;
152
+ result = result[prop];
153
+ }
154
+ } catch (e_2_1) {
155
+ e_2 = {
156
+ error: e_2_1
157
+ };
158
+ } finally {
159
+ try {
160
+ if (props_1_1 && !props_1_1.done && (_a = props_1.return)) _a.call(props_1);
161
+ } finally {
162
+ if (e_2) throw e_2.error;
163
+ }
164
+ }
165
+
204
166
  return result;
205
- }; };
206
- exports.path = path;
207
- /**
208
- * Retrieves a value at the given path via the nested accessor prop.
209
- * @param props The deep path to the prop of the desired value
167
+ };
168
+ };
169
+ /**
170
+ * Retrieves a value at the given path via the nested accessor prop.
171
+ * @param props The deep path to the prop of the desired value
210
172
  */
173
+
211
174
  function nestedPath(props, accessorProp) {
212
- return function (object) {
213
- var e_3, _a;
214
- var result = object;
215
- try {
216
- for (var props_2 = __values(props), props_2_1 = props_2.next(); !props_2_1.done; props_2_1 = props_2.next()) {
217
- var prop = props_2_1.value;
218
- result = result[accessorProp][prop];
219
- }
220
- }
221
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
222
- finally {
223
- try {
224
- if (props_2_1 && !props_2_1.done && (_a = props_2.return)) _a.call(props_2);
225
- }
226
- finally { if (e_3) throw e_3.error; }
227
- }
228
- return result;
229
- };
230
- }
231
- exports.nestedPath = nestedPath;
232
- function toStatePaths(stateValue) {
233
- if (!stateValue) {
234
- return [[]];
235
- }
236
- if (isString(stateValue)) {
237
- return [[stateValue]];
238
- }
239
- var result = flatten(keys(stateValue).map(function (key) {
240
- var subStateValue = stateValue[key];
241
- if (typeof subStateValue !== 'string' &&
242
- (!subStateValue || !Object.keys(subStateValue).length)) {
243
- return [[key]];
244
- }
245
- return toStatePaths(stateValue[key]).map(function (subPath) {
246
- return [key].concat(subPath);
247
- });
248
- }));
249
- return result;
250
- }
251
- exports.toStatePaths = toStatePaths;
252
- function pathsToStateValue(paths) {
253
- var e_4, _a;
254
- var result = {};
255
- if (paths && paths.length === 1 && paths[0].length === 1) {
256
- return paths[0][0];
257
- }
175
+ return function (object) {
176
+ var e_3, _a;
177
+
178
+ var result = object;
179
+
258
180
  try {
259
- for (var paths_1 = __values(paths), paths_1_1 = paths_1.next(); !paths_1_1.done; paths_1_1 = paths_1.next()) {
260
- var currentPath = paths_1_1.value;
261
- var marker = result;
262
- // tslint:disable-next-line:prefer-for-of
263
- for (var i = 0; i < currentPath.length; i++) {
264
- var subPath = currentPath[i];
265
- if (i === currentPath.length - 2) {
266
- marker[subPath] = currentPath[i + 1];
267
- break;
268
- }
269
- marker[subPath] = marker[subPath] || {};
270
- marker = marker[subPath];
271
- }
272
- }
273
- }
274
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
275
- finally {
276
- try {
277
- if (paths_1_1 && !paths_1_1.done && (_a = paths_1.return)) _a.call(paths_1);
278
- }
279
- finally { if (e_4) throw e_4.error; }
280
- }
181
+ for (var props_2 = _tslib.__values(props), props_2_1 = props_2.next(); !props_2_1.done; props_2_1 = props_2.next()) {
182
+ var prop = props_2_1.value;
183
+ result = result[accessorProp][prop];
184
+ }
185
+ } catch (e_3_1) {
186
+ e_3 = {
187
+ error: e_3_1
188
+ };
189
+ } finally {
190
+ try {
191
+ if (props_2_1 && !props_2_1.done && (_a = props_2.return)) _a.call(props_2);
192
+ } finally {
193
+ if (e_3) throw e_3.error;
194
+ }
195
+ }
196
+
281
197
  return result;
198
+ };
199
+ }
200
+ function toStatePaths(stateValue) {
201
+ if (!stateValue) {
202
+ return [[]];
203
+ }
204
+
205
+ if (isString(stateValue)) {
206
+ return [[stateValue]];
207
+ }
208
+
209
+ var result = flatten(keys(stateValue).map(function (key) {
210
+ var subStateValue = stateValue[key];
211
+
212
+ if (typeof subStateValue !== 'string' && (!subStateValue || !Object.keys(subStateValue).length)) {
213
+ return [[key]];
214
+ }
215
+
216
+ return toStatePaths(stateValue[key]).map(function (subPath) {
217
+ return [key].concat(subPath);
218
+ });
219
+ }));
220
+ return result;
282
221
  }
283
- exports.pathsToStateValue = pathsToStateValue;
284
222
  function flatten(array) {
285
- var _a;
286
- return (_a = []).concat.apply(_a, __spreadArray([], __read(array)));
223
+ var _a;
224
+
225
+ return (_a = []).concat.apply(_a, _tslib.__spreadArray([], _tslib.__read(array)));
287
226
  }
288
- exports.flatten = flatten;
289
227
  function toArrayStrict(value) {
290
- if (isArray(value)) {
291
- return value;
292
- }
293
- return [value];
228
+ if (isArray(value)) {
229
+ return value;
230
+ }
231
+
232
+ return [value];
294
233
  }
295
- exports.toArrayStrict = toArrayStrict;
296
234
  function toArray(value) {
297
- if (value === undefined) {
298
- return [];
299
- }
300
- return toArrayStrict(value);
235
+ if (value === undefined) {
236
+ return [];
237
+ }
238
+
239
+ return toArrayStrict(value);
301
240
  }
302
- exports.toArray = toArray;
303
241
  function mapContext(mapper, context, _event) {
304
- var e_5, _a;
305
- if (isFunction(mapper)) {
306
- return mapper(context, _event.data);
307
- }
308
- var result = {};
242
+ var e_5, _a;
243
+
244
+ if (isFunction(mapper)) {
245
+ return mapper(context, _event.data);
246
+ }
247
+
248
+ var result = {};
249
+
250
+ try {
251
+ for (var _b = _tslib.__values(Object.keys(mapper)), _c = _b.next(); !_c.done; _c = _b.next()) {
252
+ var key = _c.value;
253
+ var subMapper = mapper[key];
254
+
255
+ if (isFunction(subMapper)) {
256
+ result[key] = subMapper(context, _event.data);
257
+ } else {
258
+ result[key] = subMapper;
259
+ }
260
+ }
261
+ } catch (e_5_1) {
262
+ e_5 = {
263
+ error: e_5_1
264
+ };
265
+ } finally {
309
266
  try {
310
- for (var _b = __values(Object.keys(mapper)), _c = _b.next(); !_c.done; _c = _b.next()) {
311
- var key = _c.value;
312
- var subMapper = mapper[key];
313
- if (isFunction(subMapper)) {
314
- result[key] = subMapper(context, _event.data);
315
- }
316
- else {
317
- result[key] = subMapper;
318
- }
319
- }
267
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
268
+ } finally {
269
+ if (e_5) throw e_5.error;
320
270
  }
321
- catch (e_5_1) { e_5 = { error: e_5_1 }; }
322
- finally {
323
- try {
324
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
325
- }
326
- finally { if (e_5) throw e_5.error; }
327
- }
328
- return result;
271
+ }
272
+
273
+ return result;
329
274
  }
330
- exports.mapContext = mapContext;
331
275
  function isBuiltInEvent(eventType) {
332
- return /^(done|error)\./.test(eventType);
276
+ return /^(done|error)\./.test(eventType);
333
277
  }
334
- exports.isBuiltInEvent = isBuiltInEvent;
335
278
  function isPromiseLike(value) {
336
- if (value instanceof Promise) {
337
- return true;
338
- }
339
- // Check if shape matches the Promise/A+ specification for a "thenable".
340
- if (value !== null &&
341
- (isFunction(value) || typeof value === 'object') &&
342
- isFunction(value.then)) {
343
- return true;
344
- }
345
- return false;
279
+ if (value instanceof Promise) {
280
+ return true;
281
+ } // Check if shape matches the Promise/A+ specification for a "thenable".
282
+
283
+
284
+ if (value !== null && (isFunction(value) || typeof value === 'object') && isFunction(value.then)) {
285
+ return true;
286
+ }
287
+
288
+ return false;
289
+ }
290
+ function isBehavior(value) {
291
+ return value !== null && typeof value === 'object' && 'transition' in value && typeof value.transition === 'function';
346
292
  }
347
- exports.isPromiseLike = isPromiseLike;
348
293
  function partition(items, predicate) {
349
- var e_6, _a;
350
- var _b = __read([[], []], 2), truthy = _b[0], falsy = _b[1];
294
+ var e_6, _a;
295
+
296
+ var _b = _tslib.__read([[], []], 2),
297
+ truthy = _b[0],
298
+ falsy = _b[1];
299
+
300
+ try {
301
+ for (var items_1 = _tslib.__values(items), items_1_1 = items_1.next(); !items_1_1.done; items_1_1 = items_1.next()) {
302
+ var item = items_1_1.value;
303
+
304
+ if (predicate(item)) {
305
+ truthy.push(item);
306
+ } else {
307
+ falsy.push(item);
308
+ }
309
+ }
310
+ } catch (e_6_1) {
311
+ e_6 = {
312
+ error: e_6_1
313
+ };
314
+ } finally {
351
315
  try {
352
- for (var items_1 = __values(items), items_1_1 = items_1.next(); !items_1_1.done; items_1_1 = items_1.next()) {
353
- var item = items_1_1.value;
354
- if (predicate(item)) {
355
- truthy.push(item);
356
- }
357
- else {
358
- falsy.push(item);
359
- }
360
- }
361
- }
362
- catch (e_6_1) { e_6 = { error: e_6_1 }; }
363
- finally {
364
- try {
365
- if (items_1_1 && !items_1_1.done && (_a = items_1.return)) _a.call(items_1);
366
- }
367
- finally { if (e_6) throw e_6.error; }
316
+ if (items_1_1 && !items_1_1.done && (_a = items_1.return)) _a.call(items_1);
317
+ } finally {
318
+ if (e_6) throw e_6.error;
368
319
  }
369
- return [truthy, falsy];
320
+ }
321
+
322
+ return [truthy, falsy];
370
323
  }
371
- exports.partition = partition;
372
324
  function updateHistoryStates(hist, stateValue) {
373
- return mapValues(hist.states, function (subHist, key) {
374
- if (!subHist) {
375
- return undefined;
376
- }
377
- var subStateValue = (isString(stateValue) ? undefined : stateValue[key]) ||
378
- (subHist ? subHist.current : undefined);
379
- if (!subStateValue) {
380
- return undefined;
381
- }
382
- return {
383
- current: subStateValue,
384
- states: updateHistoryStates(subHist, subStateValue)
385
- };
386
- });
387
- }
388
- exports.updateHistoryStates = updateHistoryStates;
389
- function updateHistoryValue(hist, stateValue) {
325
+ return mapValues(hist.states, function (subHist, key) {
326
+ if (!subHist) {
327
+ return undefined;
328
+ }
329
+
330
+ var subStateValue = (isString(stateValue) ? undefined : stateValue[key]) || (subHist ? subHist.current : undefined);
331
+
332
+ if (!subStateValue) {
333
+ return undefined;
334
+ }
335
+
390
336
  return {
391
- current: stateValue,
392
- states: updateHistoryStates(hist, stateValue)
337
+ current: subStateValue,
338
+ states: updateHistoryStates(subHist, subStateValue)
393
339
  };
340
+ });
394
341
  }
395
- exports.updateHistoryValue = updateHistoryValue;
396
- function updateContext(context, _event, assignActions, state) {
397
- if (!environment_1.IS_PRODUCTION) {
398
- warn(!!context, 'Attempting to update undefined context');
399
- }
400
- var updatedContext = context
401
- ? assignActions.reduce(function (acc, assignAction) {
402
- var e_7, _a;
403
- var assignment = assignAction.assignment;
404
- var meta = {
405
- state: state,
406
- action: assignAction,
407
- _event: _event
408
- };
409
- var partialUpdate = {};
410
- if (isFunction(assignment)) {
411
- partialUpdate = assignment(acc, _event.data, meta);
412
- }
413
- else {
414
- try {
415
- for (var _b = __values(keys(assignment)), _c = _b.next(); !_c.done; _c = _b.next()) {
416
- var key = _c.value;
417
- var propAssignment = assignment[key];
418
- partialUpdate[key] = isFunction(propAssignment)
419
- ? propAssignment(acc, _event.data, meta)
420
- : propAssignment;
421
- }
422
- }
423
- catch (e_7_1) { e_7 = { error: e_7_1 }; }
424
- finally {
425
- try {
426
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
427
- }
428
- finally { if (e_7) throw e_7.error; }
429
- }
430
- }
431
- return Object.assign({}, acc, partialUpdate);
432
- }, context)
433
- : context;
434
- return updatedContext;
342
+ function updateHistoryValue(hist, stateValue) {
343
+ return {
344
+ current: stateValue,
345
+ states: updateHistoryStates(hist, stateValue)
346
+ };
435
347
  }
436
- exports.updateContext = updateContext;
437
- // tslint:disable-next-line:no-empty
438
- var warn = function () { };
439
- exports.warn = warn;
440
- if (!environment_1.IS_PRODUCTION) {
441
- exports.warn = warn = function (condition, message) {
442
- var error = condition instanceof Error ? condition : undefined;
443
- if (!error && condition) {
444
- return;
348
+ function updateContext(context, _event, assignActions, state) {
349
+ if (!environment.IS_PRODUCTION) {
350
+ exports.warn(!!context, 'Attempting to update undefined context');
351
+ }
352
+
353
+ var updatedContext = context ? assignActions.reduce(function (acc, assignAction) {
354
+ var e_7, _a;
355
+
356
+ var assignment = assignAction.assignment;
357
+ var meta = {
358
+ state: state,
359
+ action: assignAction,
360
+ _event: _event
361
+ };
362
+ var partialUpdate = {};
363
+
364
+ if (isFunction(assignment)) {
365
+ partialUpdate = assignment(acc, _event.data, meta);
366
+ } else {
367
+ try {
368
+ for (var _b = _tslib.__values(keys(assignment)), _c = _b.next(); !_c.done; _c = _b.next()) {
369
+ var key = _c.value;
370
+ var propAssignment = assignment[key];
371
+ partialUpdate[key] = isFunction(propAssignment) ? propAssignment(acc, _event.data, meta) : propAssignment;
445
372
  }
446
- if (console !== undefined) {
447
- var args = ["Warning: " + message];
448
- if (error) {
449
- args.push(error);
450
- }
451
- // tslint:disable-next-line:no-console
452
- console.warn.apply(console, args);
373
+ } catch (e_7_1) {
374
+ e_7 = {
375
+ error: e_7_1
376
+ };
377
+ } finally {
378
+ try {
379
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
380
+ } finally {
381
+ if (e_7) throw e_7.error;
453
382
  }
454
- };
383
+ }
384
+ }
385
+
386
+ return Object.assign({}, acc, partialUpdate);
387
+ }, context) : context;
388
+ return updatedContext;
389
+ } // tslint:disable-next-line:no-empty
390
+
391
+ exports.warn = function () {};
392
+
393
+ if (!environment.IS_PRODUCTION) {
394
+ exports.warn = function (condition, message) {
395
+ var error = condition instanceof Error ? condition : undefined;
396
+
397
+ if (!error && condition) {
398
+ return;
399
+ }
400
+
401
+ if (console !== undefined) {
402
+ var args = ["Warning: " + message];
403
+
404
+ if (error) {
405
+ args.push(error);
406
+ } // tslint:disable-next-line:no-console
407
+
408
+
409
+ console.warn.apply(console, args);
410
+ }
411
+ };
455
412
  }
456
413
  function isArray(value) {
457
- return Array.isArray(value);
458
- }
459
- exports.isArray = isArray;
460
- // tslint:disable-next-line:ban-types
414
+ return Array.isArray(value);
415
+ } // tslint:disable-next-line:ban-types
416
+
461
417
  function isFunction(value) {
462
- return typeof value === 'function';
418
+ return typeof value === 'function';
463
419
  }
464
- exports.isFunction = isFunction;
465
420
  function isString(value) {
466
- return typeof value === 'string';
467
- }
468
- exports.isString = isString;
469
- // export function memoizedGetter<T, TP extends { prototype: object }>(
421
+ return typeof value === 'string';
422
+ } // export function memoizedGetter<T, TP extends { prototype: object }>(
470
423
  // o: TP,
471
424
  // property: string,
472
425
  // getter: () => T
@@ -477,150 +430,198 @@ exports.isString = isString;
477
430
  // configurable: false
478
431
  // });
479
432
  // }
433
+
480
434
  function toGuard(condition, guardMap) {
481
- if (!condition) {
482
- return undefined;
483
- }
484
- if (isString(condition)) {
485
- return {
486
- type: constants_1.DEFAULT_GUARD_TYPE,
487
- name: condition,
488
- predicate: guardMap ? guardMap[condition] : undefined
489
- };
490
- }
491
- if (isFunction(condition)) {
492
- return {
493
- type: constants_1.DEFAULT_GUARD_TYPE,
494
- name: condition.name,
495
- predicate: condition
496
- };
497
- }
498
- return condition;
435
+ if (!condition) {
436
+ return undefined;
437
+ }
438
+
439
+ if (isString(condition)) {
440
+ return {
441
+ type: constants.DEFAULT_GUARD_TYPE,
442
+ name: condition,
443
+ predicate: guardMap ? guardMap[condition] : undefined
444
+ };
445
+ }
446
+
447
+ if (isFunction(condition)) {
448
+ return {
449
+ type: constants.DEFAULT_GUARD_TYPE,
450
+ name: condition.name,
451
+ predicate: condition
452
+ };
453
+ }
454
+
455
+ return condition;
499
456
  }
500
- exports.toGuard = toGuard;
501
457
  function isObservable(value) {
502
- try {
503
- return 'subscribe' in value && isFunction(value.subscribe);
504
- }
505
- catch (e) {
506
- return false;
507
- }
458
+ try {
459
+ return 'subscribe' in value && isFunction(value.subscribe);
460
+ } catch (e) {
461
+ return false;
462
+ }
508
463
  }
509
- exports.isObservable = isObservable;
510
- exports.symbolObservable = (function () {
511
- return (typeof Symbol === 'function' && Symbol.observable) ||
512
- '@@observable';
513
- })();
464
+ var symbolObservable = /*#__PURE__*/function () {
465
+ return typeof Symbol === 'function' && Symbol.observable || '@@observable';
466
+ }();
514
467
  function isMachine(value) {
515
- try {
516
- return '__xstatenode' in value;
517
- }
518
- catch (e) {
519
- return false;
520
- }
468
+ try {
469
+ return '__xstatenode' in value;
470
+ } catch (e) {
471
+ return false;
472
+ }
521
473
  }
522
- exports.isMachine = isMachine;
523
474
  function isActor(value) {
524
- return !!value && typeof value.send === 'function';
525
- }
526
- exports.isActor = isActor;
527
- exports.uniqueId = (function () {
528
- var currentId = 0;
529
- return function () {
530
- currentId++;
531
- return currentId.toString(16);
532
- };
533
- })();
534
- function toEventObject(event, payload
535
- // id?: TEvent['type']
475
+ return !!value && typeof value.send === 'function';
476
+ }
477
+ var uniqueId = /*#__PURE__*/function () {
478
+ var currentId = 0;
479
+ return function () {
480
+ currentId++;
481
+ return currentId.toString(16);
482
+ };
483
+ }();
484
+ function toEventObject(event, payload // id?: TEvent['type']
536
485
  ) {
537
- if (isString(event) || typeof event === 'number') {
538
- return __assign({ type: event }, payload);
539
- }
540
- return event;
486
+ if (isString(event) || typeof event === 'number') {
487
+ return _tslib.__assign({
488
+ type: event
489
+ }, payload);
490
+ }
491
+
492
+ return event;
541
493
  }
542
- exports.toEventObject = toEventObject;
543
494
  function toSCXMLEvent(event, scxmlEvent) {
544
- if (!isString(event) && '$$type' in event && event.$$type === 'scxml') {
545
- return event;
546
- }
547
- var eventObject = toEventObject(event);
548
- return __assign({ name: eventObject.type, data: eventObject, $$type: 'scxml', type: 'external' }, scxmlEvent);
495
+ if (!isString(event) && '$$type' in event && event.$$type === 'scxml') {
496
+ return event;
497
+ }
498
+
499
+ var eventObject = toEventObject(event);
500
+ return _tslib.__assign({
501
+ name: eventObject.type,
502
+ data: eventObject,
503
+ $$type: 'scxml',
504
+ type: 'external'
505
+ }, scxmlEvent);
549
506
  }
550
- exports.toSCXMLEvent = toSCXMLEvent;
551
507
  function toTransitionConfigArray(event, configLike) {
552
- var transitions = toArrayStrict(configLike).map(function (transitionLike) {
553
- if (typeof transitionLike === 'undefined' ||
554
- typeof transitionLike === 'string' ||
555
- isMachine(transitionLike)) {
556
- return { target: transitionLike, event: event };
557
- }
558
- return __assign(__assign({}, transitionLike), { event: event });
508
+ var transitions = toArrayStrict(configLike).map(function (transitionLike) {
509
+ if (typeof transitionLike === 'undefined' || typeof transitionLike === 'string' || isMachine(transitionLike)) {
510
+ return {
511
+ target: transitionLike,
512
+ event: event
513
+ };
514
+ }
515
+
516
+ return _tslib.__assign(_tslib.__assign({}, transitionLike), {
517
+ event: event
559
518
  });
560
- return transitions;
519
+ });
520
+ return transitions;
561
521
  }
562
- exports.toTransitionConfigArray = toTransitionConfigArray;
563
522
  function normalizeTarget(target) {
564
- if (target === undefined || target === constants_1.TARGETLESS_KEY) {
565
- return undefined;
566
- }
567
- return toArray(target);
523
+ if (target === undefined || target === constants.TARGETLESS_KEY) {
524
+ return undefined;
525
+ }
526
+
527
+ return toArray(target);
568
528
  }
569
- exports.normalizeTarget = normalizeTarget;
570
529
  function reportUnhandledExceptionOnInvocation(originalError, currentError, id) {
571
- if (!environment_1.IS_PRODUCTION) {
572
- var originalStackTrace = originalError.stack
573
- ? " Stacktrace was '" + originalError.stack + "'"
574
- : '';
575
- if (originalError === currentError) {
576
- // tslint:disable-next-line:no-console
577
- console.error("Missing onError handler for invocation '" + id + "', error was '" + originalError + "'." + originalStackTrace);
578
- }
579
- else {
580
- var stackTrace = currentError.stack
581
- ? " Stacktrace was '" + currentError.stack + "'"
582
- : '';
583
- // tslint:disable-next-line:no-console
584
- console.error("Missing onError handler and/or unhandled exception/promise rejection for invocation '" + id + "'. " +
585
- ("Original error: '" + originalError + "'. " + originalStackTrace + " Current error is '" + currentError + "'." + stackTrace));
586
- }
587
- }
530
+ if (!environment.IS_PRODUCTION) {
531
+ var originalStackTrace = originalError.stack ? " Stacktrace was '" + originalError.stack + "'" : '';
532
+
533
+ if (originalError === currentError) {
534
+ // tslint:disable-next-line:no-console
535
+ console.error("Missing onError handler for invocation '" + id + "', error was '" + originalError + "'." + originalStackTrace);
536
+ } else {
537
+ var stackTrace = currentError.stack ? " Stacktrace was '" + currentError.stack + "'" : ''; // tslint:disable-next-line:no-console
538
+
539
+ console.error("Missing onError handler and/or unhandled exception/promise rejection for invocation '" + id + "'. " + ("Original error: '" + originalError + "'. " + originalStackTrace + " Current error is '" + currentError + "'." + stackTrace));
540
+ }
541
+ }
588
542
  }
589
- exports.reportUnhandledExceptionOnInvocation = reportUnhandledExceptionOnInvocation;
590
543
  function evaluateGuard(machine, guard, context, _event, state) {
591
- var guards = machine.options.guards;
592
- var guardMeta = {
593
- state: state,
594
- cond: guard,
595
- _event: _event
596
- };
597
- // TODO: do not hardcode!
598
- if (guard.type === constants_1.DEFAULT_GUARD_TYPE) {
599
- return guard.predicate(context, _event.data, guardMeta);
600
- }
601
- var condFn = guards[guard.type];
602
- if (!condFn) {
603
- throw new Error("Guard '" + guard.type + "' is not implemented on machine '" + machine.id + "'.");
604
- }
605
- return condFn(context, _event.data, guardMeta);
544
+ var guards = machine.options.guards;
545
+ var guardMeta = {
546
+ state: state,
547
+ cond: guard,
548
+ _event: _event
549
+ }; // TODO: do not hardcode!
550
+
551
+ if (guard.type === constants.DEFAULT_GUARD_TYPE) {
552
+ return guard.predicate(context, _event.data, guardMeta);
553
+ }
554
+
555
+ var condFn = guards[guard.type];
556
+
557
+ if (!condFn) {
558
+ throw new Error("Guard '" + guard.type + "' is not implemented on machine '" + machine.id + "'.");
559
+ }
560
+
561
+ return condFn(context, _event.data, guardMeta);
606
562
  }
607
- exports.evaluateGuard = evaluateGuard;
608
563
  function toInvokeSource(src) {
609
- if (typeof src === 'string') {
610
- return { type: src };
611
- }
612
- return src;
613
- }
614
- exports.toInvokeSource = toInvokeSource;
615
- function toObserver(nextHandler, errorHandler, completionHandler) {
616
- if (typeof nextHandler === 'object') {
617
- return nextHandler;
618
- }
619
- var noop = function () { return void 0; };
564
+ if (typeof src === 'string') {
620
565
  return {
621
- next: nextHandler,
622
- error: errorHandler || noop,
623
- complete: completionHandler || noop
566
+ type: src
624
567
  };
568
+ }
569
+
570
+ return src;
625
571
  }
572
+ function toObserver(nextHandler, errorHandler, completionHandler) {
573
+ if (typeof nextHandler === 'object') {
574
+ return nextHandler;
575
+ }
576
+
577
+ var noop = function () {
578
+ return void 0;
579
+ };
580
+
581
+ return {
582
+ next: nextHandler,
583
+ error: errorHandler || noop,
584
+ complete: completionHandler || noop
585
+ };
586
+ }
587
+
588
+ exports.evaluateGuard = evaluateGuard;
589
+ exports.flatten = flatten;
590
+ exports.getEventType = getEventType;
591
+ exports.isActor = isActor;
592
+ exports.isArray = isArray;
593
+ exports.isBehavior = isBehavior;
594
+ exports.isBuiltInEvent = isBuiltInEvent;
595
+ exports.isFunction = isFunction;
596
+ exports.isMachine = isMachine;
597
+ exports.isObservable = isObservable;
598
+ exports.isPromiseLike = isPromiseLike;
599
+ exports.isStateLike = isStateLike;
600
+ exports.isString = isString;
601
+ exports.keys = keys;
602
+ exports.mapContext = mapContext;
603
+ exports.mapFilterValues = mapFilterValues;
604
+ exports.mapValues = mapValues;
605
+ exports.matchesState = matchesState;
606
+ exports.nestedPath = nestedPath;
607
+ exports.normalizeTarget = normalizeTarget;
608
+ exports.partition = partition;
609
+ exports.path = path;
610
+ exports.pathToStateValue = pathToStateValue;
611
+ exports.reportUnhandledExceptionOnInvocation = reportUnhandledExceptionOnInvocation;
612
+ exports.symbolObservable = symbolObservable;
613
+ exports.toArray = toArray;
614
+ exports.toArrayStrict = toArrayStrict;
615
+ exports.toEventObject = toEventObject;
616
+ exports.toGuard = toGuard;
617
+ exports.toInvokeSource = toInvokeSource;
626
618
  exports.toObserver = toObserver;
619
+ exports.toSCXMLEvent = toSCXMLEvent;
620
+ exports.toStatePath = toStatePath;
621
+ exports.toStatePaths = toStatePaths;
622
+ exports.toStateValue = toStateValue;
623
+ exports.toTransitionConfigArray = toTransitionConfigArray;
624
+ exports.uniqueId = uniqueId;
625
+ exports.updateContext = updateContext;
626
+ exports.updateHistoryStates = updateHistoryStates;
627
+ exports.updateHistoryValue = updateHistoryValue;