xstate 5.0.0-beta.28 → 5.0.0-beta.30

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 (60) hide show
  1. package/actions/dist/xstate-actions.cjs.js +3 -3
  2. package/actions/dist/xstate-actions.development.cjs.js +3 -3
  3. package/actions/dist/xstate-actions.development.esm.js +3 -3
  4. package/actions/dist/xstate-actions.esm.js +3 -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 +104 -139
  8. package/actors/dist/xstate-actors.cjs.mjs +1 -3
  9. package/actors/dist/xstate-actors.development.cjs.js +104 -139
  10. package/actors/dist/xstate-actors.development.cjs.mjs +1 -3
  11. package/actors/dist/xstate-actors.development.esm.js +105 -138
  12. package/actors/dist/xstate-actors.esm.js +105 -138
  13. package/actors/dist/xstate-actors.umd.min.js +1 -1
  14. package/actors/dist/xstate-actors.umd.min.js.map +1 -1
  15. package/dist/declarations/src/State.d.ts +4 -6
  16. package/dist/declarations/src/StateMachine.d.ts +28 -21
  17. package/dist/declarations/src/StateNode.d.ts +1 -1
  18. package/dist/declarations/src/actions/assign.d.ts +4 -4
  19. package/dist/declarations/src/actions/cancel.d.ts +4 -4
  20. package/dist/declarations/src/actions/choose.d.ts +3 -3
  21. package/dist/declarations/src/actions/log.d.ts +4 -4
  22. package/dist/declarations/src/actions/pure.d.ts +1 -1
  23. package/dist/declarations/src/actions/raise.d.ts +2 -2
  24. package/dist/declarations/src/actions/send.d.ts +7 -7
  25. package/dist/declarations/src/actions/stop.d.ts +4 -4
  26. package/dist/declarations/src/actors/callback.d.ts +8 -8
  27. package/dist/declarations/src/actors/index.d.ts +3 -5
  28. package/dist/declarations/src/actors/observable.d.ts +12 -13
  29. package/dist/declarations/src/actors/promise.d.ts +11 -14
  30. package/dist/declarations/src/actors/transition.d.ts +10 -7
  31. package/dist/declarations/src/index.d.ts +1 -1
  32. package/dist/declarations/src/interpreter.d.ts +4 -4
  33. package/dist/declarations/src/stateUtils.d.ts +5 -6
  34. package/dist/declarations/src/types.d.ts +92 -70
  35. package/dist/{interpreter-a1432c7d.development.cjs.js → interpreter-7f1dc557.development.cjs.js} +9 -30
  36. package/dist/{interpreter-a77bb0ec.development.esm.js → interpreter-945c4b96.development.esm.js} +10 -28
  37. package/dist/{interpreter-672794ae.cjs.js → interpreter-a2c1e529.cjs.js} +9 -30
  38. package/dist/{interpreter-b5203bcb.esm.js → interpreter-b8f53c4b.esm.js} +10 -28
  39. package/dist/{raise-b9c9a234.esm.js → raise-0b7dde8b.esm.js} +13 -11
  40. package/dist/{raise-a60c9290.development.esm.js → raise-6e4f5cf7.development.esm.js} +13 -11
  41. package/dist/{raise-74b72ca5.development.cjs.js → raise-7cae872b.development.cjs.js} +13 -11
  42. package/dist/{raise-436a57a2.cjs.js → raise-e79b1f86.cjs.js} +13 -11
  43. package/dist/{send-e8b55d00.development.cjs.js → send-19a256f0.development.cjs.js} +2 -2
  44. package/dist/{send-e63b7b83.development.esm.js → send-a1d772da.development.esm.js} +2 -2
  45. package/dist/{send-35e1a689.cjs.js → send-e7063201.cjs.js} +2 -2
  46. package/dist/{send-4192e7bc.esm.js → send-f4fb3ba5.esm.js} +2 -2
  47. package/dist/xstate.cjs.js +20 -31
  48. package/dist/xstate.cjs.mjs +0 -2
  49. package/dist/xstate.development.cjs.js +20 -31
  50. package/dist/xstate.development.cjs.mjs +0 -2
  51. package/dist/xstate.development.esm.js +24 -33
  52. package/dist/xstate.esm.js +24 -33
  53. package/dist/xstate.umd.min.js +1 -1
  54. package/dist/xstate.umd.min.js.map +1 -1
  55. package/guards/dist/xstate-guards.cjs.js +2 -2
  56. package/guards/dist/xstate-guards.development.cjs.js +2 -2
  57. package/guards/dist/xstate-guards.development.esm.js +2 -2
  58. package/guards/dist/xstate-guards.esm.js +2 -2
  59. package/guards/dist/xstate-guards.umd.min.js.map +1 -1
  60. package/package.json +1 -1
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var interpreter = require('./interpreter-672794ae.cjs.js');
3
+ var interpreter = require('./interpreter-a2c1e529.cjs.js');
4
4
 
5
5
  const cache = new WeakMap();
6
6
  function memo(object, key, fn) {
@@ -892,7 +892,7 @@ function microstepProcedure(transitions, currentState, mutConfiguration, event,
892
892
  historyValue,
893
893
  _internalQueue: internalQueue,
894
894
  context: nextState.context,
895
- done,
895
+ status: done ? 'done' : currentState.status,
896
896
  output,
897
897
  children: nextState.children
898
898
  });
@@ -1121,7 +1121,7 @@ function macrostep(state, event, actorCtx) {
1121
1121
  nextState = microstep(transitions, state, actorCtx, nextEvent, false);
1122
1122
  states.push(nextState);
1123
1123
  }
1124
- while (!nextState.done) {
1124
+ while (nextState.status === 'active') {
1125
1125
  let enabledTransitions = selectEventlessTransitions(nextState, nextEvent);
1126
1126
  if (!enabledTransitions.length) {
1127
1127
  if (!nextState._internalQueue.length) {
@@ -1138,7 +1138,7 @@ function macrostep(state, event, actorCtx) {
1138
1138
  states.push(nextState);
1139
1139
  }
1140
1140
  }
1141
- if (nextState.done) {
1141
+ if (nextState.status !== 'active') {
1142
1142
  // Perform the stop step to ensure that child actors are stopped
1143
1143
  stopStep(nextEvent, nextState, actorCtx);
1144
1144
  }
@@ -1231,7 +1231,8 @@ class State {
1231
1231
  meta: {},
1232
1232
  configuration: [],
1233
1233
  // TODO: fix,
1234
- children: {}
1234
+ children: {},
1235
+ status: 'active'
1235
1236
  }, machine);
1236
1237
  }
1237
1238
  return stateValue;
@@ -1242,7 +1243,8 @@ class State {
1242
1243
  context,
1243
1244
  meta: undefined,
1244
1245
  configuration: Array.from(configuration),
1245
- children: {}
1246
+ children: {},
1247
+ status: 'active'
1246
1248
  }, machine);
1247
1249
  }
1248
1250
 
@@ -1255,8 +1257,7 @@ class State {
1255
1257
  this.machine = machine;
1256
1258
  this.tags = void 0;
1257
1259
  this.value = void 0;
1258
- this.done = void 0;
1259
- this.output = void 0;
1260
+ this.status = void 0;
1260
1261
  this.error = void 0;
1261
1262
  this.context = void 0;
1262
1263
  this.historyValue = {};
@@ -1272,7 +1273,7 @@ class State {
1272
1273
  this.children = config.children;
1273
1274
  this.value = getStateValue(machine.root, this.configuration);
1274
1275
  this.tags = new Set(interpreter.flatten(this.configuration.map(sn => sn.tags)));
1275
- this.done = config.done ?? false;
1276
+ this.status = config.status;
1276
1277
  this.output = config.output;
1277
1278
  this.error = config.error;
1278
1279
  }
@@ -1367,9 +1368,10 @@ function getPersistedState(state) {
1367
1368
  } = state;
1368
1369
  const childrenJson = {};
1369
1370
  for (const id in children) {
1371
+ const child = children[id];
1370
1372
  childrenJson[id] = {
1371
- state: children[id].getPersistedState?.(),
1372
- src: children[id].src
1373
+ state: child.getPersistedState?.(),
1374
+ src: child.src
1373
1375
  };
1374
1376
  }
1375
1377
  return {
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
- var guards_dist_xstateGuards = require('./raise-74b72ca5.development.cjs.js');
4
- var interpreter = require('./interpreter-a1432c7d.development.cjs.js');
3
+ var guards_dist_xstateGuards = require('./raise-7cae872b.development.cjs.js');
4
+ var interpreter = require('./interpreter-7f1dc557.development.cjs.js');
5
5
 
6
6
  function createSpawner(actorContext, {
7
7
  machine,
@@ -1,5 +1,5 @@
1
- import { j as cloneState, e as evaluateGuard } from './raise-a60c9290.development.esm.js';
2
- import { f as ActorStatus, l as createErrorActorEvent, r as resolveReferencedActor, d as createActor, t as toArray, C as XSTATE_ERROR } from './interpreter-a77bb0ec.development.esm.js';
1
+ import { j as cloneState, e as evaluateGuard } from './raise-6e4f5cf7.development.esm.js';
2
+ import { f as ActorStatus, k as createErrorActorEvent, r as resolveReferencedActor, d as createActor, t as toArray, y as XSTATE_ERROR } from './interpreter-945c4b96.development.esm.js';
3
3
 
4
4
  function createSpawner(actorContext, {
5
5
  machine,
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
- var guards_dist_xstateGuards = require('./raise-436a57a2.cjs.js');
4
- var interpreter = require('./interpreter-672794ae.cjs.js');
3
+ var guards_dist_xstateGuards = require('./raise-e79b1f86.cjs.js');
4
+ var interpreter = require('./interpreter-a2c1e529.cjs.js');
5
5
 
6
6
  function createSpawner(actorContext, {
7
7
  machine,
@@ -1,5 +1,5 @@
1
- import { j as cloneState, e as evaluateGuard } from './raise-b9c9a234.esm.js';
2
- import { f as ActorStatus, l as createErrorActorEvent, r as resolveReferencedActor, d as createActor, t as toArray, C as XSTATE_ERROR } from './interpreter-b5203bcb.esm.js';
1
+ import { j as cloneState, e as evaluateGuard } from './raise-0b7dde8b.esm.js';
2
+ import { f as ActorStatus, k as createErrorActorEvent, r as resolveReferencedActor, d as createActor, t as toArray, y as XSTATE_ERROR } from './interpreter-b8f53c4b.esm.js';
3
3
 
4
4
  function createSpawner(actorContext, {
5
5
  machine,
@@ -3,9 +3,9 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var actors_dist_xstateActors = require('../actors/dist/xstate-actors.cjs.js');
6
- var interpreter = require('./interpreter-672794ae.cjs.js');
7
- var guards_dist_xstateGuards = require('./raise-436a57a2.cjs.js');
8
- var send = require('./send-35e1a689.cjs.js');
6
+ var interpreter = require('./interpreter-a2c1e529.cjs.js');
7
+ var guards_dist_xstateGuards = require('./raise-e79b1f86.cjs.js');
8
+ var send = require('./send-e7063201.cjs.js');
9
9
  require('../dev/dist/xstate-dev.cjs.js');
10
10
 
11
11
  class SimulatedClock {
@@ -58,7 +58,7 @@ class SimulatedClock {
58
58
  }
59
59
 
60
60
  const EMPTY_OBJECT = {};
61
- const toSerializableActon = action => {
61
+ const toSerializableAction = action => {
62
62
  if (typeof action === 'string') {
63
63
  return {
64
64
  type: action
@@ -212,13 +212,13 @@ class StateNode {
212
212
  initial: this.initial ? {
213
213
  target: this.initial.target,
214
214
  source: this,
215
- actions: this.initial.actions.map(toSerializableActon),
215
+ actions: this.initial.actions.map(toSerializableAction),
216
216
  eventType: null,
217
217
  reenter: false,
218
218
  toJSON: () => ({
219
219
  target: this.initial.target.map(t => `#${t.id}`),
220
220
  source: `#${this.id}`,
221
- actions: this.initial.actions.map(toSerializableActon),
221
+ actions: this.initial.actions.map(toSerializableAction),
222
222
  eventType: null
223
223
  })
224
224
  } : undefined,
@@ -229,10 +229,10 @@ class StateNode {
229
229
  on: this.on,
230
230
  transitions: [...this.transitions.values()].flat().map(t => ({
231
231
  ...t,
232
- actions: t.actions.map(toSerializableActon)
232
+ actions: t.actions.map(toSerializableAction)
233
233
  })),
234
- entry: this.entry.map(toSerializableActon),
235
- exit: this.exit.map(toSerializableActon),
234
+ entry: this.entry.map(toSerializableAction),
235
+ exit: this.exit.map(toSerializableAction),
236
236
  meta: this.meta,
237
237
  order: this.order || -1,
238
238
  output: this.output,
@@ -467,7 +467,7 @@ class StateMachine {
467
467
  ...state,
468
468
  value: guards_dist_xstateGuards.resolveStateValue(this.root, state.value),
469
469
  configuration,
470
- done: guards_dist_xstateGuards.isInFinalState(configuration)
470
+ status: guards_dist_xstateGuards.isInFinalState(configuration) ? 'done' : state.status
471
471
  });
472
472
  }
473
473
  resolveStateValue(stateValue, ...[context]) {
@@ -486,6 +486,7 @@ class StateMachine {
486
486
  // TODO: handle error events in a better way
487
487
  if (interpreter.isErrorActorEvent(event) && !state.nextEvents.some(nextEvent => nextEvent === event.type)) {
488
488
  return guards_dist_xstateGuards.cloneState(state, {
489
+ status: 'error',
489
490
  error: event.data
490
491
  });
491
492
  }
@@ -523,7 +524,8 @@ class StateMachine {
523
524
  context: typeof context !== 'function' && context ? context : {},
524
525
  meta: undefined,
525
526
  configuration: guards_dist_xstateGuards.getInitialConfiguration(this.root),
526
- children: {}
527
+ children: {},
528
+ status: 'active'
527
529
  }));
528
530
  if (typeof context === 'function') {
529
531
  const assignment = ({
@@ -587,21 +589,10 @@ class StateMachine {
587
589
  createState(stateConfig) {
588
590
  return stateConfig instanceof guards_dist_xstateGuards.State ? stateConfig : new guards_dist_xstateGuards.State(stateConfig, this);
589
591
  }
590
- getStatus(state) {
591
- return state.error ? {
592
- status: 'error',
593
- data: state.error
594
- } : state.done ? {
595
- status: 'done',
596
- data: state.output
597
- } : {
598
- status: 'active'
599
- };
600
- }
601
- restoreState(state, _actorCtx) {
592
+ restoreState(snapshot, _actorCtx) {
602
593
  const children = {};
603
- Object.keys(state.children).forEach(actorId => {
604
- const actorData = state.children[actorId];
594
+ Object.keys(snapshot.children).forEach(actorId => {
595
+ const actorData = snapshot.children[actorId];
605
596
  const childState = actorData.state;
606
597
  const src = actorData.src;
607
598
  const logic = src ? interpreter.resolveReferencedActor(this.implementations.actors[src])?.src : undefined;
@@ -615,13 +606,13 @@ class StateMachine {
615
606
  });
616
607
  children[actorId] = actorRef;
617
608
  });
618
- const restoredState = this.createState(new guards_dist_xstateGuards.State({
619
- ...state,
609
+ const restoredSnapshot = this.createState(new guards_dist_xstateGuards.State({
610
+ ...snapshot,
620
611
  children
621
612
  }, this));
622
613
 
623
614
  // TODO: DRY this up
624
- restoredState.configuration.forEach(stateNode => {
615
+ restoredSnapshot.configuration.forEach(stateNode => {
625
616
  if (stateNode.invoke) {
626
617
  stateNode.invoke.forEach(invokeConfig => {
627
618
  const {
@@ -643,7 +634,7 @@ class StateMachine {
643
634
  });
644
635
  }
645
636
  });
646
- return restoredState;
637
+ return restoredSnapshot;
647
638
  }
648
639
 
649
640
  /**@deprecated an internal property acting as a "phantom" type, not meant to be used at runtime */
@@ -740,8 +731,6 @@ exports.fromEventObservable = actors_dist_xstateActors.fromEventObservable;
740
731
  exports.fromObservable = actors_dist_xstateActors.fromObservable;
741
732
  exports.fromPromise = actors_dist_xstateActors.fromPromise;
742
733
  exports.fromTransition = actors_dist_xstateActors.fromTransition;
743
- exports.isActorRef = actors_dist_xstateActors.isActorRef;
744
- exports.toActorRef = actors_dist_xstateActors.toActorRef;
745
734
  exports.Actor = interpreter.Actor;
746
735
  exports.ActorStatus = interpreter.ActorStatus;
747
736
  exports.InterpreterStatus = interpreter.InterpreterStatus;
@@ -23,7 +23,6 @@ export {
23
23
  fromTransition,
24
24
  getStateNodes,
25
25
  interpret,
26
- isActorRef,
27
26
  log,
28
27
  mapState,
29
28
  matchesState,
@@ -36,7 +35,6 @@ export {
36
35
  sendTo,
37
36
  stateIn,
38
37
  stop,
39
- toActorRef,
40
38
  toObserver,
41
39
  waitFor
42
40
  } from "./xstate.cjs.js";
@@ -3,9 +3,9 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var actors_dist_xstateActors = require('../actors/dist/xstate-actors.development.cjs.js');
6
- var interpreter = require('./interpreter-a1432c7d.development.cjs.js');
7
- var guards_dist_xstateGuards = require('./raise-74b72ca5.development.cjs.js');
8
- var send = require('./send-e8b55d00.development.cjs.js');
6
+ var interpreter = require('./interpreter-7f1dc557.development.cjs.js');
7
+ var guards_dist_xstateGuards = require('./raise-7cae872b.development.cjs.js');
8
+ var send = require('./send-19a256f0.development.cjs.js');
9
9
  require('../dev/dist/xstate-dev.development.cjs.js');
10
10
 
11
11
  class SimulatedClock {
@@ -58,7 +58,7 @@ class SimulatedClock {
58
58
  }
59
59
 
60
60
  const EMPTY_OBJECT = {};
61
- const toSerializableActon = action => {
61
+ const toSerializableAction = action => {
62
62
  if (typeof action === 'string') {
63
63
  return {
64
64
  type: action
@@ -212,13 +212,13 @@ class StateNode {
212
212
  initial: this.initial ? {
213
213
  target: this.initial.target,
214
214
  source: this,
215
- actions: this.initial.actions.map(toSerializableActon),
215
+ actions: this.initial.actions.map(toSerializableAction),
216
216
  eventType: null,
217
217
  reenter: false,
218
218
  toJSON: () => ({
219
219
  target: this.initial.target.map(t => `#${t.id}`),
220
220
  source: `#${this.id}`,
221
- actions: this.initial.actions.map(toSerializableActon),
221
+ actions: this.initial.actions.map(toSerializableAction),
222
222
  eventType: null
223
223
  })
224
224
  } : undefined,
@@ -229,10 +229,10 @@ class StateNode {
229
229
  on: this.on,
230
230
  transitions: [...this.transitions.values()].flat().map(t => ({
231
231
  ...t,
232
- actions: t.actions.map(toSerializableActon)
232
+ actions: t.actions.map(toSerializableAction)
233
233
  })),
234
- entry: this.entry.map(toSerializableActon),
235
- exit: this.exit.map(toSerializableActon),
234
+ entry: this.entry.map(toSerializableAction),
235
+ exit: this.exit.map(toSerializableAction),
236
236
  meta: this.meta,
237
237
  order: this.order || -1,
238
238
  output: this.output,
@@ -467,7 +467,7 @@ class StateMachine {
467
467
  ...state,
468
468
  value: guards_dist_xstateGuards.resolveStateValue(this.root, state.value),
469
469
  configuration,
470
- done: guards_dist_xstateGuards.isInFinalState(configuration)
470
+ status: guards_dist_xstateGuards.isInFinalState(configuration) ? 'done' : state.status
471
471
  });
472
472
  }
473
473
  resolveStateValue(stateValue, ...[context]) {
@@ -486,6 +486,7 @@ class StateMachine {
486
486
  // TODO: handle error events in a better way
487
487
  if (interpreter.isErrorActorEvent(event) && !state.nextEvents.some(nextEvent => nextEvent === event.type)) {
488
488
  return guards_dist_xstateGuards.cloneState(state, {
489
+ status: 'error',
489
490
  error: event.data
490
491
  });
491
492
  }
@@ -523,7 +524,8 @@ class StateMachine {
523
524
  context: typeof context !== 'function' && context ? context : {},
524
525
  meta: undefined,
525
526
  configuration: guards_dist_xstateGuards.getInitialConfiguration(this.root),
526
- children: {}
527
+ children: {},
528
+ status: 'active'
527
529
  }));
528
530
  if (typeof context === 'function') {
529
531
  const assignment = ({
@@ -587,21 +589,10 @@ class StateMachine {
587
589
  createState(stateConfig) {
588
590
  return stateConfig instanceof guards_dist_xstateGuards.State ? stateConfig : new guards_dist_xstateGuards.State(stateConfig, this);
589
591
  }
590
- getStatus(state) {
591
- return state.error ? {
592
- status: 'error',
593
- data: state.error
594
- } : state.done ? {
595
- status: 'done',
596
- data: state.output
597
- } : {
598
- status: 'active'
599
- };
600
- }
601
- restoreState(state, _actorCtx) {
592
+ restoreState(snapshot, _actorCtx) {
602
593
  const children = {};
603
- Object.keys(state.children).forEach(actorId => {
604
- const actorData = state.children[actorId];
594
+ Object.keys(snapshot.children).forEach(actorId => {
595
+ const actorData = snapshot.children[actorId];
605
596
  const childState = actorData.state;
606
597
  const src = actorData.src;
607
598
  const logic = src ? interpreter.resolveReferencedActor(this.implementations.actors[src])?.src : undefined;
@@ -615,13 +606,13 @@ class StateMachine {
615
606
  });
616
607
  children[actorId] = actorRef;
617
608
  });
618
- const restoredState = this.createState(new guards_dist_xstateGuards.State({
619
- ...state,
609
+ const restoredSnapshot = this.createState(new guards_dist_xstateGuards.State({
610
+ ...snapshot,
620
611
  children
621
612
  }, this));
622
613
 
623
614
  // TODO: DRY this up
624
- restoredState.configuration.forEach(stateNode => {
615
+ restoredSnapshot.configuration.forEach(stateNode => {
625
616
  if (stateNode.invoke) {
626
617
  stateNode.invoke.forEach(invokeConfig => {
627
618
  const {
@@ -643,7 +634,7 @@ class StateMachine {
643
634
  });
644
635
  }
645
636
  });
646
- return restoredState;
637
+ return restoredSnapshot;
647
638
  }
648
639
 
649
640
  /**@deprecated an internal property acting as a "phantom" type, not meant to be used at runtime */
@@ -743,8 +734,6 @@ exports.fromEventObservable = actors_dist_xstateActors.fromEventObservable;
743
734
  exports.fromObservable = actors_dist_xstateActors.fromObservable;
744
735
  exports.fromPromise = actors_dist_xstateActors.fromPromise;
745
736
  exports.fromTransition = actors_dist_xstateActors.fromTransition;
746
- exports.isActorRef = actors_dist_xstateActors.isActorRef;
747
- exports.toActorRef = actors_dist_xstateActors.toActorRef;
748
737
  exports.Actor = interpreter.Actor;
749
738
  exports.ActorStatus = interpreter.ActorStatus;
750
739
  exports.InterpreterStatus = interpreter.InterpreterStatus;
@@ -23,7 +23,6 @@ export {
23
23
  fromTransition,
24
24
  getStateNodes,
25
25
  interpret,
26
- isActorRef,
27
26
  log,
28
27
  mapState,
29
28
  matchesState,
@@ -36,7 +35,6 @@ export {
36
35
  sendTo,
37
36
  stateIn,
38
37
  stop,
39
- toActorRef,
40
38
  toObserver,
41
39
  waitFor
42
40
  } from "./xstate.development.cjs.js";
@@ -1,10 +1,10 @@
1
- export { createEmptyActor, fromCallback, fromEventObservable, fromObservable, fromPromise, fromTransition, isActorRef, toActorRef } from '../actors/dist/xstate-actors.development.esm.js';
2
- import { S as STATE_DELIMITER, m as mapValues, t as toArray, a as toTransitionConfigArray, N as NULL_EVENT, c as createInvokeId, i as isErrorActorEvent, b as createInitEvent, r as resolveReferencedActor, d as createActor, e as matchesState } from './interpreter-a77bb0ec.development.esm.js';
3
- export { A as Actor, f as ActorStatus, I as InterpreterStatus, d as createActor, g as interpret, e as matchesState, p as pathToStateValue, h as toObserver } from './interpreter-a77bb0ec.development.esm.js';
4
- import { f as formatTransitions, a as formatTransition, m as memo, e as evaluateGuard, g as getDelayedTransitions, b as formatInitialTransition, c as getCandidates, d as getConfiguration, h as getStateNodes, r as resolveStateValue, i as isInFinalState, S as State, j as cloneState, k as macrostep, t as transitionNode, l as getInitialConfiguration, n as resolveActionsAndContext, o as microstep, p as isAtomicStateNode, q as isStateId, s as getStateNodeByPath, u as getPersistedState } from './raise-a60c9290.development.esm.js';
5
- export { S as State, v as and, z as cancel, h as getStateNodes, w as not, x as or, A as raise, y as stateIn, B as stop } from './raise-a60c9290.development.esm.js';
6
- import { a as assign } from './send-e63b7b83.development.esm.js';
7
- export { S as SpecialTargets, a as assign, c as choose, e as escalate, f as forwardTo, l as log, p as pure, s as sendParent, b as sendTo } from './send-e63b7b83.development.esm.js';
1
+ export { createEmptyActor, fromCallback, fromEventObservable, fromObservable, fromPromise, fromTransition } from '../actors/dist/xstate-actors.development.esm.js';
2
+ import { S as STATE_DELIMITER, m as mapValues, t as toArray, a as toTransitionConfigArray, N as NULL_EVENT, c as createInvokeId, i as isErrorActorEvent, b as createInitEvent, r as resolveReferencedActor, d as createActor, e as matchesState } from './interpreter-945c4b96.development.esm.js';
3
+ export { A as Actor, f as ActorStatus, I as InterpreterStatus, d as createActor, g as interpret, e as matchesState, p as pathToStateValue, h as toObserver } from './interpreter-945c4b96.development.esm.js';
4
+ import { f as formatTransitions, a as formatTransition, m as memo, e as evaluateGuard, g as getDelayedTransitions, b as formatInitialTransition, c as getCandidates, d as getConfiguration, h as getStateNodes, r as resolveStateValue, i as isInFinalState, S as State, j as cloneState, k as macrostep, t as transitionNode, l as getInitialConfiguration, n as resolveActionsAndContext, o as microstep, p as isAtomicStateNode, q as isStateId, s as getStateNodeByPath, u as getPersistedState } from './raise-6e4f5cf7.development.esm.js';
5
+ export { S as State, v as and, z as cancel, h as getStateNodes, w as not, x as or, A as raise, y as stateIn, B as stop } from './raise-6e4f5cf7.development.esm.js';
6
+ import { a as assign } from './send-a1d772da.development.esm.js';
7
+ export { S as SpecialTargets, a as assign, c as choose, e as escalate, f as forwardTo, l as log, p as pure, s as sendParent, b as sendTo } from './send-a1d772da.development.esm.js';
8
8
  import '../dev/dist/xstate-dev.development.esm.js';
9
9
 
10
10
  class SimulatedClock {
@@ -57,7 +57,7 @@ class SimulatedClock {
57
57
  }
58
58
 
59
59
  const EMPTY_OBJECT = {};
60
- const toSerializableActon = action => {
60
+ const toSerializableAction = action => {
61
61
  if (typeof action === 'string') {
62
62
  return {
63
63
  type: action
@@ -211,13 +211,13 @@ class StateNode {
211
211
  initial: this.initial ? {
212
212
  target: this.initial.target,
213
213
  source: this,
214
- actions: this.initial.actions.map(toSerializableActon),
214
+ actions: this.initial.actions.map(toSerializableAction),
215
215
  eventType: null,
216
216
  reenter: false,
217
217
  toJSON: () => ({
218
218
  target: this.initial.target.map(t => `#${t.id}`),
219
219
  source: `#${this.id}`,
220
- actions: this.initial.actions.map(toSerializableActon),
220
+ actions: this.initial.actions.map(toSerializableAction),
221
221
  eventType: null
222
222
  })
223
223
  } : undefined,
@@ -228,10 +228,10 @@ class StateNode {
228
228
  on: this.on,
229
229
  transitions: [...this.transitions.values()].flat().map(t => ({
230
230
  ...t,
231
- actions: t.actions.map(toSerializableActon)
231
+ actions: t.actions.map(toSerializableAction)
232
232
  })),
233
- entry: this.entry.map(toSerializableActon),
234
- exit: this.exit.map(toSerializableActon),
233
+ entry: this.entry.map(toSerializableAction),
234
+ exit: this.exit.map(toSerializableAction),
235
235
  meta: this.meta,
236
236
  order: this.order || -1,
237
237
  output: this.output,
@@ -466,7 +466,7 @@ class StateMachine {
466
466
  ...state,
467
467
  value: resolveStateValue(this.root, state.value),
468
468
  configuration,
469
- done: isInFinalState(configuration)
469
+ status: isInFinalState(configuration) ? 'done' : state.status
470
470
  });
471
471
  }
472
472
  resolveStateValue(stateValue, ...[context]) {
@@ -485,6 +485,7 @@ class StateMachine {
485
485
  // TODO: handle error events in a better way
486
486
  if (isErrorActorEvent(event) && !state.nextEvents.some(nextEvent => nextEvent === event.type)) {
487
487
  return cloneState(state, {
488
+ status: 'error',
488
489
  error: event.data
489
490
  });
490
491
  }
@@ -522,7 +523,8 @@ class StateMachine {
522
523
  context: typeof context !== 'function' && context ? context : {},
523
524
  meta: undefined,
524
525
  configuration: getInitialConfiguration(this.root),
525
- children: {}
526
+ children: {},
527
+ status: 'active'
526
528
  }));
527
529
  if (typeof context === 'function') {
528
530
  const assignment = ({
@@ -586,21 +588,10 @@ class StateMachine {
586
588
  createState(stateConfig) {
587
589
  return stateConfig instanceof State ? stateConfig : new State(stateConfig, this);
588
590
  }
589
- getStatus(state) {
590
- return state.error ? {
591
- status: 'error',
592
- data: state.error
593
- } : state.done ? {
594
- status: 'done',
595
- data: state.output
596
- } : {
597
- status: 'active'
598
- };
599
- }
600
- restoreState(state, _actorCtx) {
591
+ restoreState(snapshot, _actorCtx) {
601
592
  const children = {};
602
- Object.keys(state.children).forEach(actorId => {
603
- const actorData = state.children[actorId];
593
+ Object.keys(snapshot.children).forEach(actorId => {
594
+ const actorData = snapshot.children[actorId];
604
595
  const childState = actorData.state;
605
596
  const src = actorData.src;
606
597
  const logic = src ? resolveReferencedActor(this.implementations.actors[src])?.src : undefined;
@@ -614,13 +605,13 @@ class StateMachine {
614
605
  });
615
606
  children[actorId] = actorRef;
616
607
  });
617
- const restoredState = this.createState(new State({
618
- ...state,
608
+ const restoredSnapshot = this.createState(new State({
609
+ ...snapshot,
619
610
  children
620
611
  }, this));
621
612
 
622
613
  // TODO: DRY this up
623
- restoredState.configuration.forEach(stateNode => {
614
+ restoredSnapshot.configuration.forEach(stateNode => {
624
615
  if (stateNode.invoke) {
625
616
  stateNode.invoke.forEach(invokeConfig => {
626
617
  const {
@@ -642,7 +633,7 @@ class StateMachine {
642
633
  });
643
634
  }
644
635
  });
645
- return restoredState;
636
+ return restoredSnapshot;
646
637
  }
647
638
 
648
639
  /**@deprecated an internal property acting as a "phantom" type, not meant to be used at runtime */