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