xstate 5.0.0-beta.29 → 5.0.0-beta.31

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 (52) 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 +100 -104
  8. package/actors/dist/xstate-actors.development.cjs.js +100 -104
  9. package/actors/dist/xstate-actors.development.esm.js +100 -104
  10. package/actors/dist/xstate-actors.esm.js +100 -104
  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/Machine.d.ts +2 -2
  14. package/dist/declarations/src/State.d.ts +4 -6
  15. package/dist/declarations/src/StateMachine.d.ts +28 -21
  16. package/dist/declarations/src/StateNode.d.ts +3 -3
  17. package/dist/declarations/src/actions/stop.d.ts +1 -1
  18. package/dist/declarations/src/actors/callback.d.ts +8 -8
  19. package/dist/declarations/src/actors/index.d.ts +3 -3
  20. package/dist/declarations/src/actors/observable.d.ts +12 -13
  21. package/dist/declarations/src/actors/promise.d.ts +11 -14
  22. package/dist/declarations/src/actors/transition.d.ts +10 -7
  23. package/dist/declarations/src/index.d.ts +1 -1
  24. package/dist/declarations/src/interpreter.d.ts +4 -4
  25. package/dist/declarations/src/spawn.d.ts +3 -0
  26. package/dist/declarations/src/stateUtils.d.ts +5 -6
  27. package/dist/declarations/src/types.d.ts +74 -69
  28. package/dist/declarations/src/utils.d.ts +4 -4
  29. package/dist/{interpreter-c357bc50.cjs.js → interpreter-05e11c15.cjs.js} +11 -13
  30. package/dist/{interpreter-e2c6a579.development.cjs.js → interpreter-a2236840.development.cjs.js} +12 -14
  31. package/dist/{interpreter-498891b2.esm.js → interpreter-d5fa7ce0.esm.js} +11 -13
  32. package/dist/{interpreter-6e7909c8.development.esm.js → interpreter-e4d2487f.development.esm.js} +12 -14
  33. package/dist/{raise-59f2c242.esm.js → raise-6a68d0cc.esm.js} +61 -32
  34. package/dist/{raise-e778a828.development.esm.js → raise-6fbd4513.development.esm.js} +61 -32
  35. package/dist/{raise-03e57569.cjs.js → raise-90808d65.cjs.js} +61 -32
  36. package/dist/{raise-f751dfac.development.cjs.js → raise-b4bfe138.development.cjs.js} +61 -32
  37. package/dist/{send-f53778f6.development.cjs.js → send-4163d2af.development.cjs.js} +52 -20
  38. package/dist/{send-51717e53.cjs.js → send-72e85cc6.cjs.js} +52 -20
  39. package/dist/{send-42c83fb2.development.esm.js → send-7baeedcb.development.esm.js} +52 -20
  40. package/dist/{send-fff224db.esm.js → send-e5f0f3f6.esm.js} +52 -20
  41. package/dist/xstate.cjs.js +15 -24
  42. package/dist/xstate.development.cjs.js +18 -24
  43. package/dist/xstate.development.esm.js +21 -27
  44. package/dist/xstate.esm.js +18 -27
  45. package/dist/xstate.umd.min.js +1 -1
  46. package/dist/xstate.umd.min.js.map +1 -1
  47. package/guards/dist/xstate-guards.cjs.js +2 -2
  48. package/guards/dist/xstate-guards.development.cjs.js +2 -2
  49. package/guards/dist/xstate-guards.development.esm.js +2 -2
  50. package/guards/dist/xstate-guards.esm.js +2 -2
  51. package/guards/dist/xstate-guards.umd.min.js.map +1 -1
  52. package/package.json +1 -1
@@ -1,5 +1,5 @@
1
- import { j as cloneState, e as evaluateGuard } from './raise-e778a828.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-6e7909c8.development.esm.js';
1
+ import { j as cloneState, e as evaluateGuard } from './raise-6fbd4513.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-e4d2487f.development.esm.js';
3
3
 
4
4
  function createSpawner(actorContext, {
5
5
  machine,
@@ -17,7 +17,7 @@ function createSpawner(actorContext, {
17
17
  const input = 'input' in options ? options.input : referenced.input;
18
18
 
19
19
  // TODO: this should also receive `src`
20
- const actor = createActor(referenced.src, {
20
+ const actorRef = createActor(referenced.src, {
21
21
  id: options.id,
22
22
  parent: actorContext.self,
23
23
  input: typeof input === 'function' ? input({
@@ -27,16 +27,48 @@ function createSpawner(actorContext, {
27
27
  }) : input,
28
28
  systemId
29
29
  });
30
- spawnedChildren[actor.id] = actor;
31
- return actor;
30
+ spawnedChildren[actorRef.id] = actorRef;
31
+ if (options.syncSnapshot) {
32
+ actorRef.subscribe({
33
+ next: snapshot => {
34
+ if (snapshot.status === 'active') {
35
+ actorContext.self.send({
36
+ type: `xstate.snapshot.${actorRef.id}`,
37
+ snapshot
38
+ });
39
+ }
40
+ },
41
+ error: () => {
42
+ /* TODO */
43
+ }
44
+ });
45
+ }
46
+ return actorRef;
32
47
  } else {
33
48
  // TODO: this should also receive `src`
34
- return createActor(src, {
49
+ const actorRef = createActor(src, {
35
50
  id: options.id,
36
51
  parent: actorContext.self,
37
52
  input: options.input,
38
53
  systemId
39
54
  });
55
+ if (options.syncSnapshot) {
56
+ actorRef.subscribe({
57
+ next: snapshot => {
58
+ if (snapshot.status === 'active') {
59
+ actorContext.self.send({
60
+ type: `xstate.snapshot.${actorRef.id}`,
61
+ snapshot,
62
+ id: actorRef.id
63
+ });
64
+ }
65
+ },
66
+ error: () => {
67
+ /* TODO */
68
+ }
69
+ });
70
+ }
71
+ return actorRef;
40
72
  }
41
73
  };
42
74
  return (src, options) => {
@@ -57,7 +89,7 @@ function createSpawner(actorContext, {
57
89
  };
58
90
  }
59
91
 
60
- function resolve$4(actorContext, state, actionArgs, {
92
+ function resolveAssign(actorContext, state, actionArgs, {
61
93
  assignment
62
94
  }) {
63
95
  if (!state.context) {
@@ -103,11 +135,11 @@ function assign(assignment) {
103
135
  }
104
136
  assign.type = 'xstate.assign';
105
137
  assign.assignment = assignment;
106
- assign.resolve = resolve$4;
138
+ assign.resolve = resolveAssign;
107
139
  return assign;
108
140
  }
109
141
 
110
- function resolve$3(_, state, actionArgs, {
142
+ function resolveChoose(_, state, actionArgs, {
111
143
  branches
112
144
  }) {
113
145
  const matchedActions = branches.find(condition => {
@@ -123,11 +155,11 @@ function choose(branches) {
123
155
  }
124
156
  choose.type = 'xstate.choose';
125
157
  choose.branches = branches;
126
- choose.resolve = resolve$3;
158
+ choose.resolve = resolveChoose;
127
159
  return choose;
128
160
  }
129
161
 
130
- function resolve$2(_, state, actionArgs, {
162
+ function resolveLog(_, state, actionArgs, {
131
163
  value,
132
164
  label
133
165
  }) {
@@ -136,7 +168,7 @@ function resolve$2(_, state, actionArgs, {
136
168
  label
137
169
  }];
138
170
  }
139
- function execute$1({
171
+ function executeLog({
140
172
  logger
141
173
  }, {
142
174
  value,
@@ -171,12 +203,12 @@ function log(value = ({
171
203
  log.type = 'xstate.log';
172
204
  log.value = value;
173
205
  log.label = label;
174
- log.resolve = resolve$2;
175
- log.execute = execute$1;
206
+ log.resolve = resolveLog;
207
+ log.execute = executeLog;
176
208
  return log;
177
209
  }
178
210
 
179
- function resolve$1(_, state, args, {
211
+ function resolvePure(_, state, args, {
180
212
  get
181
213
  }) {
182
214
  return [state, undefined, toArray(get({
@@ -192,7 +224,7 @@ function pure(getActions) {
192
224
  }
193
225
  pure.type = 'xstate.pure';
194
226
  pure.get = getActions;
195
- pure.resolve = resolve$1;
227
+ pure.resolve = resolvePure;
196
228
  return pure;
197
229
  }
198
230
 
@@ -231,7 +263,7 @@ let SpecialTargets = /*#__PURE__*/function (SpecialTargets) {
231
263
  return SpecialTargets;
232
264
  }({});
233
265
 
234
- function resolve(actorContext, state, args, {
266
+ function resolveSendTo(actorContext, state, args, {
235
267
  to,
236
268
  event: eventOrExpr,
237
269
  id,
@@ -276,7 +308,7 @@ function resolve(actorContext, state, args, {
276
308
  delay: resolvedDelay
277
309
  }];
278
310
  }
279
- function execute(actorContext, params) {
311
+ function executeSendTo(actorContext, params) {
280
312
  if (typeof params.delay === 'number') {
281
313
  actorContext.self.delaySend(params);
282
314
  return;
@@ -309,8 +341,8 @@ function sendTo(to, eventOrExpr, options) {
309
341
  sendTo.event = eventOrExpr;
310
342
  sendTo.id = options?.id;
311
343
  sendTo.delay = options?.delay;
312
- sendTo.resolve = resolve;
313
- sendTo.execute = execute;
344
+ sendTo.resolve = resolveSendTo;
345
+ sendTo.execute = executeSendTo;
314
346
  return sendTo;
315
347
  }
316
348
 
@@ -1,5 +1,5 @@
1
- import { j as cloneState, e as evaluateGuard } from './raise-59f2c242.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-498891b2.esm.js';
1
+ import { j as cloneState, e as evaluateGuard } from './raise-6a68d0cc.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-d5fa7ce0.esm.js';
3
3
 
4
4
  function createSpawner(actorContext, {
5
5
  machine,
@@ -17,7 +17,7 @@ function createSpawner(actorContext, {
17
17
  const input = 'input' in options ? options.input : referenced.input;
18
18
 
19
19
  // TODO: this should also receive `src`
20
- const actor = createActor(referenced.src, {
20
+ const actorRef = createActor(referenced.src, {
21
21
  id: options.id,
22
22
  parent: actorContext.self,
23
23
  input: typeof input === 'function' ? input({
@@ -27,16 +27,48 @@ function createSpawner(actorContext, {
27
27
  }) : input,
28
28
  systemId
29
29
  });
30
- spawnedChildren[actor.id] = actor;
31
- return actor;
30
+ spawnedChildren[actorRef.id] = actorRef;
31
+ if (options.syncSnapshot) {
32
+ actorRef.subscribe({
33
+ next: snapshot => {
34
+ if (snapshot.status === 'active') {
35
+ actorContext.self.send({
36
+ type: `xstate.snapshot.${actorRef.id}`,
37
+ snapshot
38
+ });
39
+ }
40
+ },
41
+ error: () => {
42
+ /* TODO */
43
+ }
44
+ });
45
+ }
46
+ return actorRef;
32
47
  } else {
33
48
  // TODO: this should also receive `src`
34
- return createActor(src, {
49
+ const actorRef = createActor(src, {
35
50
  id: options.id,
36
51
  parent: actorContext.self,
37
52
  input: options.input,
38
53
  systemId
39
54
  });
55
+ if (options.syncSnapshot) {
56
+ actorRef.subscribe({
57
+ next: snapshot => {
58
+ if (snapshot.status === 'active') {
59
+ actorContext.self.send({
60
+ type: `xstate.snapshot.${actorRef.id}`,
61
+ snapshot,
62
+ id: actorRef.id
63
+ });
64
+ }
65
+ },
66
+ error: () => {
67
+ /* TODO */
68
+ }
69
+ });
70
+ }
71
+ return actorRef;
40
72
  }
41
73
  };
42
74
  return (src, options) => {
@@ -57,7 +89,7 @@ function createSpawner(actorContext, {
57
89
  };
58
90
  }
59
91
 
60
- function resolve$4(actorContext, state, actionArgs, {
92
+ function resolveAssign(actorContext, state, actionArgs, {
61
93
  assignment
62
94
  }) {
63
95
  if (!state.context) {
@@ -100,11 +132,11 @@ function assign(assignment) {
100
132
  }
101
133
  assign.type = 'xstate.assign';
102
134
  assign.assignment = assignment;
103
- assign.resolve = resolve$4;
135
+ assign.resolve = resolveAssign;
104
136
  return assign;
105
137
  }
106
138
 
107
- function resolve$3(_, state, actionArgs, {
139
+ function resolveChoose(_, state, actionArgs, {
108
140
  branches
109
141
  }) {
110
142
  const matchedActions = branches.find(condition => {
@@ -117,11 +149,11 @@ function choose(branches) {
117
149
  }
118
150
  choose.type = 'xstate.choose';
119
151
  choose.branches = branches;
120
- choose.resolve = resolve$3;
152
+ choose.resolve = resolveChoose;
121
153
  return choose;
122
154
  }
123
155
 
124
- function resolve$2(_, state, actionArgs, {
156
+ function resolveLog(_, state, actionArgs, {
125
157
  value,
126
158
  label
127
159
  }) {
@@ -130,7 +162,7 @@ function resolve$2(_, state, actionArgs, {
130
162
  label
131
163
  }];
132
164
  }
133
- function execute$1({
165
+ function executeLog({
134
166
  logger
135
167
  }, {
136
168
  value,
@@ -162,12 +194,12 @@ function log(value = ({
162
194
  log.type = 'xstate.log';
163
195
  log.value = value;
164
196
  log.label = label;
165
- log.resolve = resolve$2;
166
- log.execute = execute$1;
197
+ log.resolve = resolveLog;
198
+ log.execute = executeLog;
167
199
  return log;
168
200
  }
169
201
 
170
- function resolve$1(_, state, args, {
202
+ function resolvePure(_, state, args, {
171
203
  get
172
204
  }) {
173
205
  return [state, undefined, toArray(get({
@@ -180,7 +212,7 @@ function pure(getActions) {
180
212
  }
181
213
  pure.type = 'xstate.pure';
182
214
  pure.get = getActions;
183
- pure.resolve = resolve$1;
215
+ pure.resolve = resolvePure;
184
216
  return pure;
185
217
  }
186
218
 
@@ -219,7 +251,7 @@ let SpecialTargets = /*#__PURE__*/function (SpecialTargets) {
219
251
  return SpecialTargets;
220
252
  }({});
221
253
 
222
- function resolve(actorContext, state, args, {
254
+ function resolveSendTo(actorContext, state, args, {
223
255
  to,
224
256
  event: eventOrExpr,
225
257
  id,
@@ -264,7 +296,7 @@ function resolve(actorContext, state, args, {
264
296
  delay: resolvedDelay
265
297
  }];
266
298
  }
267
- function execute(actorContext, params) {
299
+ function executeSendTo(actorContext, params) {
268
300
  if (typeof params.delay === 'number') {
269
301
  actorContext.self.delaySend(params);
270
302
  return;
@@ -294,8 +326,8 @@ function sendTo(to, eventOrExpr, options) {
294
326
  sendTo.event = eventOrExpr;
295
327
  sendTo.id = options?.id;
296
328
  sendTo.delay = options?.delay;
297
- sendTo.resolve = resolve;
298
- sendTo.execute = execute;
329
+ sendTo.resolve = resolveSendTo;
330
+ sendTo.execute = executeSendTo;
299
331
  return sendTo;
300
332
  }
301
333
 
@@ -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-c357bc50.cjs.js');
7
- var guards_dist_xstateGuards = require('./raise-03e57569.cjs.js');
8
- var send = require('./send-51717e53.cjs.js');
6
+ var interpreter = require('./interpreter-05e11c15.cjs.js');
7
+ var guards_dist_xstateGuards = require('./raise-90808d65.cjs.js');
8
+ var send = require('./send-72e85cc6.cjs.js');
9
9
  require('../dev/dist/xstate-dev.cjs.js');
10
10
 
11
11
  class SimulatedClock {
@@ -187,7 +187,7 @@ class StateNode {
187
187
  this.entry = interpreter.toArray(this.config.entry).slice();
188
188
  this.exit = interpreter.toArray(this.config.exit).slice();
189
189
  this.meta = this.config.meta;
190
- this.output = this.type === 'final' ? this.config.output : undefined;
190
+ this.output = this.type === 'final' || !this.parent ? this.config.output : undefined;
191
191
  this.tags = interpreter.toArray(config.tags).slice();
192
192
  }
193
193
  _initialize() {
@@ -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 */
@@ -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-e2c6a579.development.cjs.js');
7
- var guards_dist_xstateGuards = require('./raise-f751dfac.development.cjs.js');
8
- var send = require('./send-f53778f6.development.cjs.js');
6
+ var interpreter = require('./interpreter-a2236840.development.cjs.js');
7
+ var guards_dist_xstateGuards = require('./raise-b4bfe138.development.cjs.js');
8
+ var send = require('./send-4163d2af.development.cjs.js');
9
9
  require('../dev/dist/xstate-dev.development.cjs.js');
10
10
 
11
11
  class SimulatedClock {
@@ -187,7 +187,7 @@ class StateNode {
187
187
  this.entry = interpreter.toArray(this.config.entry).slice();
188
188
  this.exit = interpreter.toArray(this.config.exit).slice();
189
189
  this.meta = this.config.meta;
190
- this.output = this.type === 'final' ? this.config.output : undefined;
190
+ this.output = this.type === 'final' || !this.parent ? this.config.output : undefined;
191
191
  this.tags = interpreter.toArray(config.tags).slice();
192
192
  }
193
193
  _initialize() {
@@ -415,6 +415,9 @@ class StateMachine {
415
415
  this.root._initialize();
416
416
  this.states = this.root.states; // TODO: remove!
417
417
  this.events = this.root.events;
418
+ if (!this.root.output && Object.values(this.states).some(state => state.type === 'final' && !!state.output)) {
419
+ console.warn('Missing `machine.output` declaration (top-level final state with output detected)');
420
+ }
418
421
  }
419
422
 
420
423
  /**
@@ -467,7 +470,7 @@ class StateMachine {
467
470
  ...state,
468
471
  value: guards_dist_xstateGuards.resolveStateValue(this.root, state.value),
469
472
  configuration,
470
- done: guards_dist_xstateGuards.isInFinalState(configuration)
473
+ status: guards_dist_xstateGuards.isInFinalState(configuration) ? 'done' : state.status
471
474
  });
472
475
  }
473
476
  resolveStateValue(stateValue, ...[context]) {
@@ -486,6 +489,7 @@ class StateMachine {
486
489
  // TODO: handle error events in a better way
487
490
  if (interpreter.isErrorActorEvent(event) && !state.nextEvents.some(nextEvent => nextEvent === event.type)) {
488
491
  return guards_dist_xstateGuards.cloneState(state, {
492
+ status: 'error',
489
493
  error: event.data
490
494
  });
491
495
  }
@@ -523,7 +527,8 @@ class StateMachine {
523
527
  context: typeof context !== 'function' && context ? context : {},
524
528
  meta: undefined,
525
529
  configuration: guards_dist_xstateGuards.getInitialConfiguration(this.root),
526
- children: {}
530
+ children: {},
531
+ status: 'active'
527
532
  }));
528
533
  if (typeof context === 'function') {
529
534
  const assignment = ({
@@ -587,21 +592,10 @@ class StateMachine {
587
592
  createState(stateConfig) {
588
593
  return stateConfig instanceof guards_dist_xstateGuards.State ? stateConfig : new guards_dist_xstateGuards.State(stateConfig, this);
589
594
  }
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) {
595
+ restoreState(snapshot, _actorCtx) {
602
596
  const children = {};
603
- Object.keys(state.children).forEach(actorId => {
604
- const actorData = state.children[actorId];
597
+ Object.keys(snapshot.children).forEach(actorId => {
598
+ const actorData = snapshot.children[actorId];
605
599
  const childState = actorData.state;
606
600
  const src = actorData.src;
607
601
  const logic = src ? interpreter.resolveReferencedActor(this.implementations.actors[src])?.src : undefined;
@@ -615,13 +609,13 @@ class StateMachine {
615
609
  });
616
610
  children[actorId] = actorRef;
617
611
  });
618
- const restoredState = this.createState(new guards_dist_xstateGuards.State({
619
- ...state,
612
+ const restoredSnapshot = this.createState(new guards_dist_xstateGuards.State({
613
+ ...snapshot,
620
614
  children
621
615
  }, this));
622
616
 
623
617
  // TODO: DRY this up
624
- restoredState.configuration.forEach(stateNode => {
618
+ restoredSnapshot.configuration.forEach(stateNode => {
625
619
  if (stateNode.invoke) {
626
620
  stateNode.invoke.forEach(invokeConfig => {
627
621
  const {
@@ -643,7 +637,7 @@ class StateMachine {
643
637
  });
644
638
  }
645
639
  });
646
- return restoredState;
640
+ return restoredSnapshot;
647
641
  }
648
642
 
649
643
  /**@deprecated an internal property acting as a "phantom" type, not meant to be used at runtime */
@@ -1,10 +1,10 @@
1
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-6e7909c8.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-6e7909c8.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-e778a828.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-e778a828.development.esm.js';
6
- import { a as assign } from './send-42c83fb2.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-42c83fb2.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-e4d2487f.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-e4d2487f.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-6fbd4513.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-6fbd4513.development.esm.js';
6
+ import { a as assign } from './send-7baeedcb.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-7baeedcb.development.esm.js';
8
8
  import '../dev/dist/xstate-dev.development.esm.js';
9
9
 
10
10
  class SimulatedClock {
@@ -186,7 +186,7 @@ class StateNode {
186
186
  this.entry = toArray(this.config.entry).slice();
187
187
  this.exit = toArray(this.config.exit).slice();
188
188
  this.meta = this.config.meta;
189
- this.output = this.type === 'final' ? this.config.output : undefined;
189
+ this.output = this.type === 'final' || !this.parent ? this.config.output : undefined;
190
190
  this.tags = toArray(config.tags).slice();
191
191
  }
192
192
  _initialize() {
@@ -414,6 +414,9 @@ class StateMachine {
414
414
  this.root._initialize();
415
415
  this.states = this.root.states; // TODO: remove!
416
416
  this.events = this.root.events;
417
+ if (!this.root.output && Object.values(this.states).some(state => state.type === 'final' && !!state.output)) {
418
+ console.warn('Missing `machine.output` declaration (top-level final state with output detected)');
419
+ }
417
420
  }
418
421
 
419
422
  /**
@@ -466,7 +469,7 @@ class StateMachine {
466
469
  ...state,
467
470
  value: resolveStateValue(this.root, state.value),
468
471
  configuration,
469
- done: isInFinalState(configuration)
472
+ status: isInFinalState(configuration) ? 'done' : state.status
470
473
  });
471
474
  }
472
475
  resolveStateValue(stateValue, ...[context]) {
@@ -485,6 +488,7 @@ class StateMachine {
485
488
  // TODO: handle error events in a better way
486
489
  if (isErrorActorEvent(event) && !state.nextEvents.some(nextEvent => nextEvent === event.type)) {
487
490
  return cloneState(state, {
491
+ status: 'error',
488
492
  error: event.data
489
493
  });
490
494
  }
@@ -522,7 +526,8 @@ class StateMachine {
522
526
  context: typeof context !== 'function' && context ? context : {},
523
527
  meta: undefined,
524
528
  configuration: getInitialConfiguration(this.root),
525
- children: {}
529
+ children: {},
530
+ status: 'active'
526
531
  }));
527
532
  if (typeof context === 'function') {
528
533
  const assignment = ({
@@ -586,21 +591,10 @@ class StateMachine {
586
591
  createState(stateConfig) {
587
592
  return stateConfig instanceof State ? stateConfig : new State(stateConfig, this);
588
593
  }
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) {
594
+ restoreState(snapshot, _actorCtx) {
601
595
  const children = {};
602
- Object.keys(state.children).forEach(actorId => {
603
- const actorData = state.children[actorId];
596
+ Object.keys(snapshot.children).forEach(actorId => {
597
+ const actorData = snapshot.children[actorId];
604
598
  const childState = actorData.state;
605
599
  const src = actorData.src;
606
600
  const logic = src ? resolveReferencedActor(this.implementations.actors[src])?.src : undefined;
@@ -614,13 +608,13 @@ class StateMachine {
614
608
  });
615
609
  children[actorId] = actorRef;
616
610
  });
617
- const restoredState = this.createState(new State({
618
- ...state,
611
+ const restoredSnapshot = this.createState(new State({
612
+ ...snapshot,
619
613
  children
620
614
  }, this));
621
615
 
622
616
  // TODO: DRY this up
623
- restoredState.configuration.forEach(stateNode => {
617
+ restoredSnapshot.configuration.forEach(stateNode => {
624
618
  if (stateNode.invoke) {
625
619
  stateNode.invoke.forEach(invokeConfig => {
626
620
  const {
@@ -642,7 +636,7 @@ class StateMachine {
642
636
  });
643
637
  }
644
638
  });
645
- return restoredState;
639
+ return restoredSnapshot;
646
640
  }
647
641
 
648
642
  /**@deprecated an internal property acting as a "phantom" type, not meant to be used at runtime */