xstate 4.22.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.
Files changed (88) hide show
  1. package/CHANGELOG.md +58 -4
  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 +1 -6
  6. package/es/Machine.d.ts +3 -3
  7. package/es/Machine.js +1 -2
  8. package/es/State.js +1 -3
  9. package/es/StateNode.js +3 -2
  10. package/es/_virtual/_tslib.js +59 -73
  11. package/es/actionTypes.js +3 -2
  12. package/es/actions.d.ts +1 -1
  13. package/es/actions.js +51 -37
  14. package/es/behaviors.js +4 -2
  15. package/es/constants.js +2 -1
  16. package/es/devTools.js +1 -1
  17. package/es/environment.js +2 -1
  18. package/es/index.js +3 -1
  19. package/es/interpreter.d.ts +8 -2
  20. package/es/interpreter.js +8 -6
  21. package/es/invokeUtils.js +4 -3
  22. package/es/mapState.js +1 -1
  23. package/es/match.js +1 -1
  24. package/es/model.d.ts +2 -37
  25. package/es/model.types.d.ts +37 -0
  26. package/es/registry.js +2 -1
  27. package/es/scheduler.js +2 -1
  28. package/es/schema.js +1 -1
  29. package/es/serviceScope.js +1 -3
  30. package/es/stateUtils.js +1 -9
  31. package/es/types.d.ts +12 -2
  32. package/es/types.js +1 -1
  33. package/es/utils.js +1 -41
  34. package/lib/Actor.d.ts +25 -25
  35. package/lib/Actor.js +85 -66
  36. package/lib/Machine.d.ts +17 -17
  37. package/lib/Machine.js +14 -8
  38. package/lib/SimulatedClock.d.ts +16 -16
  39. package/lib/State.d.ts +108 -108
  40. package/lib/State.js +246 -236
  41. package/lib/StateNode.d.ts +279 -279
  42. package/lib/StateNode.js +1535 -1357
  43. package/lib/_virtual/_tslib.js +81 -0
  44. package/lib/actionTypes.d.ts +19 -19
  45. package/lib/actionTypes.js +43 -23
  46. package/lib/actions.d.ts +138 -138
  47. package/lib/actions.js +465 -387
  48. package/lib/behaviors.d.ts +36 -36
  49. package/lib/behaviors.js +65 -106
  50. package/lib/constants.d.ts +5 -5
  51. package/lib/constants.js +13 -7
  52. package/lib/devTools.d.ts +15 -15
  53. package/lib/devTools.js +37 -26
  54. package/lib/each.d.ts +3 -3
  55. package/lib/environment.d.ts +1 -1
  56. package/lib/environment.js +7 -4
  57. package/lib/index.d.ts +30 -30
  58. package/lib/index.js +67 -57
  59. package/lib/interpreter.d.ts +205 -199
  60. package/lib/interpreter.js +1306 -1060
  61. package/lib/invoke.d.ts +10 -10
  62. package/lib/invokeUtils.d.ts +6 -6
  63. package/lib/invokeUtils.js +40 -37
  64. package/lib/json.d.ts +30 -30
  65. package/lib/mapState.d.ts +3 -3
  66. package/lib/mapState.js +31 -32
  67. package/lib/match.d.ts +8 -8
  68. package/lib/match.js +33 -47
  69. package/lib/model.d.ts +4 -39
  70. package/lib/model.types.d.ts +37 -0
  71. package/lib/model.types.js +2 -0
  72. package/lib/patterns.d.ts +13 -13
  73. package/lib/registry.d.ts +8 -8
  74. package/lib/registry.js +21 -18
  75. package/lib/scheduler.d.ts +16 -16
  76. package/lib/scheduler.js +79 -70
  77. package/lib/schema.d.ts +1 -1
  78. package/lib/schema.js +6 -4
  79. package/lib/scxml.d.ts +5 -5
  80. package/lib/serviceScope.d.ts +3 -3
  81. package/lib/serviceScope.js +16 -12
  82. package/lib/stateUtils.d.ts +14 -14
  83. package/lib/stateUtils.js +231 -199
  84. package/lib/types.d.ts +928 -918
  85. package/lib/types.js +29 -29
  86. package/lib/utils.d.ts +68 -68
  87. package/lib/utils.js +528 -534
  88. package/package.json +5 -5
package/lib/utils.js CHANGED
@@ -1,479 +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.isBehavior = 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
- }
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
+ }
84
47
  }
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
- }
97
- }
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
- }
130
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
131
+ } finally {
132
+ if (e_1) throw e_1.error;
173
133
  }
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; }
180
- }
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
- }
320
- }
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; }
267
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
268
+ } finally {
269
+ if (e_5) throw e_5.error;
327
270
  }
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;
346
289
  }
347
- exports.isPromiseLike = isPromiseLike;
348
290
  function isBehavior(value) {
349
- return (value !== null &&
350
- typeof value === 'object' &&
351
- 'transition' in value &&
352
- typeof value.transition === 'function');
291
+ return value !== null && typeof value === 'object' && 'transition' in value && typeof value.transition === 'function';
353
292
  }
354
- exports.isBehavior = isBehavior;
355
293
  function partition(items, predicate) {
356
- var e_6, _a;
357
- 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 {
358
315
  try {
359
- for (var items_1 = __values(items), items_1_1 = items_1.next(); !items_1_1.done; items_1_1 = items_1.next()) {
360
- var item = items_1_1.value;
361
- if (predicate(item)) {
362
- truthy.push(item);
363
- }
364
- else {
365
- falsy.push(item);
366
- }
367
- }
368
- }
369
- catch (e_6_1) { e_6 = { error: e_6_1 }; }
370
- finally {
371
- try {
372
- if (items_1_1 && !items_1_1.done && (_a = items_1.return)) _a.call(items_1);
373
- }
374
- 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;
375
319
  }
376
- return [truthy, falsy];
320
+ }
321
+
322
+ return [truthy, falsy];
377
323
  }
378
- exports.partition = partition;
379
324
  function updateHistoryStates(hist, stateValue) {
380
- return mapValues(hist.states, function (subHist, key) {
381
- if (!subHist) {
382
- return undefined;
383
- }
384
- var subStateValue = (isString(stateValue) ? undefined : stateValue[key]) ||
385
- (subHist ? subHist.current : undefined);
386
- if (!subStateValue) {
387
- return undefined;
388
- }
389
- return {
390
- current: subStateValue,
391
- states: updateHistoryStates(subHist, subStateValue)
392
- };
393
- });
394
- }
395
- exports.updateHistoryStates = updateHistoryStates;
396
- 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
+
397
336
  return {
398
- current: stateValue,
399
- states: updateHistoryStates(hist, stateValue)
337
+ current: subStateValue,
338
+ states: updateHistoryStates(subHist, subStateValue)
400
339
  };
340
+ });
401
341
  }
402
- exports.updateHistoryValue = updateHistoryValue;
403
- function updateContext(context, _event, assignActions, state) {
404
- if (!environment_1.IS_PRODUCTION) {
405
- warn(!!context, 'Attempting to update undefined context');
406
- }
407
- var updatedContext = context
408
- ? assignActions.reduce(function (acc, assignAction) {
409
- var e_7, _a;
410
- var assignment = assignAction.assignment;
411
- var meta = {
412
- state: state,
413
- action: assignAction,
414
- _event: _event
415
- };
416
- var partialUpdate = {};
417
- if (isFunction(assignment)) {
418
- partialUpdate = assignment(acc, _event.data, meta);
419
- }
420
- else {
421
- try {
422
- for (var _b = __values(keys(assignment)), _c = _b.next(); !_c.done; _c = _b.next()) {
423
- var key = _c.value;
424
- var propAssignment = assignment[key];
425
- partialUpdate[key] = isFunction(propAssignment)
426
- ? propAssignment(acc, _event.data, meta)
427
- : propAssignment;
428
- }
429
- }
430
- catch (e_7_1) { e_7 = { error: e_7_1 }; }
431
- finally {
432
- try {
433
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
434
- }
435
- finally { if (e_7) throw e_7.error; }
436
- }
437
- }
438
- return Object.assign({}, acc, partialUpdate);
439
- }, context)
440
- : context;
441
- return updatedContext;
342
+ function updateHistoryValue(hist, stateValue) {
343
+ return {
344
+ current: stateValue,
345
+ states: updateHistoryStates(hist, stateValue)
346
+ };
442
347
  }
443
- exports.updateContext = updateContext;
444
- // tslint:disable-next-line:no-empty
445
- var warn = function () { };
446
- exports.warn = warn;
447
- if (!environment_1.IS_PRODUCTION) {
448
- exports.warn = warn = function (condition, message) {
449
- var error = condition instanceof Error ? condition : undefined;
450
- if (!error && condition) {
451
- 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;
452
372
  }
453
- if (console !== undefined) {
454
- var args = ["Warning: " + message];
455
- if (error) {
456
- args.push(error);
457
- }
458
- // tslint:disable-next-line:no-console
459
- 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;
460
382
  }
461
- };
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
+ };
462
412
  }
463
413
  function isArray(value) {
464
- return Array.isArray(value);
465
- }
466
- exports.isArray = isArray;
467
- // tslint:disable-next-line:ban-types
414
+ return Array.isArray(value);
415
+ } // tslint:disable-next-line:ban-types
416
+
468
417
  function isFunction(value) {
469
- return typeof value === 'function';
418
+ return typeof value === 'function';
470
419
  }
471
- exports.isFunction = isFunction;
472
420
  function isString(value) {
473
- return typeof value === 'string';
474
- }
475
- exports.isString = isString;
476
- // export function memoizedGetter<T, TP extends { prototype: object }>(
421
+ return typeof value === 'string';
422
+ } // export function memoizedGetter<T, TP extends { prototype: object }>(
477
423
  // o: TP,
478
424
  // property: string,
479
425
  // getter: () => T
@@ -484,150 +430,198 @@ exports.isString = isString;
484
430
  // configurable: false
485
431
  // });
486
432
  // }
433
+
487
434
  function toGuard(condition, guardMap) {
488
- if (!condition) {
489
- return undefined;
490
- }
491
- if (isString(condition)) {
492
- return {
493
- type: constants_1.DEFAULT_GUARD_TYPE,
494
- name: condition,
495
- predicate: guardMap ? guardMap[condition] : undefined
496
- };
497
- }
498
- if (isFunction(condition)) {
499
- return {
500
- type: constants_1.DEFAULT_GUARD_TYPE,
501
- name: condition.name,
502
- predicate: condition
503
- };
504
- }
505
- 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;
506
456
  }
507
- exports.toGuard = toGuard;
508
457
  function isObservable(value) {
509
- try {
510
- return 'subscribe' in value && isFunction(value.subscribe);
511
- }
512
- catch (e) {
513
- return false;
514
- }
458
+ try {
459
+ return 'subscribe' in value && isFunction(value.subscribe);
460
+ } catch (e) {
461
+ return false;
462
+ }
515
463
  }
516
- exports.isObservable = isObservable;
517
- exports.symbolObservable = (function () {
518
- return (typeof Symbol === 'function' && Symbol.observable) ||
519
- '@@observable';
520
- })();
464
+ var symbolObservable = /*#__PURE__*/function () {
465
+ return typeof Symbol === 'function' && Symbol.observable || '@@observable';
466
+ }();
521
467
  function isMachine(value) {
522
- try {
523
- return '__xstatenode' in value;
524
- }
525
- catch (e) {
526
- return false;
527
- }
468
+ try {
469
+ return '__xstatenode' in value;
470
+ } catch (e) {
471
+ return false;
472
+ }
528
473
  }
529
- exports.isMachine = isMachine;
530
474
  function isActor(value) {
531
- return !!value && typeof value.send === 'function';
532
- }
533
- exports.isActor = isActor;
534
- exports.uniqueId = (function () {
535
- var currentId = 0;
536
- return function () {
537
- currentId++;
538
- return currentId.toString(16);
539
- };
540
- })();
541
- function toEventObject(event, payload
542
- // 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']
543
485
  ) {
544
- if (isString(event) || typeof event === 'number') {
545
- return __assign({ type: event }, payload);
546
- }
547
- return event;
486
+ if (isString(event) || typeof event === 'number') {
487
+ return _tslib.__assign({
488
+ type: event
489
+ }, payload);
490
+ }
491
+
492
+ return event;
548
493
  }
549
- exports.toEventObject = toEventObject;
550
494
  function toSCXMLEvent(event, scxmlEvent) {
551
- if (!isString(event) && '$$type' in event && event.$$type === 'scxml') {
552
- return event;
553
- }
554
- var eventObject = toEventObject(event);
555
- 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);
556
506
  }
557
- exports.toSCXMLEvent = toSCXMLEvent;
558
507
  function toTransitionConfigArray(event, configLike) {
559
- var transitions = toArrayStrict(configLike).map(function (transitionLike) {
560
- if (typeof transitionLike === 'undefined' ||
561
- typeof transitionLike === 'string' ||
562
- isMachine(transitionLike)) {
563
- return { target: transitionLike, event: event };
564
- }
565
- 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
566
518
  });
567
- return transitions;
519
+ });
520
+ return transitions;
568
521
  }
569
- exports.toTransitionConfigArray = toTransitionConfigArray;
570
522
  function normalizeTarget(target) {
571
- if (target === undefined || target === constants_1.TARGETLESS_KEY) {
572
- return undefined;
573
- }
574
- return toArray(target);
523
+ if (target === undefined || target === constants.TARGETLESS_KEY) {
524
+ return undefined;
525
+ }
526
+
527
+ return toArray(target);
575
528
  }
576
- exports.normalizeTarget = normalizeTarget;
577
529
  function reportUnhandledExceptionOnInvocation(originalError, currentError, id) {
578
- if (!environment_1.IS_PRODUCTION) {
579
- var originalStackTrace = originalError.stack
580
- ? " Stacktrace was '" + originalError.stack + "'"
581
- : '';
582
- if (originalError === currentError) {
583
- // tslint:disable-next-line:no-console
584
- console.error("Missing onError handler for invocation '" + id + "', error was '" + originalError + "'." + originalStackTrace);
585
- }
586
- else {
587
- var stackTrace = currentError.stack
588
- ? " Stacktrace was '" + currentError.stack + "'"
589
- : '';
590
- // tslint:disable-next-line:no-console
591
- console.error("Missing onError handler and/or unhandled exception/promise rejection for invocation '" + id + "'. " +
592
- ("Original error: '" + originalError + "'. " + originalStackTrace + " Current error is '" + currentError + "'." + stackTrace));
593
- }
594
- }
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
+ }
595
542
  }
596
- exports.reportUnhandledExceptionOnInvocation = reportUnhandledExceptionOnInvocation;
597
543
  function evaluateGuard(machine, guard, context, _event, state) {
598
- var guards = machine.options.guards;
599
- var guardMeta = {
600
- state: state,
601
- cond: guard,
602
- _event: _event
603
- };
604
- // TODO: do not hardcode!
605
- if (guard.type === constants_1.DEFAULT_GUARD_TYPE) {
606
- return guard.predicate(context, _event.data, guardMeta);
607
- }
608
- var condFn = guards[guard.type];
609
- if (!condFn) {
610
- throw new Error("Guard '" + guard.type + "' is not implemented on machine '" + machine.id + "'.");
611
- }
612
- 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);
613
562
  }
614
- exports.evaluateGuard = evaluateGuard;
615
563
  function toInvokeSource(src) {
616
- if (typeof src === 'string') {
617
- return { type: src };
618
- }
619
- return src;
620
- }
621
- exports.toInvokeSource = toInvokeSource;
622
- function toObserver(nextHandler, errorHandler, completionHandler) {
623
- if (typeof nextHandler === 'object') {
624
- return nextHandler;
625
- }
626
- var noop = function () { return void 0; };
564
+ if (typeof src === 'string') {
627
565
  return {
628
- next: nextHandler,
629
- error: errorHandler || noop,
630
- complete: completionHandler || noop
566
+ type: src
631
567
  };
568
+ }
569
+
570
+ return src;
632
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;
633
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;