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