xstate 5.0.0-beta.27 → 5.0.0-beta.29

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 (67) hide show
  1. package/README.md +9 -7
  2. package/actions/dist/xstate-actions.cjs.js +11 -17
  3. package/actions/dist/xstate-actions.cjs.mjs +0 -8
  4. package/actions/dist/xstate-actions.development.cjs.js +11 -17
  5. package/actions/dist/xstate-actions.development.cjs.mjs +0 -8
  6. package/actions/dist/xstate-actions.development.esm.js +3 -1
  7. package/actions/dist/xstate-actions.esm.js +3 -1
  8. package/actions/dist/xstate-actions.umd.min.js +1 -1
  9. package/actions/dist/xstate-actions.umd.min.js.map +1 -1
  10. package/actors/dist/xstate-actors.cjs.js +395 -28
  11. package/actors/dist/xstate-actors.cjs.mjs +1 -3
  12. package/actors/dist/xstate-actors.development.cjs.js +395 -28
  13. package/actors/dist/xstate-actors.development.cjs.mjs +1 -3
  14. package/actors/dist/xstate-actors.development.esm.js +389 -21
  15. package/actors/dist/xstate-actors.esm.js +389 -21
  16. package/actors/dist/xstate-actors.umd.min.js +1 -1
  17. package/actors/dist/xstate-actors.umd.min.js.map +1 -1
  18. package/dist/declarations/src/StateNode.d.ts +3 -3
  19. package/dist/declarations/src/actions/assign.d.ts +9 -4
  20. package/dist/declarations/src/actions/cancel.d.ts +4 -4
  21. package/dist/declarations/src/actions/choose.d.ts +5 -4
  22. package/dist/declarations/src/actions/log.d.ts +4 -4
  23. package/dist/declarations/src/actions/pure.d.ts +6 -5
  24. package/dist/declarations/src/actions/raise.d.ts +2 -2
  25. package/dist/declarations/src/actions/send.d.ts +7 -7
  26. package/dist/declarations/src/actions/stop.d.ts +4 -4
  27. package/dist/declarations/src/actions.d.ts +8 -44
  28. package/dist/declarations/src/actors/callback.d.ts +2 -2
  29. package/dist/declarations/src/actors/index.d.ts +3 -5
  30. package/dist/declarations/src/constants.d.ts +1 -0
  31. package/dist/declarations/src/index.d.ts +9 -16
  32. package/dist/declarations/src/spawn.d.ts +25 -0
  33. package/dist/declarations/src/stateUtils.d.ts +1 -1
  34. package/dist/declarations/src/typegenTypes.d.ts +4 -4
  35. package/dist/declarations/src/types.d.ts +92 -122
  36. package/dist/declarations/src/utils.d.ts +2 -2
  37. package/dist/interpreter-498891b2.esm.js +741 -0
  38. package/dist/interpreter-6e7909c8.development.esm.js +749 -0
  39. package/dist/interpreter-c357bc50.cjs.js +773 -0
  40. package/dist/interpreter-e2c6a579.development.cjs.js +781 -0
  41. package/dist/{actions-9754d2ca.development.esm.js → raise-03e57569.cjs.js} +130 -1307
  42. package/dist/{actions-d1dba4ac.cjs.js → raise-59f2c242.esm.js} +65 -1267
  43. package/dist/{actions-020463e9.esm.js → raise-e778a828.development.esm.js} +109 -1203
  44. package/dist/{actions-ca622922.development.cjs.js → raise-f751dfac.development.cjs.js} +101 -1306
  45. package/dist/send-42c83fb2.development.esm.js +364 -0
  46. package/dist/send-51717e53.cjs.js +349 -0
  47. package/dist/send-f53778f6.development.cjs.js +374 -0
  48. package/dist/send-fff224db.esm.js +339 -0
  49. package/dist/xstate.cjs.js +114 -112
  50. package/dist/xstate.cjs.mjs +2 -2
  51. package/dist/xstate.development.cjs.js +114 -112
  52. package/dist/xstate.development.cjs.mjs +2 -2
  53. package/dist/xstate.development.esm.js +78 -74
  54. package/dist/xstate.esm.js +78 -74
  55. package/dist/xstate.umd.min.js +1 -1
  56. package/dist/xstate.umd.min.js.map +1 -1
  57. package/guards/dist/xstate-guards.cjs.js +2 -1
  58. package/guards/dist/xstate-guards.development.cjs.js +2 -1
  59. package/guards/dist/xstate-guards.development.esm.js +2 -1
  60. package/guards/dist/xstate-guards.esm.js +2 -1
  61. package/guards/dist/xstate-guards.umd.min.js.map +1 -1
  62. package/package.json +1 -1
  63. package/dist/declarations/src/constantPrefixes.d.ts +0 -6
  64. package/dist/promise-2ad94e3b.development.esm.js +0 -406
  65. package/dist/promise-3b7e3357.development.cjs.js +0 -412
  66. package/dist/promise-5b07c38e.esm.js +0 -406
  67. package/dist/promise-7a8c1768.cjs.js +0 -412
@@ -1,198 +1,4 @@
1
- 'use strict';
2
-
3
- var dev_dist_xstateDev = require('../dev/dist/xstate-dev.cjs.js');
4
-
5
- /**
6
- * `T | unknown` reduces to `unknown` and that can be problematic when it comes to contextual typing.
7
- * It especially is a problem when the union has a function member, like here:
8
- *
9
- * ```ts
10
- * declare function test(cbOrVal: ((arg: number) => unknown) | unknown): void;
11
- * test((arg) => {}) // oops, implicit any
12
- * ```
13
- *
14
- * This type can be used to avoid this problem. This union represents the same value space as `unknown`.
15
- */
16
-
17
- // https://github.com/microsoft/TypeScript/issues/23182#issuecomment-379091887
18
-
19
- /**
20
- * The full definition of an event, with a string `type`.
21
- */
22
-
23
- // TODO: do not accept machines without all implementations
24
- // we should also accept a raw machine as actor logic here
25
- // or just make machine actor logic
26
-
27
- /**
28
- * The string or object representing the state value relative to the parent state node.
29
- *
30
- * - For a child atomic state node, this is a string, e.g., `"pending"`.
31
- * - For complex state nodes, this is an object, e.g., `{ success: "someChildState" }`.
32
- */
33
-
34
- // TODO: remove once TS fixes this type-widening issue
35
-
36
- // TODO: possibly refactor this somehow, use even a simpler type, and maybe even make `machine.options` private or something
37
-
38
- let ConstantPrefix = /*#__PURE__*/function (ConstantPrefix) {
39
- ConstantPrefix["After"] = "xstate.after";
40
- ConstantPrefix["DoneState"] = "done.state";
41
- ConstantPrefix["DoneInvoke"] = "done.invoke";
42
- ConstantPrefix["ErrorExecution"] = "error.execution";
43
- ConstantPrefix["ErrorCommunication"] = "error.communication";
44
- ConstantPrefix["ErrorPlatform"] = "error.platform";
45
- ConstantPrefix["ErrorCustom"] = "xstate.error";
46
- return ConstantPrefix;
47
- }({});
48
- let SpecialTargets = /*#__PURE__*/function (SpecialTargets) {
49
- SpecialTargets["Parent"] = "#_parent";
50
- SpecialTargets["Internal"] = "#_internal";
51
- return SpecialTargets;
52
- }({});
53
-
54
- const after$1 = ConstantPrefix.After;
55
- const doneState = ConstantPrefix.DoneState;
56
- const errorExecution = ConstantPrefix.ErrorExecution;
57
- const errorPlatform = ConstantPrefix.ErrorPlatform;
58
- const error$1 = ConstantPrefix.ErrorCustom;
59
-
60
- var constantPrefixes = /*#__PURE__*/Object.freeze({
61
- __proto__: null,
62
- after: after$1,
63
- doneState: doneState,
64
- errorExecution: errorExecution,
65
- errorPlatform: errorPlatform,
66
- error: error$1
67
- });
68
-
69
- const STATE_DELIMITER = '.';
70
- const TARGETLESS_KEY = '';
71
- const NULL_EVENT = '';
72
- const STATE_IDENTIFIER = '#';
73
- const WILDCARD = '*';
74
- const XSTATE_INIT = 'xstate.init';
75
- const XSTATE_STOP = 'xstate.stop';
76
-
77
- function resolve$8(actorContext, state, args, {
78
- to,
79
- event: eventOrExpr,
80
- id,
81
- delay
82
- }) {
83
- const delaysMap = state.machine.implementations.delays;
84
- if (typeof eventOrExpr === 'string') {
85
- throw new Error(`Only event objects may be used with sendTo; use sendTo({ type: "${eventOrExpr}" }) instead`);
86
- }
87
- const resolvedEvent = typeof eventOrExpr === 'function' ? eventOrExpr(args) : eventOrExpr;
88
- let resolvedDelay;
89
- if (typeof delay === 'string') {
90
- const configDelay = delaysMap && delaysMap[delay];
91
- resolvedDelay = typeof configDelay === 'function' ? configDelay(args) : configDelay;
92
- } else {
93
- resolvedDelay = typeof delay === 'function' ? delay(args) : delay;
94
- }
95
- const resolvedTarget = typeof to === 'function' ? to(args) : to;
96
- let targetActorRef;
97
- if (typeof resolvedTarget === 'string') {
98
- if (resolvedTarget === SpecialTargets.Parent) {
99
- targetActorRef = actorContext?.self._parent;
100
- } else if (resolvedTarget === SpecialTargets.Internal) {
101
- targetActorRef = actorContext?.self;
102
- } else if (resolvedTarget.startsWith('#_')) {
103
- // SCXML compatibility: https://www.w3.org/TR/scxml/#SCXMLEventProcessor
104
- // #_invokeid. If the target is the special term '#_invokeid', where invokeid is the invokeid of an SCXML session that the sending session has created by <invoke>, the Processor must add the event to the external queue of that session.
105
- targetActorRef = state.children[resolvedTarget.slice(2)];
106
- } else {
107
- targetActorRef = state.children[resolvedTarget];
108
- }
109
- if (!targetActorRef) {
110
- throw new Error(`Unable to send event to actor '${resolvedTarget}' from machine '${state.machine.id}'.`);
111
- }
112
- } else {
113
- targetActorRef = resolvedTarget || actorContext?.self;
114
- }
115
- return [state, {
116
- to: targetActorRef,
117
- event: resolvedEvent,
118
- id,
119
- delay: resolvedDelay
120
- }];
121
- }
122
- function execute$5(actorContext, params) {
123
- if (typeof params.delay === 'number') {
124
- actorContext.self.delaySend(params);
125
- return;
126
- }
127
- const {
128
- to,
129
- event
130
- } = params;
131
- actorContext.defer(() => {
132
- to.send(event.type === error$1 ? {
133
- type: `${error(actorContext.self.id)}`,
134
- data: event.data
135
- } : event);
136
- });
137
- }
138
- /**
139
- * Sends an event to an actor.
140
- *
141
- * @param actor The `ActorRef` to send the event to.
142
- * @param event The event to send, or an expression that evaluates to the event to send
143
- * @param options Send action options
144
- * - `id` - The unique send event identifier (used with `cancel()`).
145
- * - `delay` - The number of milliseconds to delay the sending of the event.
146
- */
147
- function sendTo(to, eventOrExpr, options) {
148
- function sendTo(_) {
149
- }
150
- sendTo.type = 'xstate.sendTo';
151
- sendTo.to = to;
152
- sendTo.event = eventOrExpr;
153
- sendTo.id = options?.id;
154
- sendTo.delay = options?.delay;
155
- sendTo.resolve = resolve$8;
156
- sendTo.execute = execute$5;
157
- return sendTo;
158
- }
159
-
160
- /**
161
- * Sends an event to this machine's parent.
162
- *
163
- * @param event The event to send to the parent machine.
164
- * @param options Options to pass into the send event.
165
- */
166
- function sendParent(event, options) {
167
- return sendTo(SpecialTargets.Parent, event, options);
168
- }
169
- /**
170
- * Forwards (sends) an event to a specified service.
171
- *
172
- * @param target The target service to forward the event to.
173
- * @param options Options to pass into the send action creator.
174
- */
175
- function forwardTo(target, options) {
176
- return sendTo(target, ({
177
- event
178
- }) => event, options);
179
- }
180
-
181
- /**
182
- * Escalates an error by sending it as an event to this machine's parent.
183
- *
184
- * @param errorData The error data to send, or the expression function that
185
- * takes in the `context`, `event`, and `meta`, and returns the error data to send.
186
- * @param options Options to pass into the send action creator.
187
- */
188
- function escalate(errorData, options) {
189
- return sendParent(arg => {
190
- return {
191
- type: error$1,
192
- data: typeof errorData === 'function' ? errorData(arg) : errorData
193
- };
194
- }, options);
195
- }
1
+ import { r as resolveReferencedActor, d as createActor, f as ActorStatus, k as createErrorActorEvent, l as toStateValue, n as STATE_IDENTIFIER, o as normalizeTarget, t as toArray, N as NULL_EVENT, a as toTransitionConfigArray, S as STATE_DELIMITER, q as toStatePath, s as createDoneStateEvent, u as mapContext, j as XSTATE_STOP, X as XSTATE_INIT, W as WILDCARD, v as isArray, w as createAfterEvent, x as flatten, e as matchesState } from './interpreter-498891b2.esm.js';
196
2
 
197
3
  const cache = new WeakMap();
198
4
  function memo(object, key, fn) {
@@ -208,13 +14,13 @@ function memo(object, key, fn) {
208
14
  return memoizedData[key];
209
15
  }
210
16
 
211
- function resolve$7(_, state, actionArgs, {
17
+ function resolve$3(_, state, actionArgs, {
212
18
  sendId
213
19
  }) {
214
20
  const resolvedSendId = typeof sendId === 'function' ? sendId(actionArgs) : sendId;
215
21
  return [state, resolvedSendId];
216
22
  }
217
- function execute$4(actorContext, resolvedSendId) {
23
+ function execute$3(actorContext, resolvedSendId) {
218
24
  actorContext.self.cancel(resolvedSendId);
219
25
  }
220
26
  /**
@@ -229,701 +35,12 @@ function cancel(sendId) {
229
35
  }
230
36
  cancel.type = 'xstate.cancel';
231
37
  cancel.sendId = sendId;
232
- cancel.resolve = resolve$7;
233
- cancel.execute = execute$4;
38
+ cancel.resolve = resolve$3;
39
+ cancel.execute = execute$3;
234
40
  return cancel;
235
41
  }
236
42
 
237
- class Mailbox {
238
- constructor(_process) {
239
- this._process = _process;
240
- this._active = false;
241
- this._current = null;
242
- this._last = null;
243
- }
244
- start() {
245
- this._active = true;
246
- this.flush();
247
- }
248
- clear() {
249
- // we can't set _current to null because we might be currently processing
250
- // and enqueue following clear shouldnt start processing the enqueued item immediately
251
- if (this._current) {
252
- this._current.next = null;
253
- this._last = this._current;
254
- }
255
- }
256
-
257
- // TODO: rethink this design
258
- prepend(event) {
259
- if (!this._current) {
260
- this.enqueue(event);
261
- return;
262
- }
263
-
264
- // we know that something is already queued up
265
- // so the mailbox is already flushing or it's inactive
266
- // therefore the only thing that we need to do is to reassign `this._current`
267
- this._current = {
268
- value: event,
269
- next: this._current
270
- };
271
- }
272
- enqueue(event) {
273
- const enqueued = {
274
- value: event,
275
- next: null
276
- };
277
- if (this._current) {
278
- this._last.next = enqueued;
279
- this._last = enqueued;
280
- return;
281
- }
282
- this._current = enqueued;
283
- this._last = enqueued;
284
- if (this._active) {
285
- this.flush();
286
- }
287
- }
288
- flush() {
289
- while (this._current) {
290
- // atm the given _process is responsible for implementing proper try/catch handling
291
- // we assume here that this won't throw in a way that can affect this mailbox
292
- const consumed = this._current;
293
- this._process(consumed.value);
294
- // something could have been prepended in the meantime
295
- // so we need to be defensive here to avoid skipping over a prepended item
296
- if (consumed === this._current) {
297
- this._current = this._current.next;
298
- }
299
- }
300
- this._last = null;
301
- }
302
- }
303
-
304
- /**
305
- * This function makes sure that unhandled errors are thrown in a separate macrotask.
306
- * It allows those errors to be detected by global error handlers and reported to bug tracking services
307
- * without interrupting our own stack of execution.
308
- *
309
- * @param err error to be thrown
310
- */
311
- function reportUnhandledError(err) {
312
- setTimeout(() => {
313
- throw err;
314
- });
315
- }
316
-
317
- const symbolObservable = (() => typeof Symbol === 'function' && Symbol.observable || '@@observable')();
318
-
319
- function createSystem() {
320
- let sessionIdCounter = 0;
321
- const children = new Map();
322
- const keyedActors = new Map();
323
- const reverseKeyedActors = new WeakMap();
324
- const system = {
325
- _bookId: () => `x:${sessionIdCounter++}`,
326
- _register: (sessionId, actorRef) => {
327
- children.set(sessionId, actorRef);
328
- return sessionId;
329
- },
330
- _unregister: actorRef => {
331
- children.delete(actorRef.sessionId);
332
- const systemId = reverseKeyedActors.get(actorRef);
333
- if (systemId !== undefined) {
334
- keyedActors.delete(systemId);
335
- reverseKeyedActors.delete(actorRef);
336
- }
337
- },
338
- get: systemId => {
339
- return keyedActors.get(systemId);
340
- },
341
- _set: (systemId, actorRef) => {
342
- const existing = keyedActors.get(systemId);
343
- if (existing && existing !== actorRef) {
344
- throw new Error(`Actor with system ID '${systemId}' already exists.`);
345
- }
346
- keyedActors.set(systemId, actorRef);
347
- reverseKeyedActors.set(actorRef, systemId);
348
- }
349
- };
350
- return system;
351
- }
352
-
353
- function matchesState(parentStateId, childStateId) {
354
- const parentStateValue = toStateValue(parentStateId);
355
- const childStateValue = toStateValue(childStateId);
356
- if (typeof childStateValue === 'string') {
357
- if (typeof parentStateValue === 'string') {
358
- return childStateValue === parentStateValue;
359
- }
360
-
361
- // Parent more specific than child
362
- return false;
363
- }
364
- if (typeof parentStateValue === 'string') {
365
- return parentStateValue in childStateValue;
366
- }
367
- return Object.keys(parentStateValue).every(key => {
368
- if (!(key in childStateValue)) {
369
- return false;
370
- }
371
- return matchesState(parentStateValue[key], childStateValue[key]);
372
- });
373
- }
374
- function toStatePath(stateId) {
375
- try {
376
- if (isArray(stateId)) {
377
- return stateId;
378
- }
379
- return stateId.toString().split(STATE_DELIMITER);
380
- } catch (e) {
381
- throw new Error(`'${stateId}' is not a valid state path.`);
382
- }
383
- }
384
- function isStateLike(state) {
385
- return typeof state === 'object' && 'value' in state && 'context' in state && 'event' in state;
386
- }
387
- function toStateValue(stateValue) {
388
- if (isStateLike(stateValue)) {
389
- return stateValue.value;
390
- }
391
- if (isArray(stateValue)) {
392
- return pathToStateValue(stateValue);
393
- }
394
- if (typeof stateValue !== 'string') {
395
- return stateValue;
396
- }
397
- const statePath = toStatePath(stateValue);
398
- return pathToStateValue(statePath);
399
- }
400
- function pathToStateValue(statePath) {
401
- if (statePath.length === 1) {
402
- return statePath[0];
403
- }
404
- const value = {};
405
- let marker = value;
406
- for (let i = 0; i < statePath.length - 1; i++) {
407
- if (i === statePath.length - 2) {
408
- marker[statePath[i]] = statePath[i + 1];
409
- } else {
410
- const previous = marker;
411
- marker = {};
412
- previous[statePath[i]] = marker;
413
- }
414
- }
415
- return value;
416
- }
417
- function mapValues(collection, iteratee) {
418
- const result = {};
419
- const collectionKeys = Object.keys(collection);
420
- for (let i = 0; i < collectionKeys.length; i++) {
421
- const key = collectionKeys[i];
422
- result[key] = iteratee(collection[key], key, collection, i);
423
- }
424
- return result;
425
- }
426
- function flatten(array) {
427
- return [].concat(...array);
428
- }
429
- function toArrayStrict(value) {
430
- if (isArray(value)) {
431
- return value;
432
- }
433
- return [value];
434
- }
435
- function toArray(value) {
436
- if (value === undefined) {
437
- return [];
438
- }
439
- return toArrayStrict(value);
440
- }
441
- function mapContext(mapper, context, event, self) {
442
- if (typeof mapper === 'function') {
443
- return mapper({
444
- context,
445
- event,
446
- self
447
- });
448
- }
449
- return mapper;
450
- }
451
- function isPromiseLike(value) {
452
- if (value instanceof Promise) {
453
- return true;
454
- }
455
- // Check if shape matches the Promise/A+ specification for a "thenable".
456
- if (value !== null && (typeof value === 'function' || typeof value === 'object') && typeof value.then === 'function') {
457
- return true;
458
- }
459
- return false;
460
- }
461
- function isArray(value) {
462
- return Array.isArray(value);
463
- }
464
- function isErrorEvent(event) {
465
- return typeof event.type === 'string' && (event.type === errorExecution || event.type.startsWith(errorPlatform));
466
- }
467
- function toTransitionConfigArray(configLike) {
468
- return toArrayStrict(configLike).map(transitionLike => {
469
- if (typeof transitionLike === 'undefined' || typeof transitionLike === 'string') {
470
- return {
471
- target: transitionLike
472
- };
473
- }
474
- return transitionLike;
475
- });
476
- }
477
- function normalizeTarget(target) {
478
- if (target === undefined || target === TARGETLESS_KEY) {
479
- return undefined;
480
- }
481
- return toArray(target);
482
- }
483
- function toObserver(nextHandler, errorHandler, completionHandler) {
484
- const isObserver = typeof nextHandler === 'object';
485
- const self = isObserver ? nextHandler : undefined;
486
- return {
487
- next: (isObserver ? nextHandler.next : nextHandler)?.bind(self),
488
- error: (isObserver ? nextHandler.error : errorHandler)?.bind(self),
489
- complete: (isObserver ? nextHandler.complete : completionHandler)?.bind(self)
490
- };
491
- }
492
- function createInvokeId(stateNodeId, index) {
493
- return `${stateNodeId}:invocation[${index}]`;
494
- }
495
- function resolveReferencedActor(referenced) {
496
- return referenced ? 'transition' in referenced ? {
497
- src: referenced,
498
- input: undefined
499
- } : referenced : undefined;
500
- }
501
-
502
- let ActorStatus = /*#__PURE__*/function (ActorStatus) {
503
- ActorStatus[ActorStatus["NotStarted"] = 0] = "NotStarted";
504
- ActorStatus[ActorStatus["Running"] = 1] = "Running";
505
- ActorStatus[ActorStatus["Stopped"] = 2] = "Stopped";
506
- return ActorStatus;
507
- }({});
508
-
509
- /**
510
- * @deprecated Use `ActorStatus` instead.
511
- */
512
- const InterpreterStatus = ActorStatus;
513
- const defaultOptions = {
514
- deferEvents: true,
515
- clock: {
516
- setTimeout: (fn, ms) => {
517
- return setTimeout(fn, ms);
518
- },
519
- clearTimeout: id => {
520
- return clearTimeout(id);
521
- }
522
- },
523
- logger: console.log.bind(console),
524
- devTools: false
525
- };
526
- class Actor {
527
- /**
528
- * The current internal state of the actor.
529
- */
530
-
531
- /**
532
- * The clock that is responsible for setting and clearing timeouts, such as delayed events and transitions.
533
- */
534
-
535
- /**
536
- * The unique identifier for this actor relative to its parent.
537
- */
538
-
539
- /**
540
- * Whether the service is started.
541
- */
542
-
543
- // Actor Ref
544
-
545
- // TODO: add typings for system
546
-
547
- /**
548
- * The globally unique process ID for this invocation.
549
- */
550
-
551
- /**
552
- * Creates a new actor instance for the given logic with the provided options, if any.
553
- *
554
- * @param logic The logic to create an actor from
555
- * @param options Actor options
556
- */
557
- constructor(logic, options) {
558
- this.logic = logic;
559
- this._state = void 0;
560
- this.clock = void 0;
561
- this.options = void 0;
562
- this.id = void 0;
563
- this.mailbox = new Mailbox(this._process.bind(this));
564
- this.delayedEventsMap = {};
565
- this.observers = new Set();
566
- this.logger = void 0;
567
- this.status = ActorStatus.NotStarted;
568
- this._parent = void 0;
569
- this.ref = void 0;
570
- this._actorContext = void 0;
571
- this._systemId = void 0;
572
- this.sessionId = void 0;
573
- this.system = void 0;
574
- this._doneEvent = void 0;
575
- this.src = void 0;
576
- this._deferred = [];
577
- const resolvedOptions = {
578
- ...defaultOptions,
579
- ...options
580
- };
581
- const {
582
- clock,
583
- logger,
584
- parent,
585
- id,
586
- systemId
587
- } = resolvedOptions;
588
- const self = this;
589
- this.system = parent?.system ?? createSystem();
590
- if (systemId) {
591
- this._systemId = systemId;
592
- this.system._set(systemId, this);
593
- }
594
- this.sessionId = this.system._bookId();
595
- this.id = id ?? this.sessionId;
596
- this.logger = logger;
597
- this.clock = clock;
598
- this._parent = parent;
599
- this.options = resolvedOptions;
600
- this.src = resolvedOptions.src;
601
- this.ref = this;
602
- this._actorContext = {
603
- self,
604
- id: this.id,
605
- sessionId: this.sessionId,
606
- logger: this.logger,
607
- defer: fn => {
608
- this._deferred.push(fn);
609
- },
610
- system: this.system,
611
- stopChild: child => {
612
- if (child._parent !== this) {
613
- throw new Error(`Cannot stop child actor ${child.id} of ${this.id} because it is not a child`);
614
- }
615
- child._stop();
616
- }
617
- };
618
-
619
- // Ensure that the send method is bound to this Actor instance
620
- // if destructured
621
- this.send = this.send.bind(this);
622
- this._initState();
623
- }
624
- _initState() {
625
- this._state = this.options.state ? this.logic.restoreState ? this.logic.restoreState(this.options.state, this._actorContext) : this.options.state : this.logic.getInitialState(this._actorContext, this.options?.input);
626
- }
627
-
628
- // array of functions to defer
629
-
630
- update(state) {
631
- // Update state
632
- this._state = state;
633
- const snapshot = this.getSnapshot();
634
-
635
- // Execute deferred effects
636
- let deferredFn;
637
- while (deferredFn = this._deferred.shift()) {
638
- deferredFn();
639
- }
640
- for (const observer of this.observers) {
641
- // TODO: should observers be notified in case of the error?
642
- try {
643
- observer.next?.(snapshot);
644
- } catch (err) {
645
- reportUnhandledError(err);
646
- }
647
- }
648
- const status = this.logic.getStatus?.(state);
649
- switch (status?.status) {
650
- case 'done':
651
- this._stopProcedure();
652
- this._complete();
653
- this._doneEvent = doneInvoke(this.id, status.data);
654
- this._parent?.send(this._doneEvent);
655
- break;
656
- case 'error':
657
- this._stopProcedure();
658
- this._error(status.data);
659
- this._parent?.send(error(this.id, status.data));
660
- break;
661
- }
662
- }
663
- subscribe(nextListenerOrObserver, errorListener, completeListener) {
664
- const observer = toObserver(nextListenerOrObserver, errorListener, completeListener);
665
- if (this.status !== ActorStatus.Stopped) {
666
- this.observers.add(observer);
667
- } else {
668
- try {
669
- observer.complete?.();
670
- } catch (err) {
671
- reportUnhandledError(err);
672
- }
673
- }
674
- return {
675
- unsubscribe: () => {
676
- this.observers.delete(observer);
677
- }
678
- };
679
- }
680
-
681
- /**
682
- * Starts the Actor from the initial state
683
- */
684
- start() {
685
- if (this.status === ActorStatus.Running) {
686
- // Do not restart the service if it is already started
687
- return this;
688
- }
689
- this.system._register(this.sessionId, this);
690
- if (this._systemId) {
691
- this.system._set(this._systemId, this);
692
- }
693
- this.status = ActorStatus.Running;
694
- const status = this.logic.getStatus?.(this._state);
695
- switch (status?.status) {
696
- case 'done':
697
- // a state machine can be "done" upon intialization (it could reach a final state using initial microsteps)
698
- // we still need to complete observers, flush deferreds etc
699
- this.update(this._state);
700
- // fallthrough
701
- case 'error':
702
- // TODO: rethink cleanup of observers, mailbox, etc
703
- return this;
704
- }
705
- if (this.logic.start) {
706
- try {
707
- this.logic.start(this._state, this._actorContext);
708
- } catch (err) {
709
- this._stopProcedure();
710
- this._error(err);
711
- this._parent?.send(error(this.id, err));
712
- return this;
713
- }
714
- }
715
-
716
- // TODO: this notifies all subscribers but usually this is redundant
717
- // there is no real change happening here
718
- // we need to rethink if this needs to be refactored
719
- this.update(this._state);
720
- if (this.options.devTools) {
721
- this.attachDevTools();
722
- }
723
- this.mailbox.start();
724
- return this;
725
- }
726
- _process(event) {
727
- // TODO: reexamine what happens when an action (or a guard or smth) throws
728
- let nextState;
729
- let caughtError;
730
- try {
731
- nextState = this.logic.transition(this._state, event, this._actorContext);
732
- } catch (err) {
733
- // we wrap it in a box so we can rethrow it later even if falsy value gets caught here
734
- caughtError = {
735
- err
736
- };
737
- }
738
- if (caughtError) {
739
- const {
740
- err
741
- } = caughtError;
742
- this._stopProcedure();
743
- this._error(err);
744
- this._parent?.send(error(this.id, err));
745
- return;
746
- }
747
- this.update(nextState);
748
- if (event.type === XSTATE_STOP) {
749
- this._stopProcedure();
750
- this._complete();
751
- }
752
- }
753
- _stop() {
754
- if (this.status === ActorStatus.Stopped) {
755
- return this;
756
- }
757
- this.mailbox.clear();
758
- if (this.status === ActorStatus.NotStarted) {
759
- this.status = ActorStatus.Stopped;
760
- return this;
761
- }
762
- this.mailbox.enqueue({
763
- type: XSTATE_STOP
764
- });
765
- return this;
766
- }
767
-
768
- /**
769
- * Stops the Actor and unsubscribe all listeners.
770
- */
771
- stop() {
772
- if (this._parent) {
773
- throw new Error('A non-root actor cannot be stopped directly.');
774
- }
775
- return this._stop();
776
- }
777
- _complete() {
778
- for (const observer of this.observers) {
779
- try {
780
- observer.complete?.();
781
- } catch (err) {
782
- reportUnhandledError(err);
783
- }
784
- }
785
- this.observers.clear();
786
- }
787
- _error(err) {
788
- if (!this.observers.size) {
789
- if (!this._parent) {
790
- reportUnhandledError(err);
791
- }
792
- return;
793
- }
794
- let reportError = false;
795
- for (const observer of this.observers) {
796
- const errorListener = observer.error;
797
- reportError ||= !errorListener;
798
- try {
799
- errorListener?.(err);
800
- } catch (err2) {
801
- reportUnhandledError(err2);
802
- }
803
- }
804
- this.observers.clear();
805
- if (reportError) {
806
- reportUnhandledError(err);
807
- }
808
- }
809
- _stopProcedure() {
810
- if (this.status !== ActorStatus.Running) {
811
- // Actor already stopped; do nothing
812
- return this;
813
- }
814
-
815
- // Cancel all delayed events
816
- for (const key of Object.keys(this.delayedEventsMap)) {
817
- this.clock.clearTimeout(this.delayedEventsMap[key]);
818
- }
819
-
820
- // TODO: mailbox.reset
821
- this.mailbox.clear();
822
- // TODO: after `stop` we must prepare ourselves for receiving events again
823
- // events sent *after* stop signal must be queued
824
- // it seems like this should be the common behavior for all of our consumers
825
- // so perhaps this should be unified somehow for all of them
826
- this.mailbox = new Mailbox(this._process.bind(this));
827
- this.status = ActorStatus.Stopped;
828
- this.system._unregister(this);
829
- return this;
830
- }
831
-
832
- /**
833
- * Sends an event to the running Actor to trigger a transition.
834
- *
835
- * @param event The event to send
836
- */
837
- send(event) {
838
- if (typeof event === 'string') {
839
- throw new Error(`Only event objects may be sent to actors; use .send({ type: "${event}" }) instead`);
840
- }
841
- if (this.status === ActorStatus.Stopped) {
842
- return;
843
- }
844
- if (this.status !== ActorStatus.Running && !this.options.deferEvents) {
845
- throw new Error(`Event "${event.type}" was sent to uninitialized actor "${this.id
846
- // tslint:disable-next-line:max-line-length
847
- }". Make sure .start() is called for this actor, or set { deferEvents: true } in the actor options.\nEvent: ${JSON.stringify(event)}`);
848
- }
849
- this.mailbox.enqueue(event);
850
- }
851
-
852
- // TODO: make private (and figure out a way to do this within the machine)
853
- delaySend({
854
- event,
855
- id,
856
- delay,
857
- to
858
- }) {
859
- const timerId = this.clock.setTimeout(() => {
860
- if (to) {
861
- to.send(event);
862
- } else {
863
- this.send(event);
864
- }
865
- }, delay);
866
-
867
- // TODO: consider the rehydration story here
868
- if (id) {
869
- this.delayedEventsMap[id] = timerId;
870
- }
871
- }
872
-
873
- // TODO: make private (and figure out a way to do this within the machine)
874
- cancel(sendId) {
875
- this.clock.clearTimeout(this.delayedEventsMap[sendId]);
876
- delete this.delayedEventsMap[sendId];
877
- }
878
- attachDevTools() {
879
- const {
880
- devTools
881
- } = this.options;
882
- if (devTools) {
883
- const resolvedDevToolsAdapter = typeof devTools === 'function' ? devTools : dev_dist_xstateDev.devToolsAdapter;
884
- resolvedDevToolsAdapter(this);
885
- }
886
- }
887
- toJSON() {
888
- return {
889
- id: this.id
890
- };
891
- }
892
- getPersistedState() {
893
- return this.logic.getPersistedState?.(this._state);
894
- }
895
- [symbolObservable]() {
896
- return this;
897
- }
898
- getSnapshot() {
899
- return this.logic.getSnapshot ? this.logic.getSnapshot(this._state) : this._state;
900
- }
901
- }
902
-
903
- /**
904
- * Creates a new `ActorRef` instance for the given machine with the provided options, if any.
905
- *
906
- * @param machine The machine to create an actor from
907
- * @param options `ActorRef` options
908
- */
909
-
910
- function createActor(logic, options) {
911
- const interpreter = new Actor(logic, options);
912
- return interpreter;
913
- }
914
-
915
- /**
916
- * Creates a new Interpreter instance for the given machine with the provided options, if any.
917
- *
918
- * @deprecated Use `createActor` instead
919
- */
920
- const interpret = createActor;
921
-
922
- /**
923
- * @deprecated Use `Actor` instead.
924
- */
925
-
926
- function resolve$6(actorContext, state, actionArgs, {
43
+ function resolve$2(actorContext, state, actionArgs, {
927
44
  id,
928
45
  systemId,
929
46
  src,
@@ -956,7 +73,7 @@ function resolve$6(actorContext, state, actionArgs, {
956
73
  actorRef
957
74
  }];
958
75
  }
959
- function execute$3(actorContext, {
76
+ function execute$2(actorContext, {
960
77
  id,
961
78
  actorRef
962
79
  }) {
@@ -970,7 +87,7 @@ function execute$3(actorContext, {
970
87
  try {
971
88
  actorRef.start?.();
972
89
  } catch (err) {
973
- actorContext.self.send(error(id, err));
90
+ actorContext.self.send(createErrorActorEvent(id, err));
974
91
  return;
975
92
  }
976
93
  });
@@ -991,11 +108,55 @@ function invoke({
991
108
  invoke.systemId = systemId;
992
109
  invoke.src = src;
993
110
  invoke.input = input;
994
- invoke.resolve = resolve$6;
995
- invoke.execute = execute$3;
111
+ invoke.resolve = resolve$2;
112
+ invoke.execute = execute$2;
996
113
  return invoke;
997
114
  }
998
115
 
116
+ function resolve$1(_, state, args, {
117
+ actorRef
118
+ }) {
119
+ const actorRefOrString = typeof actorRef === 'function' ? actorRef(args) : actorRef;
120
+ const resolvedActorRef = typeof actorRefOrString === 'string' ? state.children[actorRefOrString] : actorRefOrString;
121
+ let children = state.children;
122
+ if (resolvedActorRef) {
123
+ children = {
124
+ ...children
125
+ };
126
+ delete children[resolvedActorRef.id];
127
+ }
128
+ return [cloneState(state, {
129
+ children
130
+ }), resolvedActorRef];
131
+ }
132
+ function execute$1(actorContext, actorRef) {
133
+ if (!actorRef) {
134
+ return;
135
+ }
136
+ if (actorRef.status !== ActorStatus.Running) {
137
+ actorContext.stopChild(actorRef);
138
+ return;
139
+ }
140
+ // TODO: recheck why this one has to be deferred
141
+ actorContext.defer(() => {
142
+ actorContext.stopChild(actorRef);
143
+ });
144
+ }
145
+ /**
146
+ * Stops an actor.
147
+ *
148
+ * @param actorRef The actor to stop.
149
+ */
150
+ function stop(actorRef) {
151
+ function stop(_) {
152
+ }
153
+ stop.type = 'xstate.stop';
154
+ stop.actorRef = actorRef;
155
+ stop.resolve = resolve$1;
156
+ stop.execute = execute$1;
157
+ return stop;
158
+ }
159
+
999
160
  function checkStateIn(state, _, {
1000
161
  stateValue
1001
162
  }) {
@@ -1243,10 +404,9 @@ function getDelayedTransitions(stateNode) {
1243
404
  }
1244
405
  const mutateEntryExit = (delay, i) => {
1245
406
  const delayRef = typeof delay === 'function' ? `${stateNode.id}:delay[${i}]` : delay;
1246
- const eventType = after(delayRef, stateNode.id);
1247
- stateNode.entry.push(raise({
1248
- type: eventType
1249
- }, {
407
+ const afterEvent = createAfterEvent(delayRef, stateNode.id);
408
+ const eventType = afterEvent.type;
409
+ stateNode.entry.push(raise(afterEvent, {
1250
410
  id: eventType,
1251
411
  delay
1252
412
  }));
@@ -1314,16 +474,16 @@ function formatTransitions(stateNode) {
1314
474
  }
1315
475
  }
1316
476
  if (stateNode.config.onDone) {
1317
- const descriptor = String(done(stateNode.id));
477
+ const descriptor = `xstate.done.state.${stateNode.id}`;
1318
478
  transitions.set(descriptor, toTransitionConfigArray(stateNode.config.onDone).map(t => formatTransition(stateNode, descriptor, t)));
1319
479
  }
1320
480
  for (const invokeDef of stateNode.invoke) {
1321
481
  if (invokeDef.onDone) {
1322
- const descriptor = `done.invoke.${invokeDef.id}`;
482
+ const descriptor = `xstate.done.actor.${invokeDef.id}`;
1323
483
  transitions.set(descriptor, toTransitionConfigArray(invokeDef.onDone).map(t => formatTransition(stateNode, descriptor, t)));
1324
484
  }
1325
485
  if (invokeDef.onError) {
1326
- const descriptor = `error.platform.${invokeDef.id}`;
486
+ const descriptor = `xstate.error.actor.${invokeDef.id}`;
1327
487
  transitions.set(descriptor, toTransitionConfigArray(invokeDef.onError).map(t => formatTransition(stateNode, descriptor, t)));
1328
488
  }
1329
489
  if (invokeDef.onSnapshot) {
@@ -1768,12 +928,12 @@ function enterStates(event, filteredTransitions, mutConfiguration, actions, inte
1768
928
  if (!parent.parent) {
1769
929
  continue;
1770
930
  }
1771
- internalQueue.push(done(parent.id, stateNodeToEnter.output ? mapContext(stateNodeToEnter.output, currentState.context, event, actorContext.self) : undefined));
931
+ internalQueue.push(createDoneStateEvent(parent.id, stateNodeToEnter.output ? mapContext(stateNodeToEnter.output, currentState.context, event, actorContext.self) : undefined));
1772
932
  if (parent.parent) {
1773
933
  const grandparent = parent.parent;
1774
934
  if (grandparent.type === 'parallel') {
1775
935
  if (getChildren(grandparent).every(parentNode => isInFinalState([...mutConfiguration], parentNode))) {
1776
- internalQueue.push(done(grandparent.id));
936
+ internalQueue.push(createDoneStateEvent(grandparent.id));
1777
937
  }
1778
938
  }
1779
939
  }
@@ -2216,200 +1376,7 @@ function getPersistedState(state) {
2216
1376
  };
2217
1377
  }
2218
1378
 
2219
- function resolve$5(_, state, args, {
2220
- actorRef
2221
- }) {
2222
- const actorRefOrString = typeof actorRef === 'function' ? actorRef(args) : actorRef;
2223
- const resolvedActorRef = typeof actorRefOrString === 'string' ? state.children[actorRefOrString] : actorRefOrString;
2224
- let children = state.children;
2225
- if (resolvedActorRef) {
2226
- children = {
2227
- ...children
2228
- };
2229
- delete children[resolvedActorRef.id];
2230
- }
2231
- return [cloneState(state, {
2232
- children
2233
- }), resolvedActorRef];
2234
- }
2235
- function execute$2(actorContext, actorRef) {
2236
- if (!actorRef) {
2237
- return;
2238
- }
2239
- if (actorRef.status !== ActorStatus.Running) {
2240
- actorContext.stopChild(actorRef);
2241
- return;
2242
- }
2243
- // TODO: recheck why this one has to be deferred
2244
- actorContext.defer(() => {
2245
- actorContext.stopChild(actorRef);
2246
- });
2247
- }
2248
- /**
2249
- * Stops an actor.
2250
- *
2251
- * @param actorRef The actor to stop.
2252
- */
2253
- function stop(actorRef) {
2254
- function stop(_) {
2255
- }
2256
- stop.type = 'xstate.stop';
2257
- stop.actorRef = actorRef;
2258
- stop.resolve = resolve$5;
2259
- stop.execute = execute$2;
2260
- return stop;
2261
- }
2262
-
2263
- function resolve$4(_, state, actionArgs, {
2264
- value,
2265
- label
2266
- }) {
2267
- return [state, {
2268
- value: typeof value === 'function' ? value(actionArgs) : value,
2269
- label
2270
- }];
2271
- }
2272
- function execute$1({
2273
- logger
2274
- }, {
2275
- value,
2276
- label
2277
- }) {
2278
- if (label) {
2279
- logger(label, value);
2280
- } else {
2281
- logger(value);
2282
- }
2283
- }
2284
- /**
2285
- *
2286
- * @param expr The expression function to evaluate which will be logged.
2287
- * Takes in 2 arguments:
2288
- * - `ctx` - the current state context
2289
- * - `event` - the event that caused this action to be executed.
2290
- * @param label The label to give to the logged expression.
2291
- */
2292
- function log(value = ({
2293
- context,
2294
- event
2295
- }) => ({
2296
- context,
2297
- event
2298
- }), label) {
2299
- function log(_) {
2300
- }
2301
- log.type = 'xstate.log';
2302
- log.value = value;
2303
- log.label = label;
2304
- log.resolve = resolve$4;
2305
- log.execute = execute$1;
2306
- return log;
2307
- }
2308
-
2309
- function createSpawner(actorContext, {
2310
- machine,
2311
- context
2312
- }, event, spawnedChildren) {
2313
- const spawn = (src, options = {}) => {
2314
- const {
2315
- systemId
2316
- } = options;
2317
- if (typeof src === 'string') {
2318
- const referenced = resolveReferencedActor(machine.implementations.actors[src]);
2319
- if (!referenced) {
2320
- throw new Error(`Actor logic '${src}' not implemented in machine '${machine.id}'`);
2321
- }
2322
- const input = 'input' in options ? options.input : referenced.input;
2323
-
2324
- // TODO: this should also receive `src`
2325
- const actor = createActor(referenced.src, {
2326
- id: options.id,
2327
- parent: actorContext.self,
2328
- input: typeof input === 'function' ? input({
2329
- context,
2330
- event,
2331
- self: actorContext.self
2332
- }) : input,
2333
- systemId
2334
- });
2335
- spawnedChildren[actor.id] = actor;
2336
- return actor;
2337
- } else {
2338
- // TODO: this should also receive `src`
2339
- return createActor(src, {
2340
- id: options.id,
2341
- parent: actorContext.self,
2342
- input: options.input,
2343
- systemId
2344
- });
2345
- }
2346
- };
2347
- return (src, options) => {
2348
- const actorRef = spawn(src, options); // TODO: fix types
2349
- spawnedChildren[actorRef.id] = actorRef;
2350
- actorContext.defer(() => {
2351
- if (actorRef.status === ActorStatus.Stopped) {
2352
- return;
2353
- }
2354
- try {
2355
- actorRef.start?.();
2356
- } catch (err) {
2357
- actorContext.self.send(error(actorRef.id, err));
2358
- return;
2359
- }
2360
- });
2361
- return actorRef;
2362
- };
2363
- }
2364
-
2365
- function resolve$3(actorContext, state, actionArgs, {
2366
- assignment
2367
- }) {
2368
- if (!state.context) {
2369
- throw new Error('Cannot assign to undefined `context`. Ensure that `context` is defined in the machine config.');
2370
- }
2371
- const spawnedChildren = {};
2372
- const assignArgs = {
2373
- context: state.context,
2374
- event: actionArgs.event,
2375
- action: actionArgs.action,
2376
- spawn: createSpawner(actorContext, state, actionArgs.event, spawnedChildren),
2377
- self: actorContext?.self,
2378
- system: actorContext?.system
2379
- };
2380
- let partialUpdate = {};
2381
- if (typeof assignment === 'function') {
2382
- partialUpdate = assignment(assignArgs);
2383
- } else {
2384
- for (const key of Object.keys(assignment)) {
2385
- const propAssignment = assignment[key];
2386
- partialUpdate[key] = typeof propAssignment === 'function' ? propAssignment(assignArgs) : propAssignment;
2387
- }
2388
- }
2389
- const updatedContext = Object.assign({}, state.context, partialUpdate);
2390
- return [cloneState(state, {
2391
- context: updatedContext,
2392
- children: Object.keys(spawnedChildren).length ? {
2393
- ...state.children,
2394
- ...spawnedChildren
2395
- } : state.children
2396
- })];
2397
- }
2398
- /**
2399
- * Updates the current context of the machine.
2400
- *
2401
- * @param assignment An object that represents the partial context to update.
2402
- */
2403
- function assign(assignment) {
2404
- function assign(_) {
2405
- }
2406
- assign.type = 'xstate.assign';
2407
- assign.assignment = assignment;
2408
- assign.resolve = resolve$3;
2409
- return assign;
2410
- }
2411
-
2412
- function resolve$2(_, state, args, {
1379
+ function resolve(_, state, args, {
2413
1380
  event: eventOrExpr,
2414
1381
  id,
2415
1382
  delay
@@ -2453,178 +1420,9 @@ function raise(eventOrExpr, options) {
2453
1420
  raise.event = eventOrExpr;
2454
1421
  raise.id = options?.id;
2455
1422
  raise.delay = options?.delay;
2456
- raise.resolve = resolve$2;
1423
+ raise.resolve = resolve;
2457
1424
  raise.execute = execute;
2458
1425
  return raise;
2459
1426
  }
2460
1427
 
2461
- function resolve$1(_, state, actionArgs, {
2462
- branches
2463
- }) {
2464
- const matchedActions = branches.find(condition => {
2465
- return !condition.guard || evaluateGuard(condition.guard, state.context, actionArgs.event, state);
2466
- })?.actions;
2467
- return [state, undefined, toArray(matchedActions)];
2468
- }
2469
- function choose(branches) {
2470
- function choose(_) {
2471
- }
2472
- choose.type = 'xstate.choose';
2473
- choose.branches = branches;
2474
- choose.resolve = resolve$1;
2475
- return choose;
2476
- }
2477
-
2478
- function resolve(_, state, args, {
2479
- get
2480
- }) {
2481
- return [state, undefined, toArray(get({
2482
- context: args.context,
2483
- event: args.event
2484
- }))];
2485
- }
2486
- function pure(getActions) {
2487
- function pure(_) {
2488
- }
2489
- pure.type = 'xstate.pure';
2490
- pure.get = getActions;
2491
- pure.resolve = resolve;
2492
- return pure;
2493
- }
2494
-
2495
- /**
2496
- * Returns an event type that represents an implicit event that
2497
- * is sent after the specified `delay`.
2498
- *
2499
- * @param delayRef The delay in milliseconds
2500
- * @param id The state node ID where this event is handled
2501
- */
2502
- function after(delayRef, id) {
2503
- const idSuffix = id ? `#${id}` : '';
2504
- return `${ConstantPrefix.After}(${delayRef})${idSuffix}`;
2505
- }
2506
-
2507
- /**
2508
- * Returns an event that represents that a final state node
2509
- * has been reached in the parent state node.
2510
- *
2511
- * @param id The final state node's parent state node `id`
2512
- * @param output The data to pass into the event
2513
- */
2514
- function done(id, output) {
2515
- const type = `${ConstantPrefix.DoneState}.${id}`;
2516
- const eventObject = {
2517
- type,
2518
- output
2519
- };
2520
- eventObject.toString = () => type;
2521
- return eventObject;
2522
- }
2523
- function doneInvokeEventType(invokeId) {
2524
- return `${ConstantPrefix.DoneInvoke}.${invokeId}`;
2525
- }
2526
-
2527
- /**
2528
- * Returns an event that represents that an invoked service has terminated.
2529
- *
2530
- * An invoked service is terminated when it has reached a top-level final state node,
2531
- * but not when it is canceled.
2532
- *
2533
- * @param invokeId The invoked service ID
2534
- * @param output The data to pass into the event
2535
- */
2536
- function doneInvoke(invokeId, output) {
2537
- const type = doneInvokeEventType(invokeId);
2538
- const eventObject = {
2539
- type,
2540
- output
2541
- };
2542
- eventObject.toString = () => type;
2543
- return eventObject;
2544
- }
2545
- function errorEventType(id) {
2546
- return `${ConstantPrefix.ErrorPlatform}.${id}`;
2547
- }
2548
- function error(id, data) {
2549
- const type = errorEventType(id);
2550
- const eventObject = {
2551
- type,
2552
- data
2553
- };
2554
- eventObject.toString = () => type;
2555
- return eventObject;
2556
- }
2557
- function createInitEvent(input) {
2558
- return {
2559
- type: XSTATE_INIT,
2560
- input
2561
- };
2562
- }
2563
-
2564
- exports.Actor = Actor;
2565
- exports.ActorStatus = ActorStatus;
2566
- exports.ConstantPrefix = ConstantPrefix;
2567
- exports.InterpreterStatus = InterpreterStatus;
2568
- exports.NULL_EVENT = NULL_EVENT;
2569
- exports.STATE_DELIMITER = STATE_DELIMITER;
2570
- exports.SpecialTargets = SpecialTargets;
2571
- exports.State = State;
2572
- exports.XSTATE_INIT = XSTATE_INIT;
2573
- exports.XSTATE_STOP = XSTATE_STOP;
2574
- exports.after = after;
2575
- exports.and = and;
2576
- exports.assign = assign;
2577
- exports.cancel = cancel;
2578
- exports.choose = choose;
2579
- exports.cloneState = cloneState;
2580
- exports.constantPrefixes = constantPrefixes;
2581
- exports.createActor = createActor;
2582
- exports.createInitEvent = createInitEvent;
2583
- exports.createInvokeId = createInvokeId;
2584
- exports.done = done;
2585
- exports.doneInvoke = doneInvoke;
2586
- exports.doneInvokeEventType = doneInvokeEventType;
2587
- exports.error = error;
2588
- exports.errorEventType = errorEventType;
2589
- exports.escalate = escalate;
2590
- exports.evaluateGuard = evaluateGuard;
2591
- exports.formatInitialTransition = formatInitialTransition;
2592
- exports.formatTransition = formatTransition;
2593
- exports.formatTransitions = formatTransitions;
2594
- exports.forwardTo = forwardTo;
2595
- exports.getCandidates = getCandidates;
2596
- exports.getConfiguration = getConfiguration;
2597
- exports.getDelayedTransitions = getDelayedTransitions;
2598
- exports.getInitialConfiguration = getInitialConfiguration;
2599
- exports.getPersistedState = getPersistedState;
2600
- exports.getStateNodeByPath = getStateNodeByPath;
2601
- exports.getStateNodes = getStateNodes;
2602
- exports.interpret = interpret;
2603
- exports.isAtomicStateNode = isAtomicStateNode;
2604
- exports.isErrorEvent = isErrorEvent;
2605
- exports.isInFinalState = isInFinalState;
2606
- exports.isPromiseLike = isPromiseLike;
2607
- exports.isStateId = isStateId;
2608
- exports.log = log;
2609
- exports.macrostep = macrostep;
2610
- exports.mapValues = mapValues;
2611
- exports.matchesState = matchesState;
2612
- exports.memo = memo;
2613
- exports.microstep = microstep;
2614
- exports.not = not;
2615
- exports.or = or;
2616
- exports.pathToStateValue = pathToStateValue;
2617
- exports.pure = pure;
2618
- exports.raise = raise;
2619
- exports.resolveActionsAndContext = resolveActionsAndContext;
2620
- exports.resolveReferencedActor = resolveReferencedActor;
2621
- exports.resolveStateValue = resolveStateValue;
2622
- exports.sendParent = sendParent;
2623
- exports.sendTo = sendTo;
2624
- exports.stateIn = stateIn;
2625
- exports.stop = stop;
2626
- exports.symbolObservable = symbolObservable;
2627
- exports.toArray = toArray;
2628
- exports.toObserver = toObserver;
2629
- exports.toTransitionConfigArray = toTransitionConfigArray;
2630
- exports.transitionNode = transitionNode;
1428
+ export { raise as A, stop as B, State as S, formatTransition as a, formatInitialTransition as b, getCandidates as c, getConfiguration as d, evaluateGuard as e, formatTransitions as f, getDelayedTransitions as g, getStateNodes as h, isInFinalState as i, cloneState as j, macrostep as k, getInitialConfiguration as l, memo as m, resolveActionsAndContext as n, microstep as o, isAtomicStateNode as p, isStateId as q, resolveStateValue as r, getStateNodeByPath as s, transitionNode as t, getPersistedState as u, and as v, not as w, or as x, stateIn as y, cancel as z };