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
@@ -1,5 +1,4 @@
1
- import { k as cloneMachineSnapshot, e as evaluateGuard } from './raise-f4ad5a87.development.esm.js';
2
- import { P as ProcessingStatus, h as createErrorActorEvent, r as resolveReferencedActor, d as createActor, t as toArray, v as XSTATE_ERROR } from './interpreter-80eb3bec.development.esm.js';
1
+ import { R as ProcessingStatus, T as createErrorActorEvent, A as resolveReferencedActor, B as createActor, o as cloneMachineSnapshot, e as evaluateGuard, t as toArray, U as XSTATE_ERROR } from './raise-90139fbc.development.esm.js';
3
2
 
4
3
  function createSpawner(actorScope, {
5
4
  machine,
@@ -18,6 +17,7 @@ function createSpawner(actorScope, {
18
17
  const actorRef = createActor(logic, {
19
18
  id: options.id,
20
19
  parent: actorScope.self,
20
+ syncSnapshot: options.syncSnapshot,
21
21
  input: typeof input === 'function' ? input({
22
22
  context,
23
23
  event,
@@ -27,42 +27,16 @@ function createSpawner(actorScope, {
27
27
  systemId
28
28
  });
29
29
  spawnedChildren[actorRef.id] = actorRef;
30
- if (options.syncSnapshot) {
31
- actorRef.subscribe({
32
- next: snapshot => {
33
- if (snapshot.status === 'active') {
34
- actorScope.self.send({
35
- type: `xstate.snapshot.${actorRef.id}`,
36
- snapshot
37
- });
38
- }
39
- },
40
- error: () => {}
41
- });
42
- }
43
30
  return actorRef;
44
31
  } else {
45
32
  const actorRef = createActor(src, {
46
33
  id: options.id,
47
34
  parent: actorScope.self,
35
+ syncSnapshot: options.syncSnapshot,
48
36
  input: options.input,
49
37
  src,
50
38
  systemId
51
39
  });
52
- if (options.syncSnapshot) {
53
- actorRef.subscribe({
54
- next: snapshot => {
55
- if (snapshot.status === 'active') {
56
- actorScope.self.send({
57
- type: `xstate.snapshot.${actorRef.id}`,
58
- snapshot,
59
- id: actorRef.id
60
- });
61
- }
62
- },
63
- error: () => {}
64
- });
65
- }
66
40
  return actorRef;
67
41
  }
68
42
  };
@@ -255,7 +229,7 @@ function pure(getActions) {
255
229
 
256
230
  // TODO: remove once TS fixes this type-widening issue
257
231
 
258
- // TODO: replace with AnyMachineSnapshot
232
+ /** @deprecated use `AnyMachineSnapshot` instead */
259
233
 
260
234
  // TODO: possibly refactor this somehow, use even a simpler type, and maybe even make `machine.options` private or something
261
235
 
@@ -1,5 +1,4 @@
1
- import { k as cloneMachineSnapshot, e as evaluateGuard } from './raise-8dc8e1aa.esm.js';
2
- import { P as ProcessingStatus, h as createErrorActorEvent, r as resolveReferencedActor, d as createActor, t as toArray, v as XSTATE_ERROR } from './interpreter-63c80754.esm.js';
1
+ import { R as ProcessingStatus, T as createErrorActorEvent, A as resolveReferencedActor, B as createActor, o as cloneMachineSnapshot, e as evaluateGuard, t as toArray, U as XSTATE_ERROR } from './raise-2b5a4e4c.esm.js';
3
2
 
4
3
  function createSpawner(actorScope, {
5
4
  machine,
@@ -18,6 +17,7 @@ function createSpawner(actorScope, {
18
17
  const actorRef = createActor(logic, {
19
18
  id: options.id,
20
19
  parent: actorScope.self,
20
+ syncSnapshot: options.syncSnapshot,
21
21
  input: typeof input === 'function' ? input({
22
22
  context,
23
23
  event,
@@ -27,42 +27,16 @@ function createSpawner(actorScope, {
27
27
  systemId
28
28
  });
29
29
  spawnedChildren[actorRef.id] = actorRef;
30
- if (options.syncSnapshot) {
31
- actorRef.subscribe({
32
- next: snapshot => {
33
- if (snapshot.status === 'active') {
34
- actorScope.self.send({
35
- type: `xstate.snapshot.${actorRef.id}`,
36
- snapshot
37
- });
38
- }
39
- },
40
- error: () => {}
41
- });
42
- }
43
30
  return actorRef;
44
31
  } else {
45
32
  const actorRef = createActor(src, {
46
33
  id: options.id,
47
34
  parent: actorScope.self,
35
+ syncSnapshot: options.syncSnapshot,
48
36
  input: options.input,
49
37
  src,
50
38
  systemId
51
39
  });
52
- if (options.syncSnapshot) {
53
- actorRef.subscribe({
54
- next: snapshot => {
55
- if (snapshot.status === 'active') {
56
- actorScope.self.send({
57
- type: `xstate.snapshot.${actorRef.id}`,
58
- snapshot,
59
- id: actorRef.id
60
- });
61
- }
62
- },
63
- error: () => {}
64
- });
65
- }
66
40
  return actorRef;
67
41
  }
68
42
  };
@@ -243,7 +217,7 @@ function pure(getActions) {
243
217
 
244
218
  // TODO: remove once TS fixes this type-widening issue
245
219
 
246
- // TODO: replace with AnyMachineSnapshot
220
+ /** @deprecated use `AnyMachineSnapshot` instead */
247
221
 
248
222
  // TODO: possibly refactor this somehow, use even a simpler type, and maybe even make `machine.options` private or something
249
223
 
@@ -1,7 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var guards_dist_xstateGuards = require('./raise-e0fe5c2d.cjs.js');
4
- var interpreter = require('./interpreter-36d5556e.cjs.js');
3
+ var guards_dist_xstateGuards = require('./raise-fabffc3d.cjs.js');
5
4
 
6
5
  function createSpawner(actorScope, {
7
6
  machine,
@@ -13,13 +12,14 @@ function createSpawner(actorScope, {
13
12
  input
14
13
  } = options;
15
14
  if (typeof src === 'string') {
16
- const logic = interpreter.resolveReferencedActor(machine, src);
15
+ const logic = guards_dist_xstateGuards.resolveReferencedActor(machine, src);
17
16
  if (!logic) {
18
17
  throw new Error(`Actor logic '${src}' not implemented in machine '${machine.id}'`);
19
18
  }
20
- const actorRef = interpreter.createActor(logic, {
19
+ const actorRef = guards_dist_xstateGuards.createActor(logic, {
21
20
  id: options.id,
22
21
  parent: actorScope.self,
22
+ syncSnapshot: options.syncSnapshot,
23
23
  input: typeof input === 'function' ? input({
24
24
  context,
25
25
  event,
@@ -29,42 +29,16 @@ function createSpawner(actorScope, {
29
29
  systemId
30
30
  });
31
31
  spawnedChildren[actorRef.id] = actorRef;
32
- if (options.syncSnapshot) {
33
- actorRef.subscribe({
34
- next: snapshot => {
35
- if (snapshot.status === 'active') {
36
- actorScope.self.send({
37
- type: `xstate.snapshot.${actorRef.id}`,
38
- snapshot
39
- });
40
- }
41
- },
42
- error: () => {}
43
- });
44
- }
45
32
  return actorRef;
46
33
  } else {
47
- const actorRef = interpreter.createActor(src, {
34
+ const actorRef = guards_dist_xstateGuards.createActor(src, {
48
35
  id: options.id,
49
36
  parent: actorScope.self,
37
+ syncSnapshot: options.syncSnapshot,
50
38
  input: options.input,
51
39
  src,
52
40
  systemId
53
41
  });
54
- if (options.syncSnapshot) {
55
- actorRef.subscribe({
56
- next: snapshot => {
57
- if (snapshot.status === 'active') {
58
- actorScope.self.send({
59
- type: `xstate.snapshot.${actorRef.id}`,
60
- snapshot,
61
- id: actorRef.id
62
- });
63
- }
64
- },
65
- error: () => {}
66
- });
67
- }
68
42
  return actorRef;
69
43
  }
70
44
  };
@@ -72,13 +46,13 @@ function createSpawner(actorScope, {
72
46
  const actorRef = spawn(src, options); // TODO: fix types
73
47
  spawnedChildren[actorRef.id] = actorRef;
74
48
  actorScope.defer(() => {
75
- if (actorRef._processingStatus === interpreter.ProcessingStatus.Stopped) {
49
+ if (actorRef._processingStatus === guards_dist_xstateGuards.ProcessingStatus.Stopped) {
76
50
  return;
77
51
  }
78
52
  try {
79
53
  actorRef.start?.();
80
54
  } catch (err) {
81
- actorScope.self.send(interpreter.createErrorActorEvent(actorRef.id, err));
55
+ actorScope.self.send(guards_dist_xstateGuards.createErrorActorEvent(actorRef.id, err));
82
56
  return;
83
57
  }
84
58
  });
@@ -138,7 +112,7 @@ function resolveChoose(_, state, actionArgs, _actionParams, {
138
112
  const matchedActions = branches.find(condition => {
139
113
  return !condition.guard || guards_dist_xstateGuards.evaluateGuard(condition.guard, state.context, actionArgs.event, state);
140
114
  })?.actions;
141
- return [state, undefined, interpreter.toArray(matchedActions)];
115
+ return [state, undefined, guards_dist_xstateGuards.toArray(matchedActions)];
142
116
  }
143
117
  function choose(branches) {
144
118
  function choose(args, params) {
@@ -198,7 +172,7 @@ function log(value = ({
198
172
  function resolvePure(_, state, args, _actionParams, {
199
173
  get
200
174
  }) {
201
- return [state, undefined, interpreter.toArray(get({
175
+ return [state, undefined, guards_dist_xstateGuards.toArray(get({
202
176
  context: args.context,
203
177
  event: args.event
204
178
  }))];
@@ -245,7 +219,7 @@ function pure(getActions) {
245
219
 
246
220
  // TODO: remove once TS fixes this type-widening issue
247
221
 
248
- // TODO: replace with AnyMachineSnapshot
222
+ /** @deprecated use `AnyMachineSnapshot` instead */
249
223
 
250
224
  // TODO: possibly refactor this somehow, use even a simpler type, and maybe even make `machine.options` private or something
251
225
 
@@ -318,7 +292,7 @@ function executeSendTo(actorScope, params) {
318
292
  to,
319
293
  event
320
294
  } = params;
321
- actorScope?.system._relay(actorScope.self, to, event.type === interpreter.XSTATE_ERROR ? interpreter.createErrorActorEvent(actorScope.self.id, event.data) : event);
295
+ actorScope?.system._relay(actorScope.self, to, event.type === guards_dist_xstateGuards.XSTATE_ERROR ? guards_dist_xstateGuards.createErrorActorEvent(actorScope.self.id, event.data) : event);
322
296
  });
323
297
  }
324
298
  /**
@@ -375,7 +349,7 @@ function forwardTo(target, options) {
375
349
  function escalate(errorData, options) {
376
350
  return sendParent(arg => {
377
351
  return {
378
- type: interpreter.XSTATE_ERROR,
352
+ type: guards_dist_xstateGuards.XSTATE_ERROR,
379
353
  data: typeof errorData === 'function' ? errorData(arg) : errorData
380
354
  };
381
355
  }, options);
@@ -1,7 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var guards_dist_xstateGuards = require('./raise-23dea0d7.development.cjs.js');
4
- var interpreter = require('./interpreter-4e8e2a0d.development.cjs.js');
3
+ var guards_dist_xstateGuards = require('./raise-b3fb3c65.development.cjs.js');
5
4
 
6
5
  function createSpawner(actorScope, {
7
6
  machine,
@@ -13,13 +12,14 @@ function createSpawner(actorScope, {
13
12
  input
14
13
  } = options;
15
14
  if (typeof src === 'string') {
16
- const logic = interpreter.resolveReferencedActor(machine, src);
15
+ const logic = guards_dist_xstateGuards.resolveReferencedActor(machine, src);
17
16
  if (!logic) {
18
17
  throw new Error(`Actor logic '${src}' not implemented in machine '${machine.id}'`);
19
18
  }
20
- const actorRef = interpreter.createActor(logic, {
19
+ const actorRef = guards_dist_xstateGuards.createActor(logic, {
21
20
  id: options.id,
22
21
  parent: actorScope.self,
22
+ syncSnapshot: options.syncSnapshot,
23
23
  input: typeof input === 'function' ? input({
24
24
  context,
25
25
  event,
@@ -29,42 +29,16 @@ function createSpawner(actorScope, {
29
29
  systemId
30
30
  });
31
31
  spawnedChildren[actorRef.id] = actorRef;
32
- if (options.syncSnapshot) {
33
- actorRef.subscribe({
34
- next: snapshot => {
35
- if (snapshot.status === 'active') {
36
- actorScope.self.send({
37
- type: `xstate.snapshot.${actorRef.id}`,
38
- snapshot
39
- });
40
- }
41
- },
42
- error: () => {}
43
- });
44
- }
45
32
  return actorRef;
46
33
  } else {
47
- const actorRef = interpreter.createActor(src, {
34
+ const actorRef = guards_dist_xstateGuards.createActor(src, {
48
35
  id: options.id,
49
36
  parent: actorScope.self,
37
+ syncSnapshot: options.syncSnapshot,
50
38
  input: options.input,
51
39
  src,
52
40
  systemId
53
41
  });
54
- if (options.syncSnapshot) {
55
- actorRef.subscribe({
56
- next: snapshot => {
57
- if (snapshot.status === 'active') {
58
- actorScope.self.send({
59
- type: `xstate.snapshot.${actorRef.id}`,
60
- snapshot,
61
- id: actorRef.id
62
- });
63
- }
64
- },
65
- error: () => {}
66
- });
67
- }
68
42
  return actorRef;
69
43
  }
70
44
  };
@@ -72,13 +46,13 @@ function createSpawner(actorScope, {
72
46
  const actorRef = spawn(src, options); // TODO: fix types
73
47
  spawnedChildren[actorRef.id] = actorRef;
74
48
  actorScope.defer(() => {
75
- if (actorRef._processingStatus === interpreter.ProcessingStatus.Stopped) {
49
+ if (actorRef._processingStatus === guards_dist_xstateGuards.ProcessingStatus.Stopped) {
76
50
  return;
77
51
  }
78
52
  try {
79
53
  actorRef.start?.();
80
54
  } catch (err) {
81
- actorScope.self.send(interpreter.createErrorActorEvent(actorRef.id, err));
55
+ actorScope.self.send(guards_dist_xstateGuards.createErrorActorEvent(actorRef.id, err));
82
56
  return;
83
57
  }
84
58
  });
@@ -141,7 +115,7 @@ function resolveChoose(_, state, actionArgs, _actionParams, {
141
115
  const matchedActions = branches.find(condition => {
142
116
  return !condition.guard || guards_dist_xstateGuards.evaluateGuard(condition.guard, state.context, actionArgs.event, state);
143
117
  })?.actions;
144
- return [state, undefined, interpreter.toArray(matchedActions)];
118
+ return [state, undefined, guards_dist_xstateGuards.toArray(matchedActions)];
145
119
  }
146
120
  function choose(branches) {
147
121
  function choose(args, params) {
@@ -207,7 +181,7 @@ function log(value = ({
207
181
  function resolvePure(_, state, args, _actionParams, {
208
182
  get
209
183
  }) {
210
- return [state, undefined, interpreter.toArray(get({
184
+ return [state, undefined, guards_dist_xstateGuards.toArray(get({
211
185
  context: args.context,
212
186
  event: args.event
213
187
  }))];
@@ -257,7 +231,7 @@ function pure(getActions) {
257
231
 
258
232
  // TODO: remove once TS fixes this type-widening issue
259
233
 
260
- // TODO: replace with AnyMachineSnapshot
234
+ /** @deprecated use `AnyMachineSnapshot` instead */
261
235
 
262
236
  // TODO: possibly refactor this somehow, use even a simpler type, and maybe even make `machine.options` private or something
263
237
 
@@ -330,7 +304,7 @@ function executeSendTo(actorScope, params) {
330
304
  to,
331
305
  event
332
306
  } = params;
333
- actorScope?.system._relay(actorScope.self, to, event.type === interpreter.XSTATE_ERROR ? interpreter.createErrorActorEvent(actorScope.self.id, event.data) : event);
307
+ actorScope?.system._relay(actorScope.self, to, event.type === guards_dist_xstateGuards.XSTATE_ERROR ? guards_dist_xstateGuards.createErrorActorEvent(actorScope.self.id, event.data) : event);
334
308
  });
335
309
  }
336
310
  /**
@@ -400,7 +374,7 @@ function forwardTo(target, options) {
400
374
  function escalate(errorData, options) {
401
375
  return sendParent(arg => {
402
376
  return {
403
- type: interpreter.XSTATE_ERROR,
377
+ type: guards_dist_xstateGuards.XSTATE_ERROR,
404
378
  data: typeof errorData === 'function' ? errorData(arg) : errorData
405
379
  };
406
380
  }, options);
@@ -3,9 +3,8 @@
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-36d5556e.cjs.js');
7
- var guards_dist_xstateGuards = require('./raise-e0fe5c2d.cjs.js');
8
- var send = require('./send-87bbaaab.cjs.js');
6
+ var guards_dist_xstateGuards = require('./raise-fabffc3d.cjs.js');
7
+ var send = require('./send-c124176f.cjs.js');
9
8
  require('../dev/dist/xstate-dev.cjs.js');
10
9
 
11
10
  class SimulatedClock {
@@ -57,6 +56,20 @@ class SimulatedClock {
57
56
  }
58
57
  }
59
58
 
59
+ const cache = new WeakMap();
60
+ function memo(object, key, fn) {
61
+ let memoizedData = cache.get(object);
62
+ if (!memoizedData) {
63
+ memoizedData = {
64
+ [key]: fn()
65
+ };
66
+ cache.set(object, memoizedData);
67
+ } else if (!(key in memoizedData)) {
68
+ memoizedData[key] = fn();
69
+ }
70
+ return memoizedData[key];
71
+ }
72
+
60
73
  const EMPTY_OBJECT = {};
61
74
  const toSerializableAction = action => {
62
75
  if (typeof action === 'string') {
@@ -165,12 +178,12 @@ class StateNode {
165
178
  this.key = options._key;
166
179
  this.machine = options._machine;
167
180
  this.path = this.parent ? this.parent.path.concat(this.key) : [];
168
- this.id = this.config.id || [this.machine.id, ...this.path].join(interpreter.STATE_DELIMITER);
181
+ this.id = this.config.id || [this.machine.id, ...this.path].join(guards_dist_xstateGuards.STATE_DELIMITER);
169
182
  this.type = this.config.type || (this.config.states && Object.keys(this.config.states).length ? 'compound' : this.config.history ? 'history' : 'atomic');
170
183
  this.description = this.config.description;
171
184
  this.order = this.machine.idMap.size;
172
185
  this.machine.idMap.set(this.id, this);
173
- this.states = this.config.states ? interpreter.mapValues(this.config.states, (stateConfig, key) => {
186
+ this.states = this.config.states ? guards_dist_xstateGuards.mapValues(this.config.states, (stateConfig, key) => {
174
187
  const stateNode = new StateNode(stateConfig, {
175
188
  _parent: this,
176
189
  _key: key,
@@ -184,16 +197,16 @@ class StateNode {
184
197
 
185
198
  // History config
186
199
  this.history = this.config.history === true ? 'shallow' : this.config.history || false;
187
- this.entry = interpreter.toArray(this.config.entry).slice();
188
- this.exit = interpreter.toArray(this.config.exit).slice();
200
+ this.entry = guards_dist_xstateGuards.toArray(this.config.entry).slice();
201
+ this.exit = guards_dist_xstateGuards.toArray(this.config.exit).slice();
189
202
  this.meta = this.config.meta;
190
203
  this.output = this.type === 'final' || !this.parent ? this.config.output : undefined;
191
- this.tags = interpreter.toArray(config.tags).slice();
204
+ this.tags = guards_dist_xstateGuards.toArray(config.tags).slice();
192
205
  }
193
206
  _initialize() {
194
207
  this.transitions = guards_dist_xstateGuards.formatTransitions(this);
195
208
  if (this.config.always) {
196
- this.always = interpreter.toTransitionConfigArray(this.config.always).map(t => guards_dist_xstateGuards.formatTransition(this, interpreter.NULL_EVENT, t));
209
+ this.always = guards_dist_xstateGuards.toTransitionConfigArray(this.config.always).map(t => guards_dist_xstateGuards.formatTransition(this, guards_dist_xstateGuards.NULL_EVENT, t));
197
210
  }
198
211
  Object.keys(this.states).forEach(key => {
199
212
  this.states[key]._initialize();
@@ -223,7 +236,7 @@ class StateNode {
223
236
  })
224
237
  } : undefined,
225
238
  history: this.history,
226
- states: interpreter.mapValues(this.states, state => {
239
+ states: guards_dist_xstateGuards.mapValues(this.states, state => {
227
240
  return state.definition;
228
241
  }),
229
242
  on: this.on,
@@ -249,13 +262,13 @@ class StateNode {
249
262
  * The logic invoked as actors by this state node.
250
263
  */
251
264
  get invoke() {
252
- return guards_dist_xstateGuards.memo(this, 'invoke', () => interpreter.toArray(this.config.invoke).map((invokeConfig, i) => {
265
+ return memo(this, 'invoke', () => guards_dist_xstateGuards.toArray(this.config.invoke).map((invokeConfig, i) => {
253
266
  const {
254
267
  src,
255
268
  systemId
256
269
  } = invokeConfig;
257
- const resolvedId = invokeConfig.id || interpreter.createInvokeId(this.id, i);
258
- const resolvedSrc = typeof src === 'string' ? src : `xstate#${interpreter.createInvokeId(this.id, i)}`;
270
+ const resolvedId = invokeConfig.id || guards_dist_xstateGuards.createInvokeId(this.id, i);
271
+ const resolvedSrc = typeof src === 'string' ? src : `xstate#${guards_dist_xstateGuards.createInvokeId(this.id, i)}`;
259
272
  return {
260
273
  ...invokeConfig,
261
274
  src: resolvedSrc,
@@ -282,7 +295,7 @@ class StateNode {
282
295
  * The mapping of events to transitions.
283
296
  */
284
297
  get on() {
285
- return guards_dist_xstateGuards.memo(this, 'on', () => {
298
+ return memo(this, 'on', () => {
286
299
  const transitions = this.transitions;
287
300
  return [...transitions].flatMap(([descriptor, t]) => t.map(t => [descriptor, t])).reduce((map, [descriptor, transition]) => {
288
301
  map[descriptor] = map[descriptor] || [];
@@ -292,16 +305,16 @@ class StateNode {
292
305
  });
293
306
  }
294
307
  get after() {
295
- return guards_dist_xstateGuards.memo(this, 'delayedTransitions', () => guards_dist_xstateGuards.getDelayedTransitions(this));
308
+ return memo(this, 'delayedTransitions', () => guards_dist_xstateGuards.getDelayedTransitions(this));
296
309
  }
297
310
  get initial() {
298
- return guards_dist_xstateGuards.memo(this, 'initial', () => guards_dist_xstateGuards.formatInitialTransition(this, this.config.initial));
311
+ return memo(this, 'initial', () => guards_dist_xstateGuards.formatInitialTransition(this, this.config.initial));
299
312
  }
300
313
  next(state, event) {
301
314
  const eventType = event.type;
302
315
  const actions = [];
303
316
  let selectedTransition;
304
- const candidates = guards_dist_xstateGuards.memo(this, `candidates-${eventType}`, () => guards_dist_xstateGuards.getCandidates(this, eventType));
317
+ const candidates = memo(this, `candidates-${eventType}`, () => guards_dist_xstateGuards.getCandidates(this, eventType));
305
318
  for (const candidate of candidates) {
306
319
  const {
307
320
  guard
@@ -327,7 +340,7 @@ class StateNode {
327
340
  * All the event types accepted by this state node and its descendants.
328
341
  */
329
342
  get events() {
330
- return guards_dist_xstateGuards.memo(this, 'events', () => {
343
+ return memo(this, 'events', () => {
331
344
  const {
332
345
  states
333
346
  } = this;
@@ -449,12 +462,12 @@ class StateMachine {
449
462
  }
450
463
  resolveState(config) {
451
464
  const resolvedStateValue = guards_dist_xstateGuards.resolveStateValue(this.root, config.value);
452
- const configurationSet = guards_dist_xstateGuards.getConfiguration(guards_dist_xstateGuards.getStateNodes(this.root, resolvedStateValue));
465
+ const nodeSet = guards_dist_xstateGuards.getAllStateNodes(guards_dist_xstateGuards.getStateNodes(this.root, resolvedStateValue));
453
466
  return guards_dist_xstateGuards.createMachineSnapshot({
454
- configuration: [...configurationSet],
467
+ _nodes: [...nodeSet],
455
468
  context: config.context || {},
456
469
  children: {},
457
- status: guards_dist_xstateGuards.isInFinalState(configurationSet, this.root) ? 'done' : config.status || 'active',
470
+ status: guards_dist_xstateGuards.isInFinalState(nodeSet, this.root) ? 'done' : config.status || 'active',
458
471
  output: config.output,
459
472
  error: config.error,
460
473
  historyValue: config.historyValue
@@ -470,7 +483,7 @@ class StateMachine {
470
483
  */
471
484
  transition(state, event, actorScope) {
472
485
  // TODO: handle error events in a better way
473
- if (interpreter.isErrorActorEvent(event) && !state.nextEvents.some(nextEvent => nextEvent === event.type)) {
486
+ if (guards_dist_xstateGuards.isErrorActorEvent(event) && !state.getNextEvents().some(nextEvent => nextEvent === event.type)) {
474
487
  return guards_dist_xstateGuards.cloneMachineSnapshot(state, {
475
488
  status: 'error',
476
489
  error: event.data
@@ -506,7 +519,7 @@ class StateMachine {
506
519
  } = this.config;
507
520
  const preInitial = guards_dist_xstateGuards.createMachineSnapshot({
508
521
  context: typeof context !== 'function' && context ? context : {},
509
- configuration: [this.root],
522
+ _nodes: [this.root],
510
523
  children: {},
511
524
  status: 'active'
512
525
  }, this);
@@ -527,7 +540,7 @@ class StateMachine {
527
540
  * Returns the initial `State` instance, with reference to `self` as an `ActorRef`.
528
541
  */
529
542
  getInitialState(actorScope, input) {
530
- const initEvent = interpreter.createInitEvent(input); // TODO: fix;
543
+ const initEvent = guards_dist_xstateGuards.createInitEvent(input); // TODO: fix;
531
544
  const internalQueue = [];
532
545
  const preInitialState = this.getPreInitialState(actorScope, initEvent, internalQueue);
533
546
  const nextState = guards_dist_xstateGuards.microstep([{
@@ -551,7 +564,7 @@ class StateMachine {
551
564
  });
552
565
  }
553
566
  getStateNodeById(stateId) {
554
- const fullPath = stateId.split(interpreter.STATE_DELIMITER);
567
+ const fullPath = stateId.split(guards_dist_xstateGuards.STATE_DELIMITER);
555
568
  const relativePath = fullPath.slice(1);
556
569
  const resolvedStateId = guards_dist_xstateGuards.isStateId(fullPath[0]) ? fullPath[0].slice(STATE_IDENTIFIER.length) : fullPath[0];
557
570
  const stateNode = this.idMap.get(resolvedStateId);
@@ -576,14 +589,15 @@ class StateMachine {
576
589
  const actorData = snapshotChildren[actorId];
577
590
  const childState = actorData.state;
578
591
  const src = actorData.src;
579
- const logic = typeof src === 'string' ? interpreter.resolveReferencedActor(this, src) : src;
592
+ const logic = typeof src === 'string' ? guards_dist_xstateGuards.resolveReferencedActor(this, src) : src;
580
593
  if (!logic) {
581
594
  return;
582
595
  }
583
596
  const actorState = logic.restoreState?.(childState, _actorScope);
584
- const actorRef = interpreter.createActor(logic, {
597
+ const actorRef = guards_dist_xstateGuards.createActor(logic, {
585
598
  id: actorId,
586
599
  parent: _actorScope?.self,
600
+ syncSnapshot: actorData.syncSnapshot,
587
601
  state: actorState,
588
602
  src,
589
603
  systemId: actorData.systemId
@@ -593,7 +607,7 @@ class StateMachine {
593
607
  const restoredSnapshot = guards_dist_xstateGuards.createMachineSnapshot({
594
608
  ...snapshot,
595
609
  children,
596
- configuration: Array.from(guards_dist_xstateGuards.getConfiguration(guards_dist_xstateGuards.getStateNodes(this.root, snapshot.value)))
610
+ _nodes: Array.from(guards_dist_xstateGuards.getAllStateNodes(guards_dist_xstateGuards.getStateNodes(this.root, snapshot.value)))
597
611
  }, this);
598
612
  let seen = new Set();
599
613
  function reviveContext(contextPart, children) {
@@ -604,7 +618,7 @@ class StateMachine {
604
618
  for (let key in contextPart) {
605
619
  const value = contextPart[key];
606
620
  if (value && typeof value === 'object') {
607
- if ('xstate$$type' in value && value.xstate$$type === interpreter.$$ACTOR_TYPE) {
621
+ if ('xstate$$type' in value && value.xstate$$type === guards_dist_xstateGuards.$$ACTOR_TYPE) {
608
622
  contextPart[key] = children[value.id];
609
623
  continue;
610
624
  }
@@ -694,27 +708,44 @@ function createMachine(config, implementations) {
694
708
  return new StateMachine(config, implementations);
695
709
  }
696
710
 
711
+ function setup({
712
+ actors,
713
+ actions,
714
+ guards,
715
+ delays
716
+ }) {
717
+ return {
718
+ createMachine: config => createMachine(config, {
719
+ actors,
720
+ actions,
721
+ guards,
722
+ delays
723
+ })
724
+ };
725
+ }
726
+
697
727
  exports.createEmptyActor = actors_dist_xstateActors.createEmptyActor;
698
728
  exports.fromCallback = actors_dist_xstateActors.fromCallback;
699
729
  exports.fromEventObservable = actors_dist_xstateActors.fromEventObservable;
700
730
  exports.fromObservable = actors_dist_xstateActors.fromObservable;
701
731
  exports.fromPromise = actors_dist_xstateActors.fromPromise;
702
732
  exports.fromTransition = actors_dist_xstateActors.fromTransition;
703
- exports.Actor = interpreter.Actor;
704
- exports.createActor = interpreter.createActor;
705
- exports.interpret = interpreter.interpret;
706
- exports.matchesState = interpreter.matchesState;
707
- exports.pathToStateValue = interpreter.pathToStateValue;
708
- exports.toObserver = interpreter.toObserver;
733
+ exports.Actor = guards_dist_xstateGuards.Actor;
709
734
  exports.and = guards_dist_xstateGuards.and;
710
735
  exports.cancel = guards_dist_xstateGuards.cancel;
736
+ exports.createActor = guards_dist_xstateGuards.createActor;
711
737
  exports.getStateNodes = guards_dist_xstateGuards.getStateNodes;
738
+ exports.interpret = guards_dist_xstateGuards.interpret;
739
+ exports.isMachineSnapshot = guards_dist_xstateGuards.isMachineSnapshot;
740
+ exports.matchesState = guards_dist_xstateGuards.matchesState;
712
741
  exports.not = guards_dist_xstateGuards.not;
713
742
  exports.or = guards_dist_xstateGuards.or;
743
+ exports.pathToStateValue = guards_dist_xstateGuards.pathToStateValue;
714
744
  exports.raise = guards_dist_xstateGuards.raise;
715
745
  exports.spawn = guards_dist_xstateGuards.spawn;
716
746
  exports.stateIn = guards_dist_xstateGuards.stateIn;
717
747
  exports.stop = guards_dist_xstateGuards.stop;
748
+ exports.toObserver = guards_dist_xstateGuards.toObserver;
718
749
  exports.SpecialTargets = send.SpecialTargets;
719
750
  exports.assign = send.assign;
720
751
  exports.choose = send.choose;
@@ -728,4 +759,5 @@ exports.SimulatedClock = SimulatedClock;
728
759
  exports.StateMachine = StateMachine;
729
760
  exports.StateNode = StateNode;
730
761
  exports.createMachine = createMachine;
762
+ exports.setup = setup;
731
763
  exports.waitFor = waitFor;
@@ -20,6 +20,7 @@ export {
20
20
  fromTransition,
21
21
  getStateNodes,
22
22
  interpret,
23
+ isMachineSnapshot,
23
24
  log,
24
25
  matchesState,
25
26
  not,
@@ -29,6 +30,7 @@ export {
29
30
  raise,
30
31
  sendParent,
31
32
  sendTo,
33
+ setup,
32
34
  spawn,
33
35
  stateIn,
34
36
  stop,