xstate 5.0.0-beta.43 → 5.0.0-beta.45

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 (55) hide show
  1. package/actions/dist/xstate-actions.cjs.js +2 -3
  2. package/actions/dist/xstate-actions.development.cjs.js +2 -3
  3. package/actions/dist/xstate-actions.development.esm.js +2 -3
  4. package/actions/dist/xstate-actions.esm.js +2 -3
  5. package/actions/dist/xstate-actions.umd.min.js +1 -1
  6. package/actions/dist/xstate-actions.umd.min.js.map +1 -1
  7. package/actors/dist/xstate-actors.cjs.js +98 -10
  8. package/actors/dist/xstate-actors.development.cjs.js +98 -10
  9. package/actors/dist/xstate-actors.development.esm.js +93 -5
  10. package/actors/dist/xstate-actors.esm.js +93 -5
  11. package/actors/dist/xstate-actors.umd.min.js +1 -1
  12. package/actors/dist/xstate-actors.umd.min.js.map +1 -1
  13. package/dist/declarations/src/State.d.ts +14 -18
  14. package/dist/declarations/src/StateMachine.d.ts +1 -1
  15. package/dist/declarations/src/actions/choose.d.ts +3 -3
  16. package/dist/declarations/src/actions/pure.d.ts +4 -4
  17. package/dist/declarations/src/actions/spawn.d.ts +11 -16
  18. package/dist/declarations/src/actors/observable.d.ts +39 -0
  19. package/dist/declarations/src/actors/transition.d.ts +53 -4
  20. package/dist/declarations/src/{Machine.d.ts → createMachine.d.ts} +1 -1
  21. package/dist/declarations/src/guards.d.ts +27 -5
  22. package/dist/declarations/src/index.d.ts +3 -2
  23. package/dist/declarations/src/interpreter.d.ts +1 -0
  24. package/dist/declarations/src/setup.d.ts +32 -0
  25. package/dist/declarations/src/spawn.d.ts +9 -13
  26. package/dist/declarations/src/stateUtils.d.ts +11 -11
  27. package/dist/declarations/src/types.d.ts +31 -29
  28. package/dist/declarations/src/utils.d.ts +1 -3
  29. package/dist/{raise-8dc8e1aa.esm.js → raise-2b5a4e4c.esm.js} +934 -103
  30. package/dist/{raise-f4ad5a87.development.esm.js → raise-90139fbc.development.esm.js} +945 -103
  31. package/dist/{raise-23dea0d7.development.cjs.js → raise-b3fb3c65.development.cjs.js} +999 -137
  32. package/dist/{raise-e0fe5c2d.cjs.js → raise-fabffc3d.cjs.js} +986 -135
  33. package/dist/{send-5d129d95.development.esm.js → send-24cc8018.development.esm.js} +4 -30
  34. package/dist/{send-84e2e742.esm.js → send-8e7e41e7.esm.js} +4 -30
  35. package/dist/{send-87bbaaab.cjs.js → send-c124176f.cjs.js} +13 -39
  36. package/dist/{send-0174c155.development.cjs.js → send-d0bc7eed.development.cjs.js} +13 -39
  37. package/dist/xstate.cjs.js +67 -35
  38. package/dist/xstate.cjs.mjs +2 -0
  39. package/dist/xstate.development.cjs.js +67 -35
  40. package/dist/xstate.development.cjs.mjs +2 -0
  41. package/dist/xstate.development.esm.js +42 -13
  42. package/dist/xstate.esm.js +42 -13
  43. package/dist/xstate.umd.min.js +1 -1
  44. package/dist/xstate.umd.min.js.map +1 -1
  45. package/guards/dist/xstate-guards.cjs.js +1 -2
  46. package/guards/dist/xstate-guards.development.cjs.js +1 -2
  47. package/guards/dist/xstate-guards.development.esm.js +1 -2
  48. package/guards/dist/xstate-guards.esm.js +1 -2
  49. package/guards/dist/xstate-guards.umd.min.js +1 -1
  50. package/guards/dist/xstate-guards.umd.min.js.map +1 -1
  51. package/package.json +1 -1
  52. package/dist/interpreter-36d5556e.cjs.js +0 -887
  53. package/dist/interpreter-4e8e2a0d.development.cjs.js +0 -898
  54. package/dist/interpreter-63c80754.esm.js +0 -857
  55. package/dist/interpreter-80eb3bec.development.esm.js +0 -868
@@ -2,17 +2,66 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var interpreter = require('../../dist/interpreter-36d5556e.cjs.js');
5
+ var guards_dist_xstateGuards = require('../../dist/raise-fabffc3d.cjs.js');
6
6
  require('../../dev/dist/xstate-dev.cjs.js');
7
7
 
8
8
  /**
9
- * Returns actor logic from a transition function and its initial state.
9
+ * Returns actor logic given a transition function and its initial state.
10
10
  *
11
- * A transition function is a function that takes the current state and an event and returns the next state.
11
+ * A transition function is a function that takes the current `state` and received `event` object as arguments, and returns the next state, similar to a reducer.
12
12
  *
13
- * @param transition The transition function that returns the next state given the current state and event.
14
- * @param initialContext The initial state of the transition function.
13
+ * Actors created from transition logic (“transition actors”) can:
14
+ *
15
+ * - Receive events
16
+ * - Emit snapshots of its state
17
+ *
18
+ * The transition function’s `state` is used as its transition actor’s `context`.
19
+ *
20
+ * Note that the "state" for a transition function is provided by the initial state argument, and is not the same as the State object of an actor or a state within a machine configuration.
21
+ *
22
+ * @param transition The transition function used to describe the transition logic. It should return the next state given the current state and event. It receives the following arguments:
23
+ * - `state` - the current state.
24
+ * - `event` - the received event.
25
+ * - `actorScope` - the actor scope object, with properties like `self` and `system`.
26
+ * @param initialContext The initial state of the transition function, either an object representing the state, or a function which returns a state object. If a function, it will receive as its only argument an object with the following properties:
27
+ * - `input` - the `input` provided to its parent transition actor.
28
+ * - `self` - a reference to its parent transition actor.
29
+ * @see {@link https://stately.ai/docs/input | Input docs} for more information about how input is passed
15
30
  * @returns Actor logic
31
+ *
32
+ * @example
33
+ * ```ts
34
+ * const transitionLogic = fromTransition(
35
+ * (state, event) => {
36
+ * if (event.type === 'increment') {
37
+ * return {
38
+ * ...state,
39
+ * count: state.count + 1,
40
+ * };
41
+ * }
42
+ * return state;
43
+ * },
44
+ * { count: 0 },
45
+ * );
46
+ *
47
+ * const transitionActor = createActor(transitionLogic);
48
+ * transitionActor.subscribe((snapshot) => {
49
+ * console.log(snapshot);
50
+ * });
51
+ * transitionActor.start();
52
+ * // => {
53
+ * // status: 'active',
54
+ * // context: { count: 0 },
55
+ * // ...
56
+ * // }
57
+ *
58
+ * transitionActor.send({ type: 'increment' });
59
+ * // => {
60
+ * // status: 'active',
61
+ * // context: { count: 1 },
62
+ * // ...
63
+ * // }
64
+ * ```
16
65
  */
17
66
  function fromTransition(transition, initialContext) {
18
67
  return {
@@ -131,7 +180,7 @@ function fromCallback(invokeCallback) {
131
180
  });
132
181
  return state;
133
182
  }
134
- if (event.type === interpreter.XSTATE_STOP) {
183
+ if (event.type === guards_dist_xstateGuards.XSTATE_STOP) {
135
184
  state = {
136
185
  ...state,
137
186
  status: 'stopped',
@@ -169,6 +218,45 @@ function fromCallback(invokeCallback) {
169
218
  return logic;
170
219
  }
171
220
 
221
+ /**
222
+ * Observable actor logic is described by an observable stream of values. Actors created from observable logic (“observable actors”) can:
223
+ *
224
+ * - Emit snapshots of the observable’s emitted value
225
+ *
226
+ * The observable’s emitted value is used as its observable actor’s `context`.
227
+ *
228
+ * Sending events to observable actors will have no effect.
229
+ *
230
+ * @param observableCreator A function that creates an observable. It receives one argument, an object with the following properties:
231
+ * - `input` - Data that was provided to the observable actor
232
+ * - `self` - The parent actor
233
+ * - `system` - The actor system to which the observable actor belongs
234
+ * It should return a {@link Subscribable}, which is compatible with an RxJS Observable, although RxJS is not required to create them.
235
+ *
236
+ * @example
237
+ * ```ts
238
+ * import { fromObservable, createActor } from 'xstate'
239
+ * import { interval } from 'rxjs';
240
+ *
241
+ * const logic = fromObservable((obj) => interval(1000));
242
+ *
243
+ * const actor = createActor(logic);
244
+ *
245
+ * actor.subscribe((snapshot) => {
246
+ * console.log(snapshot.context);
247
+ * });
248
+ *
249
+ * actor.start();
250
+ * // At every second:
251
+ * // Logs 0
252
+ * // Logs 1
253
+ * // Logs 2
254
+ * // ...
255
+ * ```
256
+ *
257
+ * @see {@link https://rxjs.dev} for documentation on RxJS Observable and observable creators.
258
+ * @see {@link Subscribable} interface in XState, which is based on and compatible with RxJS Observable.
259
+ */
172
260
  function fromObservable(observableCreator) {
173
261
  const nextEventType = '$$xstate.next';
174
262
  const errorEventType = '$$xstate.error';
@@ -210,7 +298,7 @@ function fromObservable(observableCreator) {
210
298
  input: undefined,
211
299
  _subscription: undefined
212
300
  };
213
- case interpreter.XSTATE_STOP:
301
+ case guards_dist_xstateGuards.XSTATE_STOP:
214
302
  snapshot._subscription.unsubscribe();
215
303
  return {
216
304
  ...snapshot,
@@ -312,7 +400,7 @@ function fromEventObservable(lazyObservable) {
312
400
  input: undefined,
313
401
  _subscription: undefined
314
402
  };
315
- case interpreter.XSTATE_STOP:
403
+ case guards_dist_xstateGuards.XSTATE_STOP:
316
404
  state._subscription.unsubscribe();
317
405
  return {
318
406
  ...state,
@@ -451,7 +539,7 @@ promiseCreator) {
451
539
  error: event.data,
452
540
  input: undefined
453
541
  };
454
- case interpreter.XSTATE_STOP:
542
+ case guards_dist_xstateGuards.XSTATE_STOP:
455
543
  return {
456
544
  ...state,
457
545
  status: 'stopped',
@@ -509,7 +597,7 @@ promiseCreator) {
509
597
 
510
598
  const emptyLogic = fromTransition(_ => undefined, undefined);
511
599
  function createEmptyActor() {
512
- return interpreter.createActor(emptyLogic);
600
+ return guards_dist_xstateGuards.createActor(emptyLogic);
513
601
  }
514
602
 
515
603
  exports.createEmptyActor = createEmptyActor;
@@ -2,17 +2,66 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var interpreter = require('../../dist/interpreter-4e8e2a0d.development.cjs.js');
5
+ var guards_dist_xstateGuards = require('../../dist/raise-b3fb3c65.development.cjs.js');
6
6
  require('../../dev/dist/xstate-dev.development.cjs.js');
7
7
 
8
8
  /**
9
- * Returns actor logic from a transition function and its initial state.
9
+ * Returns actor logic given a transition function and its initial state.
10
10
  *
11
- * A transition function is a function that takes the current state and an event and returns the next state.
11
+ * A transition function is a function that takes the current `state` and received `event` object as arguments, and returns the next state, similar to a reducer.
12
12
  *
13
- * @param transition The transition function that returns the next state given the current state and event.
14
- * @param initialContext The initial state of the transition function.
13
+ * Actors created from transition logic (“transition actors”) can:
14
+ *
15
+ * - Receive events
16
+ * - Emit snapshots of its state
17
+ *
18
+ * The transition function’s `state` is used as its transition actor’s `context`.
19
+ *
20
+ * Note that the "state" for a transition function is provided by the initial state argument, and is not the same as the State object of an actor or a state within a machine configuration.
21
+ *
22
+ * @param transition The transition function used to describe the transition logic. It should return the next state given the current state and event. It receives the following arguments:
23
+ * - `state` - the current state.
24
+ * - `event` - the received event.
25
+ * - `actorScope` - the actor scope object, with properties like `self` and `system`.
26
+ * @param initialContext The initial state of the transition function, either an object representing the state, or a function which returns a state object. If a function, it will receive as its only argument an object with the following properties:
27
+ * - `input` - the `input` provided to its parent transition actor.
28
+ * - `self` - a reference to its parent transition actor.
29
+ * @see {@link https://stately.ai/docs/input | Input docs} for more information about how input is passed
15
30
  * @returns Actor logic
31
+ *
32
+ * @example
33
+ * ```ts
34
+ * const transitionLogic = fromTransition(
35
+ * (state, event) => {
36
+ * if (event.type === 'increment') {
37
+ * return {
38
+ * ...state,
39
+ * count: state.count + 1,
40
+ * };
41
+ * }
42
+ * return state;
43
+ * },
44
+ * { count: 0 },
45
+ * );
46
+ *
47
+ * const transitionActor = createActor(transitionLogic);
48
+ * transitionActor.subscribe((snapshot) => {
49
+ * console.log(snapshot);
50
+ * });
51
+ * transitionActor.start();
52
+ * // => {
53
+ * // status: 'active',
54
+ * // context: { count: 0 },
55
+ * // ...
56
+ * // }
57
+ *
58
+ * transitionActor.send({ type: 'increment' });
59
+ * // => {
60
+ * // status: 'active',
61
+ * // context: { count: 1 },
62
+ * // ...
63
+ * // }
64
+ * ```
16
65
  */
17
66
  function fromTransition(transition, initialContext) {
18
67
  return {
@@ -131,7 +180,7 @@ function fromCallback(invokeCallback) {
131
180
  });
132
181
  return state;
133
182
  }
134
- if (event.type === interpreter.XSTATE_STOP) {
183
+ if (event.type === guards_dist_xstateGuards.XSTATE_STOP) {
135
184
  state = {
136
185
  ...state,
137
186
  status: 'stopped',
@@ -169,6 +218,45 @@ function fromCallback(invokeCallback) {
169
218
  return logic;
170
219
  }
171
220
 
221
+ /**
222
+ * Observable actor logic is described by an observable stream of values. Actors created from observable logic (“observable actors”) can:
223
+ *
224
+ * - Emit snapshots of the observable’s emitted value
225
+ *
226
+ * The observable’s emitted value is used as its observable actor’s `context`.
227
+ *
228
+ * Sending events to observable actors will have no effect.
229
+ *
230
+ * @param observableCreator A function that creates an observable. It receives one argument, an object with the following properties:
231
+ * - `input` - Data that was provided to the observable actor
232
+ * - `self` - The parent actor
233
+ * - `system` - The actor system to which the observable actor belongs
234
+ * It should return a {@link Subscribable}, which is compatible with an RxJS Observable, although RxJS is not required to create them.
235
+ *
236
+ * @example
237
+ * ```ts
238
+ * import { fromObservable, createActor } from 'xstate'
239
+ * import { interval } from 'rxjs';
240
+ *
241
+ * const logic = fromObservable((obj) => interval(1000));
242
+ *
243
+ * const actor = createActor(logic);
244
+ *
245
+ * actor.subscribe((snapshot) => {
246
+ * console.log(snapshot.context);
247
+ * });
248
+ *
249
+ * actor.start();
250
+ * // At every second:
251
+ * // Logs 0
252
+ * // Logs 1
253
+ * // Logs 2
254
+ * // ...
255
+ * ```
256
+ *
257
+ * @see {@link https://rxjs.dev} for documentation on RxJS Observable and observable creators.
258
+ * @see {@link Subscribable} interface in XState, which is based on and compatible with RxJS Observable.
259
+ */
172
260
  function fromObservable(observableCreator) {
173
261
  const nextEventType = '$$xstate.next';
174
262
  const errorEventType = '$$xstate.error';
@@ -210,7 +298,7 @@ function fromObservable(observableCreator) {
210
298
  input: undefined,
211
299
  _subscription: undefined
212
300
  };
213
- case interpreter.XSTATE_STOP:
301
+ case guards_dist_xstateGuards.XSTATE_STOP:
214
302
  snapshot._subscription.unsubscribe();
215
303
  return {
216
304
  ...snapshot,
@@ -312,7 +400,7 @@ function fromEventObservable(lazyObservable) {
312
400
  input: undefined,
313
401
  _subscription: undefined
314
402
  };
315
- case interpreter.XSTATE_STOP:
403
+ case guards_dist_xstateGuards.XSTATE_STOP:
316
404
  state._subscription.unsubscribe();
317
405
  return {
318
406
  ...state,
@@ -451,7 +539,7 @@ promiseCreator) {
451
539
  error: event.data,
452
540
  input: undefined
453
541
  };
454
- case interpreter.XSTATE_STOP:
542
+ case guards_dist_xstateGuards.XSTATE_STOP:
455
543
  return {
456
544
  ...state,
457
545
  status: 'stopped',
@@ -509,7 +597,7 @@ promiseCreator) {
509
597
 
510
598
  const emptyLogic = fromTransition(_ => undefined, undefined);
511
599
  function createEmptyActor() {
512
- return interpreter.createActor(emptyLogic);
600
+ return guards_dist_xstateGuards.createActor(emptyLogic);
513
601
  }
514
602
 
515
603
  exports.createEmptyActor = createEmptyActor;
@@ -1,14 +1,63 @@
1
- import { X as XSTATE_STOP, d as createActor } from '../../dist/interpreter-80eb3bec.development.esm.js';
1
+ import { X as XSTATE_STOP, B as createActor } from '../../dist/raise-90139fbc.development.esm.js';
2
2
  import '../../dev/dist/xstate-dev.development.esm.js';
3
3
 
4
4
  /**
5
- * Returns actor logic from a transition function and its initial state.
5
+ * Returns actor logic given a transition function and its initial state.
6
6
  *
7
- * A transition function is a function that takes the current state and an event and returns the next state.
7
+ * A transition function is a function that takes the current `state` and received `event` object as arguments, and returns the next state, similar to a reducer.
8
8
  *
9
- * @param transition The transition function that returns the next state given the current state and event.
10
- * @param initialContext The initial state of the transition function.
9
+ * Actors created from transition logic (“transition actors”) can:
10
+ *
11
+ * - Receive events
12
+ * - Emit snapshots of its state
13
+ *
14
+ * The transition function’s `state` is used as its transition actor’s `context`.
15
+ *
16
+ * Note that the "state" for a transition function is provided by the initial state argument, and is not the same as the State object of an actor or a state within a machine configuration.
17
+ *
18
+ * @param transition The transition function used to describe the transition logic. It should return the next state given the current state and event. It receives the following arguments:
19
+ * - `state` - the current state.
20
+ * - `event` - the received event.
21
+ * - `actorScope` - the actor scope object, with properties like `self` and `system`.
22
+ * @param initialContext The initial state of the transition function, either an object representing the state, or a function which returns a state object. If a function, it will receive as its only argument an object with the following properties:
23
+ * - `input` - the `input` provided to its parent transition actor.
24
+ * - `self` - a reference to its parent transition actor.
25
+ * @see {@link https://stately.ai/docs/input | Input docs} for more information about how input is passed
11
26
  * @returns Actor logic
27
+ *
28
+ * @example
29
+ * ```ts
30
+ * const transitionLogic = fromTransition(
31
+ * (state, event) => {
32
+ * if (event.type === 'increment') {
33
+ * return {
34
+ * ...state,
35
+ * count: state.count + 1,
36
+ * };
37
+ * }
38
+ * return state;
39
+ * },
40
+ * { count: 0 },
41
+ * );
42
+ *
43
+ * const transitionActor = createActor(transitionLogic);
44
+ * transitionActor.subscribe((snapshot) => {
45
+ * console.log(snapshot);
46
+ * });
47
+ * transitionActor.start();
48
+ * // => {
49
+ * // status: 'active',
50
+ * // context: { count: 0 },
51
+ * // ...
52
+ * // }
53
+ *
54
+ * transitionActor.send({ type: 'increment' });
55
+ * // => {
56
+ * // status: 'active',
57
+ * // context: { count: 1 },
58
+ * // ...
59
+ * // }
60
+ * ```
12
61
  */
13
62
  function fromTransition(transition, initialContext) {
14
63
  return {
@@ -165,6 +214,45 @@ function fromCallback(invokeCallback) {
165
214
  return logic;
166
215
  }
167
216
 
217
+ /**
218
+ * Observable actor logic is described by an observable stream of values. Actors created from observable logic (“observable actors”) can:
219
+ *
220
+ * - Emit snapshots of the observable’s emitted value
221
+ *
222
+ * The observable’s emitted value is used as its observable actor’s `context`.
223
+ *
224
+ * Sending events to observable actors will have no effect.
225
+ *
226
+ * @param observableCreator A function that creates an observable. It receives one argument, an object with the following properties:
227
+ * - `input` - Data that was provided to the observable actor
228
+ * - `self` - The parent actor
229
+ * - `system` - The actor system to which the observable actor belongs
230
+ * It should return a {@link Subscribable}, which is compatible with an RxJS Observable, although RxJS is not required to create them.
231
+ *
232
+ * @example
233
+ * ```ts
234
+ * import { fromObservable, createActor } from 'xstate'
235
+ * import { interval } from 'rxjs';
236
+ *
237
+ * const logic = fromObservable((obj) => interval(1000));
238
+ *
239
+ * const actor = createActor(logic);
240
+ *
241
+ * actor.subscribe((snapshot) => {
242
+ * console.log(snapshot.context);
243
+ * });
244
+ *
245
+ * actor.start();
246
+ * // At every second:
247
+ * // Logs 0
248
+ * // Logs 1
249
+ * // Logs 2
250
+ * // ...
251
+ * ```
252
+ *
253
+ * @see {@link https://rxjs.dev} for documentation on RxJS Observable and observable creators.
254
+ * @see {@link Subscribable} interface in XState, which is based on and compatible with RxJS Observable.
255
+ */
168
256
  function fromObservable(observableCreator) {
169
257
  const nextEventType = '$$xstate.next';
170
258
  const errorEventType = '$$xstate.error';
@@ -1,14 +1,63 @@
1
- import { X as XSTATE_STOP, d as createActor } from '../../dist/interpreter-63c80754.esm.js';
1
+ import { X as XSTATE_STOP, B as createActor } from '../../dist/raise-2b5a4e4c.esm.js';
2
2
  import '../../dev/dist/xstate-dev.esm.js';
3
3
 
4
4
  /**
5
- * Returns actor logic from a transition function and its initial state.
5
+ * Returns actor logic given a transition function and its initial state.
6
6
  *
7
- * A transition function is a function that takes the current state and an event and returns the next state.
7
+ * A transition function is a function that takes the current `state` and received `event` object as arguments, and returns the next state, similar to a reducer.
8
8
  *
9
- * @param transition The transition function that returns the next state given the current state and event.
10
- * @param initialContext The initial state of the transition function.
9
+ * Actors created from transition logic (“transition actors”) can:
10
+ *
11
+ * - Receive events
12
+ * - Emit snapshots of its state
13
+ *
14
+ * The transition function’s `state` is used as its transition actor’s `context`.
15
+ *
16
+ * Note that the "state" for a transition function is provided by the initial state argument, and is not the same as the State object of an actor or a state within a machine configuration.
17
+ *
18
+ * @param transition The transition function used to describe the transition logic. It should return the next state given the current state and event. It receives the following arguments:
19
+ * - `state` - the current state.
20
+ * - `event` - the received event.
21
+ * - `actorScope` - the actor scope object, with properties like `self` and `system`.
22
+ * @param initialContext The initial state of the transition function, either an object representing the state, or a function which returns a state object. If a function, it will receive as its only argument an object with the following properties:
23
+ * - `input` - the `input` provided to its parent transition actor.
24
+ * - `self` - a reference to its parent transition actor.
25
+ * @see {@link https://stately.ai/docs/input | Input docs} for more information about how input is passed
11
26
  * @returns Actor logic
27
+ *
28
+ * @example
29
+ * ```ts
30
+ * const transitionLogic = fromTransition(
31
+ * (state, event) => {
32
+ * if (event.type === 'increment') {
33
+ * return {
34
+ * ...state,
35
+ * count: state.count + 1,
36
+ * };
37
+ * }
38
+ * return state;
39
+ * },
40
+ * { count: 0 },
41
+ * );
42
+ *
43
+ * const transitionActor = createActor(transitionLogic);
44
+ * transitionActor.subscribe((snapshot) => {
45
+ * console.log(snapshot);
46
+ * });
47
+ * transitionActor.start();
48
+ * // => {
49
+ * // status: 'active',
50
+ * // context: { count: 0 },
51
+ * // ...
52
+ * // }
53
+ *
54
+ * transitionActor.send({ type: 'increment' });
55
+ * // => {
56
+ * // status: 'active',
57
+ * // context: { count: 1 },
58
+ * // ...
59
+ * // }
60
+ * ```
12
61
  */
13
62
  function fromTransition(transition, initialContext) {
14
63
  return {
@@ -165,6 +214,45 @@ function fromCallback(invokeCallback) {
165
214
  return logic;
166
215
  }
167
216
 
217
+ /**
218
+ * Observable actor logic is described by an observable stream of values. Actors created from observable logic (“observable actors”) can:
219
+ *
220
+ * - Emit snapshots of the observable’s emitted value
221
+ *
222
+ * The observable’s emitted value is used as its observable actor’s `context`.
223
+ *
224
+ * Sending events to observable actors will have no effect.
225
+ *
226
+ * @param observableCreator A function that creates an observable. It receives one argument, an object with the following properties:
227
+ * - `input` - Data that was provided to the observable actor
228
+ * - `self` - The parent actor
229
+ * - `system` - The actor system to which the observable actor belongs
230
+ * It should return a {@link Subscribable}, which is compatible with an RxJS Observable, although RxJS is not required to create them.
231
+ *
232
+ * @example
233
+ * ```ts
234
+ * import { fromObservable, createActor } from 'xstate'
235
+ * import { interval } from 'rxjs';
236
+ *
237
+ * const logic = fromObservable((obj) => interval(1000));
238
+ *
239
+ * const actor = createActor(logic);
240
+ *
241
+ * actor.subscribe((snapshot) => {
242
+ * console.log(snapshot.context);
243
+ * });
244
+ *
245
+ * actor.start();
246
+ * // At every second:
247
+ * // Logs 0
248
+ * // Logs 1
249
+ * // Logs 2
250
+ * // ...
251
+ * ```
252
+ *
253
+ * @see {@link https://rxjs.dev} for documentation on RxJS Observable and observable creators.
254
+ * @see {@link Subscribable} interface in XState, which is based on and compatible with RxJS Observable.
255
+ */
168
256
  function fromObservable(observableCreator) {
169
257
  const nextEventType = '$$xstate.next';
170
258
  const errorEventType = '$$xstate.error';
@@ -1,2 +1,2 @@
1
- !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).XStateActors={})}(this,(function(t){"use strict";class e{constructor(t){this._process=t,this._active=!1,this._current=null,this._last=null}start(){this._active=!0,this.flush()}clear(){this._current&&(this._current.next=null,this._last=this._current)}enqueue(t){const e={value:t,next:null};if(this._current)return this._last.next=e,void(this._last=e);this._current=e,this._last=e,this._active&&this.flush()}flush(){for(;this._current;){const t=this._current;this._process(t.value),this._current=t.next}this._last=null}}const s="xstate.stop";function i(t,e){return{type:`xstate.error.actor.${t}`,data:e}}function r(){const t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:window;if(t.__xstate__)return t.__xstate__}const o=t=>{const e=r();e&&e.register(t)};function n(t){setTimeout((()=>{throw t}))}const a="function"==typeof Symbol&&Symbol.observable||"@@observable";let c=0;function h(t,e,s){const i="object"==typeof t,r=i?t:void 0;return{next:(i?t.next:t)?.bind(r),error:(i?t.error:e)?.bind(r),complete:(i?t.complete:s)?.bind(r)}}let u=function(t){return t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped",t}({});const d={clock:{setTimeout:(t,e)=>setTimeout(t,e),clearTimeout:t=>clearTimeout(t)},logger:console.log.bind(console),devTools:!1};class p{constructor(t,s){this.logic=t,this._state=void 0,this.clock=void 0,this.options=void 0,this.id=void 0,this.mailbox=new e(this._process.bind(this)),this.delayedEventsMap={},this.observers=new Set,this.logger=void 0,this._processingStatus=u.NotStarted,this._parent=void 0,this.ref=void 0,this._actorScope=void 0,this._systemId=void 0,this.sessionId=void 0,this.system=void 0,this._doneEvent=void 0,this.src=void 0,this._deferred=[];const i={...d,...s},{clock:r,logger:o,parent:n,id:a,systemId:p,inspect:_}=i;this.system=n?.system??function(t){const e=new Map,s=new Map,i=new WeakMap,r=new Set,o={_bookId:()=>"x:"+c++,_register:(t,s)=>(e.set(t,s),t),_unregister:t=>{e.delete(t.sessionId);const r=i.get(t);void 0!==r&&(s.delete(r),i.delete(t))},get:t=>s.get(t),_set:(t,e)=>{const r=s.get(t);if(r&&r!==e)throw new Error(`Actor with system ID '${t}' already exists.`);s.set(t,e),i.set(e,t)},inspect:t=>{r.add(t)},_sendInspectionEvent:e=>{const s={...e,rootId:t.sessionId};r.forEach((t=>t.next?.(s)))},_relay:(t,e,s)=>{o._sendInspectionEvent({type:"@xstate.event",sourceRef:t,actorRef:e,event:s}),e._send(s)}};return o}(this),_&&!n&&this.system.inspect(h(_)),this.sessionId=this.system._bookId(),this.id=a??this.sessionId,this.logger=o,this.clock=r,this._parent=n,this.options=i,this.src=i.src??t,this.ref=this,this._actorScope={self:this,id:this.id,sessionId:this.sessionId,logger:this.logger,defer:t=>{this._deferred.push(t)},system:this.system,stopChild:t=>{if(t._parent!==this)throw new Error(`Cannot stop child actor ${t.id} of ${this.id} because it is not a child`);t._stop()}},this.send=this.send.bind(this),this.system._sendInspectionEvent({type:"@xstate.actor",actorRef:this}),this._initState(s?.state),p&&"active"===this._state.status&&(this._systemId=p,this.system._set(p,this))}_initState(t){this._state=t?this.logic.restoreState?this.logic.restoreState(t,this._actorScope):t:this.logic.getInitialState(this._actorScope,this.options?.input)}update(t,e){let s;for(this._state=t;s=this._deferred.shift();)s();for(const e of this.observers)try{e.next?.(t)}catch(t){n(t)}switch(this._state.status){case"done":this._stopProcedure(),this._complete(),this._doneEvent=(r=this.id,o=this._state.output,{type:`xstate.done.actor.${r}`,output:o}),this._parent&&this.system._relay(this,this._parent,this._doneEvent);break;case"error":this._stopProcedure(),this._error(this._state.error),this._parent&&this.system._relay(this,this._parent,i(this.id,this._state.error))}var r,o;this.system._sendInspectionEvent({type:"@xstate.snapshot",actorRef:this,event:e,snapshot:t})}subscribe(t,e,s){const i=h(t,e,s);if(this._processingStatus!==u.Stopped)this.observers.add(i);else try{i.complete?.()}catch(t){n(t)}return{unsubscribe:()=>{this.observers.delete(i)}}}start(){if(this._processingStatus===u.Running)return this;this.system._register(this.sessionId,this),this._systemId&&this.system._set(this._systemId,this),this._processingStatus=u.Running;const t={type:"xstate.init",input:this.options.input};this.system._sendInspectionEvent({type:"@xstate.event",sourceRef:this._parent,actorRef:this,event:t});switch(this._state.status){case"done":this.update(this._state,t);case"error":return this}if(this.logic.start)try{this.logic.start(this._state,this._actorScope)}catch(t){return this._stopProcedure(),this._error(t),this._parent?.send(i(this.id,t)),this}return this.update(this._state,t),this.options.devTools&&this.attachDevTools(),this.mailbox.start(),this}_process(t){let e,r;try{e=this.logic.transition(this._state,t,this._actorScope)}catch(t){r={err:t}}if(r){const{err:t}=r;return this._stopProcedure(),this._error(t),void this._parent?.send(i(this.id,t))}this.update(e,t),t.type===s&&(this._stopProcedure(),this._complete())}_stop(){return this._processingStatus===u.Stopped?this:(this.mailbox.clear(),this._processingStatus===u.NotStarted?(this._processingStatus=u.Stopped,this):(this.mailbox.enqueue({type:s}),this))}stop(){if(this._parent)throw new Error("A non-root actor cannot be stopped directly.");return this._stop()}_complete(){for(const t of this.observers)try{t.complete?.()}catch(t){n(t)}this.observers.clear()}_error(t){if(!this.observers.size)return void(this._parent||n(t));let e=!1;for(const s of this.observers){const i=s.error;e||=!i;try{i?.(t)}catch(t){n(t)}}this.observers.clear(),e&&n(t)}_stopProcedure(){if(this._processingStatus!==u.Running)return this;for(const t of Object.keys(this.delayedEventsMap))this.clock.clearTimeout(this.delayedEventsMap[t]);return this.mailbox.clear(),this.mailbox=new e(this._process.bind(this)),this._processingStatus=u.Stopped,this.system._unregister(this),this}_send(t){this._processingStatus!==u.Stopped&&this.mailbox.enqueue(t)}send(t){this.system._relay(void 0,this,t)}delaySend(t){const{event:e,id:s,delay:i}=t,r=this.clock.setTimeout((()=>{this.system._relay(this,t.to??this,e)}),i);s&&(this.delayedEventsMap[s]=r)}cancel(t){this.clock.clearTimeout(this.delayedEventsMap[t]),delete this.delayedEventsMap[t]}attachDevTools(){const{devTools:t}=this.options;if(t){("function"==typeof t?t:o)(this)}}toJSON(){return{xstate$$type:1,id:this.id}}getPersistedState(t){return this.logic.getPersistedState(this._state,t)}[a](){return this}getSnapshot(){return this._state}}function _(t,e){return{config:t,transition:(e,s,i)=>({...e,context:t(e.context,s,i)}),getInitialState:(t,s)=>({status:"active",output:void 0,error:void 0,context:"function"==typeof e?e({input:s}):e}),getPersistedState:t=>t,restoreState:t=>t}}const l="$$xstate.resolve",v="$$xstate.reject";const f=_((t=>{}),void 0);t.createEmptyActor=function(){return new p(f,t);var t},t.fromCallback=function(t){return{config:t,start:(t,{self:e,system:s})=>{s._relay(e,e,{type:"xstate.create"})},transition:(e,i,{self:r,system:o})=>{if("xstate.create"===i.type){const s=t=>{"stopped"!==e.status&&r._parent&&o._relay(r,r._parent,t)},i=t=>{e._receivers.add(t)};return e._dispose=t({input:e.input,system:o,self:r,sendBack:s,receive:i}),e}return i.type===s?("function"==typeof(e={...e,status:"stopped",error:void 0})._dispose&&e._dispose(),e):(e._receivers.forEach((t=>t(i))),e)},getInitialState:(t,e)=>({status:"active",output:void 0,error:void 0,input:e,_receivers:new Set,_dispose:void 0}),getPersistedState:({_dispose:t,_receivers:e,...s})=>s,restoreState:t=>({_receivers:new Set,_dispose:void 0,...t})}},t.fromEventObservable=function(t){const e="$$xstate.error",i="$$xstate.complete";return{config:t,transition:(t,r)=>{if("active"!==t.status)return t;switch(r.type){case e:return{...t,status:"error",error:r.data,input:void 0,_subscription:void 0};case i:return{...t,status:"done",input:void 0,_subscription:void 0};case s:return t._subscription.unsubscribe(),{...t,status:"stopped",input:void 0,_subscription:void 0};default:return t}},getInitialState:(t,e)=>({status:"active",output:void 0,error:void 0,context:void 0,input:e,_subscription:void 0}),start:(s,{self:r,system:o})=>{"done"!==s.status&&(s._subscription=t({input:s.input,system:o,self:r}).subscribe({next:t=>{r._parent&&o._relay(r,r._parent,t)},error:t=>{o._relay(r,r,{type:e,data:t})},complete:()=>{o._relay(r,r,{type:i})}}))},getPersistedState:({_subscription:t,...e})=>e,restoreState:t=>({...t,_subscription:void 0})}},t.fromObservable=function(t){const e="$$xstate.next",i="$$xstate.error",r="$$xstate.complete";return{config:t,transition:(t,o,{self:n,id:a,defer:c,system:h})=>{if("active"!==t.status)return t;switch(o.type){case e:return{...t,context:o.data};case i:return{...t,status:"error",error:o.data,input:void 0,_subscription:void 0};case r:return{...t,status:"done",input:void 0,_subscription:void 0};case s:return t._subscription.unsubscribe(),{...t,status:"stopped",input:void 0,_subscription:void 0};default:return t}},getInitialState:(t,e)=>({status:"active",output:void 0,error:void 0,context:void 0,input:e,_subscription:void 0}),start:(s,{self:o,system:n})=>{"done"!==s.status&&(s._subscription=t({input:s.input,system:n,self:o}).subscribe({next:t=>{n._relay(o,o,{type:e,data:t})},error:t=>{n._relay(o,o,{type:i,data:t})},complete:()=>{n._relay(o,o,{type:r})}}))},getPersistedState:({_subscription:t,...e})=>e,restoreState:t=>({...t,_subscription:void 0})}},t.fromPromise=function(t){return{config:t,transition:(t,e)=>{if("active"!==t.status)return t;switch(e.type){case l:{const s=e.data;return{...t,status:"done",output:s,input:void 0}}case v:return{...t,status:"error",error:e.data,input:void 0};case s:return{...t,status:"stopped",input:void 0};default:return t}},start:(e,{self:s,system:i})=>{if("active"!==e.status)return;Promise.resolve(t({input:e.input,system:i,self:s})).then((t=>{"active"===s.getSnapshot().status&&i._relay(s,s,{type:l,data:t})}),(t=>{"active"===s.getSnapshot().status&&i._relay(s,s,{type:v,data:t})}))},getInitialState:(t,e)=>({status:"active",output:void 0,error:void 0,input:e}),getPersistedState:t=>t,restoreState:t=>t}},t.fromTransition=_,Object.defineProperty(t,"__esModule",{value:!0})}));
1
+ !function(t,s){"object"==typeof exports&&"undefined"!=typeof module?s(exports):"function"==typeof define&&define.amd?define(["exports"],s):s((t="undefined"!=typeof globalThis?globalThis:t||self).XStateActors={})}(this,(function(t){"use strict";class s{constructor(t){this._process=t,this._active=!1,this._current=null,this._last=null}start(){this._active=!0,this.flush()}clear(){this._current&&(this._current.next=null,this._last=this._current)}enqueue(t){const s={value:t,next:null};if(this._current)return this._last.next=s,void(this._last=s);this._current=s,this._last=s,this._active&&this.flush()}flush(){for(;this._current;){const t=this._current;this._process(t.value),this._current=t.next}this._last=null}}const e="xstate.stop";function i(t,s){return{type:`xstate.error.actor.${t}`,data:s}}function r(){const t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:window;if(t.__xstate__)return t.__xstate__}const o=t=>{const s=r();s&&s.register(t)};function n(t){setTimeout((()=>{throw t}))}const a="function"==typeof Symbol&&Symbol.observable||"@@observable";let c=0;function h(t,s,e){const i="object"==typeof t,r=i?t:void 0;return{next:(i?t.next:t)?.bind(r),error:(i?t.error:s)?.bind(r),complete:(i?t.complete:e)?.bind(r)}}let u=function(t){return t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped",t}({});const d={clock:{setTimeout:(t,s)=>setTimeout(t,s),clearTimeout:t=>clearTimeout(t)},logger:console.log.bind(console),devTools:!1};class p{constructor(t,e){this.logic=t,this._state=void 0,this.clock=void 0,this.options=void 0,this.id=void 0,this.mailbox=new s(this._process.bind(this)),this.delayedEventsMap={},this.observers=new Set,this.logger=void 0,this._processingStatus=u.NotStarted,this._parent=void 0,this._syncSnapshot=void 0,this.ref=void 0,this._actorScope=void 0,this._systemId=void 0,this.sessionId=void 0,this.system=void 0,this._doneEvent=void 0,this.src=void 0,this._deferred=[];const i={...d,...e},{clock:r,logger:o,parent:n,syncSnapshot:a,id:p,systemId:_,inspect:l}=i;this.system=n?.system??function(t){const s=new Map,e=new Map,i=new WeakMap,r=new Set,o={_bookId:()=>"x:"+c++,_register:(t,e)=>(s.set(t,e),t),_unregister:t=>{s.delete(t.sessionId);const r=i.get(t);void 0!==r&&(e.delete(r),i.delete(t))},get:t=>e.get(t),_set:(t,s)=>{const r=e.get(t);if(r&&r!==s)throw new Error(`Actor with system ID '${t}' already exists.`);e.set(t,s),i.set(s,t)},inspect:t=>{r.add(t)},_sendInspectionEvent:s=>{const e={...s,rootId:t.sessionId};r.forEach((t=>t.next?.(e)))},_relay:(t,s,e)=>{o._sendInspectionEvent({type:"@xstate.event",sourceRef:t,actorRef:s,event:e}),s._send(e)}};return o}(this),l&&!n&&this.system.inspect(h(l)),this.sessionId=this.system._bookId(),this.id=p??this.sessionId,this.logger=o,this.clock=r,this._parent=n,this._syncSnapshot=a,this.options=i,this.src=i.src??t,this.ref=this,this._actorScope={self:this,id:this.id,sessionId:this.sessionId,logger:this.logger,defer:t=>{this._deferred.push(t)},system:this.system,stopChild:t=>{if(t._parent!==this)throw new Error(`Cannot stop child actor ${t.id} of ${this.id} because it is not a child`);t._stop()}},this.send=this.send.bind(this),this.system._sendInspectionEvent({type:"@xstate.actor",actorRef:this}),_&&(this._systemId=_,this.system._set(_,this)),this._initState(e?.state),_&&"active"!==this._state.status&&this.system._unregister(this)}_initState(t){this._state=t?this.logic.restoreState?this.logic.restoreState(t,this._actorScope):t:this.logic.getInitialState(this._actorScope,this.options?.input)}update(t,s){let e;for(this._state=t;e=this._deferred.shift();)e();for(const s of this.observers)try{s.next?.(t)}catch(t){n(t)}switch(this._state.status){case"done":this._stopProcedure(),this._complete(),this._doneEvent=(r=this.id,o=this._state.output,{type:`xstate.done.actor.${r}`,output:o}),this._parent&&this.system._relay(this,this._parent,this._doneEvent);break;case"error":this._stopProcedure(),this._error(this._state.error),this._parent&&this.system._relay(this,this._parent,i(this.id,this._state.error))}var r,o;this.system._sendInspectionEvent({type:"@xstate.snapshot",actorRef:this,event:s,snapshot:t})}subscribe(t,s,e){const i=h(t,s,e);if(this._processingStatus!==u.Stopped)this.observers.add(i);else try{i.complete?.()}catch(t){n(t)}return{unsubscribe:()=>{this.observers.delete(i)}}}start(){if(this._processingStatus===u.Running)return this;this._syncSnapshot&&this.subscribe({next:t=>{"active"===t.status&&this._parent.send({type:`xstate.snapshot.${this.id}`,snapshot:t})},error:()=>{}}),this.system._register(this.sessionId,this),this._systemId&&this.system._set(this._systemId,this),this._processingStatus=u.Running;const t={type:"xstate.init",input:this.options.input};this.system._sendInspectionEvent({type:"@xstate.event",sourceRef:this._parent,actorRef:this,event:t});switch(this._state.status){case"done":this.update(this._state,t);case"error":return this}if(this.logic.start)try{this.logic.start(this._state,this._actorScope)}catch(t){return this._stopProcedure(),this._error(t),this._parent?.send(i(this.id,t)),this}return this.update(this._state,t),this.options.devTools&&this.attachDevTools(),this.mailbox.start(),this}_process(t){let s,r;try{s=this.logic.transition(this._state,t,this._actorScope)}catch(t){r={err:t}}if(r){const{err:t}=r;return this._stopProcedure(),this._error(t),void this._parent?.send(i(this.id,t))}this.update(s,t),t.type===e&&(this._stopProcedure(),this._complete())}_stop(){return this._processingStatus===u.Stopped?this:(this.mailbox.clear(),this._processingStatus===u.NotStarted?(this._processingStatus=u.Stopped,this):(this.mailbox.enqueue({type:e}),this))}stop(){if(this._parent)throw new Error("A non-root actor cannot be stopped directly.");return this._stop()}_complete(){for(const t of this.observers)try{t.complete?.()}catch(t){n(t)}this.observers.clear()}_error(t){if(!this.observers.size)return void(this._parent||n(t));let s=!1;for(const e of this.observers){const i=e.error;s||=!i;try{i?.(t)}catch(t){n(t)}}this.observers.clear(),s&&n(t)}_stopProcedure(){if(this._processingStatus!==u.Running)return this;for(const t of Object.keys(this.delayedEventsMap))this.clock.clearTimeout(this.delayedEventsMap[t]);return this.mailbox.clear(),this.mailbox=new s(this._process.bind(this)),this._processingStatus=u.Stopped,this.system._unregister(this),this}_send(t){this._processingStatus!==u.Stopped&&this.mailbox.enqueue(t)}send(t){this.system._relay(void 0,this,t)}delaySend(t){const{event:s,id:e,delay:i}=t,r=this.clock.setTimeout((()=>{this.system._relay(this,t.to??this,s)}),i);e&&(this.delayedEventsMap[e]=r)}cancel(t){this.clock.clearTimeout(this.delayedEventsMap[t]),delete this.delayedEventsMap[t]}attachDevTools(){const{devTools:t}=this.options;if(t){("function"==typeof t?t:o)(this)}}toJSON(){return{xstate$$type:1,id:this.id}}getPersistedState(t){return this.logic.getPersistedState(this._state,t)}[a](){return this}getSnapshot(){return this._state}}function _(t,s){return{config:t,transition:(s,e,i)=>({...s,context:t(s.context,e,i)}),getInitialState:(t,e)=>({status:"active",output:void 0,error:void 0,context:"function"==typeof s?s({input:e}):s}),getPersistedState:t=>t,restoreState:t=>t}}const l="$$xstate.resolve",v="$$xstate.reject";const f=_((t=>{}),void 0);t.createEmptyActor=function(){return new p(f,t);var t},t.fromCallback=function(t){return{config:t,start:(t,{self:s,system:e})=>{e._relay(s,s,{type:"xstate.create"})},transition:(s,i,{self:r,system:o})=>{if("xstate.create"===i.type){const e=t=>{"stopped"!==s.status&&r._parent&&o._relay(r,r._parent,t)},i=t=>{s._receivers.add(t)};return s._dispose=t({input:s.input,system:o,self:r,sendBack:e,receive:i}),s}return i.type===e?("function"==typeof(s={...s,status:"stopped",error:void 0})._dispose&&s._dispose(),s):(s._receivers.forEach((t=>t(i))),s)},getInitialState:(t,s)=>({status:"active",output:void 0,error:void 0,input:s,_receivers:new Set,_dispose:void 0}),getPersistedState:({_dispose:t,_receivers:s,...e})=>e,restoreState:t=>({_receivers:new Set,_dispose:void 0,...t})}},t.fromEventObservable=function(t){const s="$$xstate.error",i="$$xstate.complete";return{config:t,transition:(t,r)=>{if("active"!==t.status)return t;switch(r.type){case s:return{...t,status:"error",error:r.data,input:void 0,_subscription:void 0};case i:return{...t,status:"done",input:void 0,_subscription:void 0};case e:return t._subscription.unsubscribe(),{...t,status:"stopped",input:void 0,_subscription:void 0};default:return t}},getInitialState:(t,s)=>({status:"active",output:void 0,error:void 0,context:void 0,input:s,_subscription:void 0}),start:(e,{self:r,system:o})=>{"done"!==e.status&&(e._subscription=t({input:e.input,system:o,self:r}).subscribe({next:t=>{r._parent&&o._relay(r,r._parent,t)},error:t=>{o._relay(r,r,{type:s,data:t})},complete:()=>{o._relay(r,r,{type:i})}}))},getPersistedState:({_subscription:t,...s})=>s,restoreState:t=>({...t,_subscription:void 0})}},t.fromObservable=function(t){const s="$$xstate.next",i="$$xstate.error",r="$$xstate.complete";return{config:t,transition:(t,o,{self:n,id:a,defer:c,system:h})=>{if("active"!==t.status)return t;switch(o.type){case s:return{...t,context:o.data};case i:return{...t,status:"error",error:o.data,input:void 0,_subscription:void 0};case r:return{...t,status:"done",input:void 0,_subscription:void 0};case e:return t._subscription.unsubscribe(),{...t,status:"stopped",input:void 0,_subscription:void 0};default:return t}},getInitialState:(t,s)=>({status:"active",output:void 0,error:void 0,context:void 0,input:s,_subscription:void 0}),start:(e,{self:o,system:n})=>{"done"!==e.status&&(e._subscription=t({input:e.input,system:n,self:o}).subscribe({next:t=>{n._relay(o,o,{type:s,data:t})},error:t=>{n._relay(o,o,{type:i,data:t})},complete:()=>{n._relay(o,o,{type:r})}}))},getPersistedState:({_subscription:t,...s})=>s,restoreState:t=>({...t,_subscription:void 0})}},t.fromPromise=function(t){return{config:t,transition:(t,s)=>{if("active"!==t.status)return t;switch(s.type){case l:{const e=s.data;return{...t,status:"done",output:e,input:void 0}}case v:return{...t,status:"error",error:s.data,input:void 0};case e:return{...t,status:"stopped",input:void 0};default:return t}},start:(s,{self:e,system:i})=>{if("active"!==s.status)return;Promise.resolve(t({input:s.input,system:i,self:e})).then((t=>{"active"===e.getSnapshot().status&&i._relay(e,e,{type:l,data:t})}),(t=>{"active"===e.getSnapshot().status&&i._relay(e,e,{type:v,data:t})}))},getInitialState:(t,s)=>({status:"active",output:void 0,error:void 0,input:s}),getPersistedState:t=>t,restoreState:t=>t}},t.fromTransition=_,Object.defineProperty(t,"__esModule",{value:!0})}));
2
2
  //# sourceMappingURL=xstate-actors.umd.min.js.map