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
@@ -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.development.cjs.js');
6
- var interpreter = require('./interpreter-4e8e2a0d.development.cjs.js');
7
- var guards_dist_xstateGuards = require('./raise-23dea0d7.development.cjs.js');
8
- var send = require('./send-0174c155.development.cjs.js');
6
+ var guards_dist_xstateGuards = require('./raise-b3fb3c65.development.cjs.js');
7
+ var send = require('./send-d0bc7eed.development.cjs.js');
9
8
  require('../dev/dist/xstate-dev.development.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;
@@ -452,12 +465,12 @@ class StateMachine {
452
465
  }
453
466
  resolveState(config) {
454
467
  const resolvedStateValue = guards_dist_xstateGuards.resolveStateValue(this.root, config.value);
455
- const configurationSet = guards_dist_xstateGuards.getConfiguration(guards_dist_xstateGuards.getStateNodes(this.root, resolvedStateValue));
468
+ const nodeSet = guards_dist_xstateGuards.getAllStateNodes(guards_dist_xstateGuards.getStateNodes(this.root, resolvedStateValue));
456
469
  return guards_dist_xstateGuards.createMachineSnapshot({
457
- configuration: [...configurationSet],
470
+ _nodes: [...nodeSet],
458
471
  context: config.context || {},
459
472
  children: {},
460
- status: guards_dist_xstateGuards.isInFinalState(configurationSet, this.root) ? 'done' : config.status || 'active',
473
+ status: guards_dist_xstateGuards.isInFinalState(nodeSet, this.root) ? 'done' : config.status || 'active',
461
474
  output: config.output,
462
475
  error: config.error,
463
476
  historyValue: config.historyValue
@@ -473,7 +486,7 @@ class StateMachine {
473
486
  */
474
487
  transition(state, event, actorScope) {
475
488
  // TODO: handle error events in a better way
476
- if (interpreter.isErrorActorEvent(event) && !state.nextEvents.some(nextEvent => nextEvent === event.type)) {
489
+ if (guards_dist_xstateGuards.isErrorActorEvent(event) && !state.getNextEvents().some(nextEvent => nextEvent === event.type)) {
477
490
  return guards_dist_xstateGuards.cloneMachineSnapshot(state, {
478
491
  status: 'error',
479
492
  error: event.data
@@ -509,7 +522,7 @@ class StateMachine {
509
522
  } = this.config;
510
523
  const preInitial = guards_dist_xstateGuards.createMachineSnapshot({
511
524
  context: typeof context !== 'function' && context ? context : {},
512
- configuration: [this.root],
525
+ _nodes: [this.root],
513
526
  children: {},
514
527
  status: 'active'
515
528
  }, this);
@@ -530,7 +543,7 @@ class StateMachine {
530
543
  * Returns the initial `State` instance, with reference to `self` as an `ActorRef`.
531
544
  */
532
545
  getInitialState(actorScope, input) {
533
- const initEvent = interpreter.createInitEvent(input); // TODO: fix;
546
+ const initEvent = guards_dist_xstateGuards.createInitEvent(input); // TODO: fix;
534
547
  const internalQueue = [];
535
548
  const preInitialState = this.getPreInitialState(actorScope, initEvent, internalQueue);
536
549
  const nextState = guards_dist_xstateGuards.microstep([{
@@ -554,7 +567,7 @@ class StateMachine {
554
567
  });
555
568
  }
556
569
  getStateNodeById(stateId) {
557
- const fullPath = stateId.split(interpreter.STATE_DELIMITER);
570
+ const fullPath = stateId.split(guards_dist_xstateGuards.STATE_DELIMITER);
558
571
  const relativePath = fullPath.slice(1);
559
572
  const resolvedStateId = guards_dist_xstateGuards.isStateId(fullPath[0]) ? fullPath[0].slice(STATE_IDENTIFIER.length) : fullPath[0];
560
573
  const stateNode = this.idMap.get(resolvedStateId);
@@ -579,14 +592,15 @@ class StateMachine {
579
592
  const actorData = snapshotChildren[actorId];
580
593
  const childState = actorData.state;
581
594
  const src = actorData.src;
582
- const logic = typeof src === 'string' ? interpreter.resolveReferencedActor(this, src) : src;
595
+ const logic = typeof src === 'string' ? guards_dist_xstateGuards.resolveReferencedActor(this, src) : src;
583
596
  if (!logic) {
584
597
  return;
585
598
  }
586
599
  const actorState = logic.restoreState?.(childState, _actorScope);
587
- const actorRef = interpreter.createActor(logic, {
600
+ const actorRef = guards_dist_xstateGuards.createActor(logic, {
588
601
  id: actorId,
589
602
  parent: _actorScope?.self,
603
+ syncSnapshot: actorData.syncSnapshot,
590
604
  state: actorState,
591
605
  src,
592
606
  systemId: actorData.systemId
@@ -596,7 +610,7 @@ class StateMachine {
596
610
  const restoredSnapshot = guards_dist_xstateGuards.createMachineSnapshot({
597
611
  ...snapshot,
598
612
  children,
599
- configuration: Array.from(guards_dist_xstateGuards.getConfiguration(guards_dist_xstateGuards.getStateNodes(this.root, snapshot.value)))
613
+ _nodes: Array.from(guards_dist_xstateGuards.getAllStateNodes(guards_dist_xstateGuards.getStateNodes(this.root, snapshot.value)))
600
614
  }, this);
601
615
  let seen = new Set();
602
616
  function reviveContext(contextPart, children) {
@@ -607,7 +621,7 @@ class StateMachine {
607
621
  for (let key in contextPart) {
608
622
  const value = contextPart[key];
609
623
  if (value && typeof value === 'object') {
610
- if ('xstate$$type' in value && value.xstate$$type === interpreter.$$ACTOR_TYPE) {
624
+ if ('xstate$$type' in value && value.xstate$$type === guards_dist_xstateGuards.$$ACTOR_TYPE) {
611
625
  contextPart[key] = children[value.id];
612
626
  continue;
613
627
  }
@@ -700,27 +714,44 @@ function createMachine(config, implementations) {
700
714
  return new StateMachine(config, implementations);
701
715
  }
702
716
 
717
+ function setup({
718
+ actors,
719
+ actions,
720
+ guards,
721
+ delays
722
+ }) {
723
+ return {
724
+ createMachine: config => createMachine(config, {
725
+ actors,
726
+ actions,
727
+ guards,
728
+ delays
729
+ })
730
+ };
731
+ }
732
+
703
733
  exports.createEmptyActor = actors_dist_xstateActors.createEmptyActor;
704
734
  exports.fromCallback = actors_dist_xstateActors.fromCallback;
705
735
  exports.fromEventObservable = actors_dist_xstateActors.fromEventObservable;
706
736
  exports.fromObservable = actors_dist_xstateActors.fromObservable;
707
737
  exports.fromPromise = actors_dist_xstateActors.fromPromise;
708
738
  exports.fromTransition = actors_dist_xstateActors.fromTransition;
709
- exports.Actor = interpreter.Actor;
710
- exports.createActor = interpreter.createActor;
711
- exports.interpret = interpreter.interpret;
712
- exports.matchesState = interpreter.matchesState;
713
- exports.pathToStateValue = interpreter.pathToStateValue;
714
- exports.toObserver = interpreter.toObserver;
739
+ exports.Actor = guards_dist_xstateGuards.Actor;
715
740
  exports.and = guards_dist_xstateGuards.and;
716
741
  exports.cancel = guards_dist_xstateGuards.cancel;
742
+ exports.createActor = guards_dist_xstateGuards.createActor;
717
743
  exports.getStateNodes = guards_dist_xstateGuards.getStateNodes;
744
+ exports.interpret = guards_dist_xstateGuards.interpret;
745
+ exports.isMachineSnapshot = guards_dist_xstateGuards.isMachineSnapshot;
746
+ exports.matchesState = guards_dist_xstateGuards.matchesState;
718
747
  exports.not = guards_dist_xstateGuards.not;
719
748
  exports.or = guards_dist_xstateGuards.or;
749
+ exports.pathToStateValue = guards_dist_xstateGuards.pathToStateValue;
720
750
  exports.raise = guards_dist_xstateGuards.raise;
721
751
  exports.spawn = guards_dist_xstateGuards.spawn;
722
752
  exports.stateIn = guards_dist_xstateGuards.stateIn;
723
753
  exports.stop = guards_dist_xstateGuards.stop;
754
+ exports.toObserver = guards_dist_xstateGuards.toObserver;
724
755
  exports.SpecialTargets = send.SpecialTargets;
725
756
  exports.assign = send.assign;
726
757
  exports.choose = send.choose;
@@ -734,4 +765,5 @@ exports.SimulatedClock = SimulatedClock;
734
765
  exports.StateMachine = StateMachine;
735
766
  exports.StateNode = StateNode;
736
767
  exports.createMachine = createMachine;
768
+ exports.setup = setup;
737
769
  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,
@@ -1,10 +1,8 @@
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, $ as $$ACTOR_TYPE } from './interpreter-80eb3bec.development.esm.js';
3
- export { A as Actor, d as createActor, e as interpret, f as matchesState, p as pathToStateValue, g as toObserver } from './interpreter-80eb3bec.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, r as resolveStateValue, d as getConfiguration, h as getStateNodes, i as createMachineSnapshot, j as isInFinalState, k as cloneMachineSnapshot, l as macrostep, t as transitionNode, n as resolveActionsAndContext, o as microstep, p as getInitialStateNodes, q as isStateId, s as getStateNodeByPath, u as getPersistedState } from './raise-f4ad5a87.development.esm.js';
5
- export { v as and, z as cancel, h as getStateNodes, w as not, x as or, A as raise, C as spawn, y as stateIn, B as stop } from './raise-f4ad5a87.development.esm.js';
6
- import { a as assign } from './send-5d129d95.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-5d129d95.development.esm.js';
2
+ import { S as STATE_DELIMITER, m as mapValues, t as toArray, f as formatTransitions, a as toTransitionConfigArray, b as formatTransition, N as NULL_EVENT, e as evaluateGuard, c as createInvokeId, g as getDelayedTransitions, d as formatInitialTransition, h as getCandidates, r as resolveStateValue, i as getAllStateNodes, j as getStateNodes, k as createMachineSnapshot, l as isInFinalState, n as isErrorActorEvent, o as cloneMachineSnapshot, p as macrostep, q as transitionNode, s as resolveActionsAndContext, u as createInitEvent, v as microstep, w as getInitialStateNodes, x as isStateId, y as getStateNodeByPath, z as getPersistedState, A as resolveReferencedActor, B as createActor, $ as $$ACTOR_TYPE } from './raise-90139fbc.development.esm.js';
3
+ export { C as Actor, I as and, M as cancel, B as createActor, j as getStateNodes, D as interpret, E as isMachineSnapshot, F as matchesState, J as not, K as or, G as pathToStateValue, O as raise, Q as spawn, L as stateIn, P as stop, H as toObserver } from './raise-90139fbc.development.esm.js';
4
+ import { a as assign } from './send-24cc8018.development.esm.js';
5
+ 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-24cc8018.development.esm.js';
8
6
  import '../dev/dist/xstate-dev.development.esm.js';
9
7
 
10
8
  class SimulatedClock {
@@ -56,6 +54,20 @@ class SimulatedClock {
56
54
  }
57
55
  }
58
56
 
57
+ const cache = new WeakMap();
58
+ function memo(object, key, fn) {
59
+ let memoizedData = cache.get(object);
60
+ if (!memoizedData) {
61
+ memoizedData = {
62
+ [key]: fn()
63
+ };
64
+ cache.set(object, memoizedData);
65
+ } else if (!(key in memoizedData)) {
66
+ memoizedData[key] = fn();
67
+ }
68
+ return memoizedData[key];
69
+ }
70
+
59
71
  const EMPTY_OBJECT = {};
60
72
  const toSerializableAction = action => {
61
73
  if (typeof action === 'string') {
@@ -451,12 +463,12 @@ class StateMachine {
451
463
  }
452
464
  resolveState(config) {
453
465
  const resolvedStateValue = resolveStateValue(this.root, config.value);
454
- const configurationSet = getConfiguration(getStateNodes(this.root, resolvedStateValue));
466
+ const nodeSet = getAllStateNodes(getStateNodes(this.root, resolvedStateValue));
455
467
  return createMachineSnapshot({
456
- configuration: [...configurationSet],
468
+ _nodes: [...nodeSet],
457
469
  context: config.context || {},
458
470
  children: {},
459
- status: isInFinalState(configurationSet, this.root) ? 'done' : config.status || 'active',
471
+ status: isInFinalState(nodeSet, this.root) ? 'done' : config.status || 'active',
460
472
  output: config.output,
461
473
  error: config.error,
462
474
  historyValue: config.historyValue
@@ -472,7 +484,7 @@ class StateMachine {
472
484
  */
473
485
  transition(state, event, actorScope) {
474
486
  // TODO: handle error events in a better way
475
- if (isErrorActorEvent(event) && !state.nextEvents.some(nextEvent => nextEvent === event.type)) {
487
+ if (isErrorActorEvent(event) && !state.getNextEvents().some(nextEvent => nextEvent === event.type)) {
476
488
  return cloneMachineSnapshot(state, {
477
489
  status: 'error',
478
490
  error: event.data
@@ -508,7 +520,7 @@ class StateMachine {
508
520
  } = this.config;
509
521
  const preInitial = createMachineSnapshot({
510
522
  context: typeof context !== 'function' && context ? context : {},
511
- configuration: [this.root],
523
+ _nodes: [this.root],
512
524
  children: {},
513
525
  status: 'active'
514
526
  }, this);
@@ -586,6 +598,7 @@ class StateMachine {
586
598
  const actorRef = createActor(logic, {
587
599
  id: actorId,
588
600
  parent: _actorScope?.self,
601
+ syncSnapshot: actorData.syncSnapshot,
589
602
  state: actorState,
590
603
  src,
591
604
  systemId: actorData.systemId
@@ -595,7 +608,7 @@ class StateMachine {
595
608
  const restoredSnapshot = createMachineSnapshot({
596
609
  ...snapshot,
597
610
  children,
598
- configuration: Array.from(getConfiguration(getStateNodes(this.root, snapshot.value)))
611
+ _nodes: Array.from(getAllStateNodes(getStateNodes(this.root, snapshot.value)))
599
612
  }, this);
600
613
  let seen = new Set();
601
614
  function reviveContext(contextPart, children) {
@@ -699,4 +712,20 @@ function createMachine(config, implementations) {
699
712
  return new StateMachine(config, implementations);
700
713
  }
701
714
 
702
- export { SimulatedClock, StateMachine, StateNode, createMachine, waitFor };
715
+ function setup({
716
+ actors,
717
+ actions,
718
+ guards,
719
+ delays
720
+ }) {
721
+ return {
722
+ createMachine: config => createMachine(config, {
723
+ actors,
724
+ actions,
725
+ guards,
726
+ delays
727
+ })
728
+ };
729
+ }
730
+
731
+ export { SimulatedClock, StateMachine, StateNode, createMachine, setup, waitFor };
@@ -1,10 +1,8 @@
1
1
  export { createEmptyActor, fromCallback, fromEventObservable, fromObservable, fromPromise, fromTransition } from '../actors/dist/xstate-actors.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, $ as $$ACTOR_TYPE } from './interpreter-63c80754.esm.js';
3
- export { A as Actor, d as createActor, e as interpret, f as matchesState, p as pathToStateValue, g as toObserver } from './interpreter-63c80754.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, r as resolveStateValue, d as getConfiguration, h as getStateNodes, i as createMachineSnapshot, j as isInFinalState, k as cloneMachineSnapshot, l as macrostep, t as transitionNode, n as resolveActionsAndContext, o as microstep, p as getInitialStateNodes, q as isStateId, s as getStateNodeByPath, u as getPersistedState } from './raise-8dc8e1aa.esm.js';
5
- export { v as and, z as cancel, h as getStateNodes, w as not, x as or, A as raise, C as spawn, y as stateIn, B as stop } from './raise-8dc8e1aa.esm.js';
6
- import { a as assign } from './send-84e2e742.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-84e2e742.esm.js';
2
+ import { S as STATE_DELIMITER, m as mapValues, t as toArray, f as formatTransitions, a as toTransitionConfigArray, b as formatTransition, N as NULL_EVENT, e as evaluateGuard, c as createInvokeId, g as getDelayedTransitions, d as formatInitialTransition, h as getCandidates, r as resolveStateValue, i as getAllStateNodes, j as getStateNodes, k as createMachineSnapshot, l as isInFinalState, n as isErrorActorEvent, o as cloneMachineSnapshot, p as macrostep, q as transitionNode, s as resolveActionsAndContext, u as createInitEvent, v as microstep, w as getInitialStateNodes, x as isStateId, y as getStateNodeByPath, z as getPersistedState, A as resolveReferencedActor, B as createActor, $ as $$ACTOR_TYPE } from './raise-2b5a4e4c.esm.js';
3
+ export { C as Actor, I as and, M as cancel, B as createActor, j as getStateNodes, D as interpret, E as isMachineSnapshot, F as matchesState, J as not, K as or, G as pathToStateValue, O as raise, Q as spawn, L as stateIn, P as stop, H as toObserver } from './raise-2b5a4e4c.esm.js';
4
+ import { a as assign } from './send-8e7e41e7.esm.js';
5
+ 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-8e7e41e7.esm.js';
8
6
  import '../dev/dist/xstate-dev.esm.js';
9
7
 
10
8
  class SimulatedClock {
@@ -56,6 +54,20 @@ class SimulatedClock {
56
54
  }
57
55
  }
58
56
 
57
+ const cache = new WeakMap();
58
+ function memo(object, key, fn) {
59
+ let memoizedData = cache.get(object);
60
+ if (!memoizedData) {
61
+ memoizedData = {
62
+ [key]: fn()
63
+ };
64
+ cache.set(object, memoizedData);
65
+ } else if (!(key in memoizedData)) {
66
+ memoizedData[key] = fn();
67
+ }
68
+ return memoizedData[key];
69
+ }
70
+
59
71
  const EMPTY_OBJECT = {};
60
72
  const toSerializableAction = action => {
61
73
  if (typeof action === 'string') {
@@ -448,12 +460,12 @@ class StateMachine {
448
460
  }
449
461
  resolveState(config) {
450
462
  const resolvedStateValue = resolveStateValue(this.root, config.value);
451
- const configurationSet = getConfiguration(getStateNodes(this.root, resolvedStateValue));
463
+ const nodeSet = getAllStateNodes(getStateNodes(this.root, resolvedStateValue));
452
464
  return createMachineSnapshot({
453
- configuration: [...configurationSet],
465
+ _nodes: [...nodeSet],
454
466
  context: config.context || {},
455
467
  children: {},
456
- status: isInFinalState(configurationSet, this.root) ? 'done' : config.status || 'active',
468
+ status: isInFinalState(nodeSet, this.root) ? 'done' : config.status || 'active',
457
469
  output: config.output,
458
470
  error: config.error,
459
471
  historyValue: config.historyValue
@@ -469,7 +481,7 @@ class StateMachine {
469
481
  */
470
482
  transition(state, event, actorScope) {
471
483
  // TODO: handle error events in a better way
472
- if (isErrorActorEvent(event) && !state.nextEvents.some(nextEvent => nextEvent === event.type)) {
484
+ if (isErrorActorEvent(event) && !state.getNextEvents().some(nextEvent => nextEvent === event.type)) {
473
485
  return cloneMachineSnapshot(state, {
474
486
  status: 'error',
475
487
  error: event.data
@@ -505,7 +517,7 @@ class StateMachine {
505
517
  } = this.config;
506
518
  const preInitial = createMachineSnapshot({
507
519
  context: typeof context !== 'function' && context ? context : {},
508
- configuration: [this.root],
520
+ _nodes: [this.root],
509
521
  children: {},
510
522
  status: 'active'
511
523
  }, this);
@@ -583,6 +595,7 @@ class StateMachine {
583
595
  const actorRef = createActor(logic, {
584
596
  id: actorId,
585
597
  parent: _actorScope?.self,
598
+ syncSnapshot: actorData.syncSnapshot,
586
599
  state: actorState,
587
600
  src,
588
601
  systemId: actorData.systemId
@@ -592,7 +605,7 @@ class StateMachine {
592
605
  const restoredSnapshot = createMachineSnapshot({
593
606
  ...snapshot,
594
607
  children,
595
- configuration: Array.from(getConfiguration(getStateNodes(this.root, snapshot.value)))
608
+ _nodes: Array.from(getAllStateNodes(getStateNodes(this.root, snapshot.value)))
596
609
  }, this);
597
610
  let seen = new Set();
598
611
  function reviveContext(contextPart, children) {
@@ -693,4 +706,20 @@ function createMachine(config, implementations) {
693
706
  return new StateMachine(config, implementations);
694
707
  }
695
708
 
696
- export { SimulatedClock, StateMachine, StateNode, createMachine, waitFor };
709
+ function setup({
710
+ actors,
711
+ actions,
712
+ guards,
713
+ delays
714
+ }) {
715
+ return {
716
+ createMachine: config => createMachine(config, {
717
+ actors,
718
+ actions,
719
+ guards,
720
+ delays
721
+ })
722
+ };
723
+ }
724
+
725
+ export { SimulatedClock, StateMachine, StateNode, createMachine, setup, waitFor };