xstate 5.0.0-beta.44 → 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 (48) hide show
  1. package/actions/dist/xstate-actions.cjs.js +2 -2
  2. package/actions/dist/xstate-actions.development.cjs.js +2 -2
  3. package/actions/dist/xstate-actions.development.esm.js +2 -2
  4. package/actions/dist/xstate-actions.esm.js +2 -2
  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 +93 -5
  8. package/actors/dist/xstate-actors.development.cjs.js +93 -5
  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 +11 -11
  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/actors/observable.d.ts +39 -0
  18. package/dist/declarations/src/actors/transition.d.ts +53 -4
  19. package/dist/declarations/src/{Machine.d.ts → createMachine.d.ts} +1 -1
  20. package/dist/declarations/src/guards.d.ts +26 -4
  21. package/dist/declarations/src/index.d.ts +2 -1
  22. package/dist/declarations/src/interpreter.d.ts +1 -0
  23. package/dist/declarations/src/setup.d.ts +32 -0
  24. package/dist/declarations/src/stateUtils.d.ts +7 -7
  25. package/dist/declarations/src/types.d.ts +16 -13
  26. package/dist/{raise-5854eaca.esm.js → raise-2b5a4e4c.esm.js} +82 -105
  27. package/dist/{raise-348cc74e.development.esm.js → raise-90139fbc.development.esm.js} +82 -105
  28. package/dist/{raise-ed700d14.development.cjs.js → raise-b3fb3c65.development.cjs.js} +82 -106
  29. package/dist/{raise-fb6f017b.cjs.js → raise-fabffc3d.cjs.js} +82 -106
  30. package/dist/{send-a0193bdb.development.esm.js → send-24cc8018.development.esm.js} +3 -28
  31. package/dist/{send-b7b4befa.esm.js → send-8e7e41e7.esm.js} +3 -28
  32. package/dist/{send-53e5693c.cjs.js → send-c124176f.cjs.js} +3 -28
  33. package/dist/{send-00466e37.development.cjs.js → send-d0bc7eed.development.cjs.js} +3 -28
  34. package/dist/xstate.cjs.js +46 -14
  35. package/dist/xstate.cjs.mjs +1 -0
  36. package/dist/xstate.development.cjs.js +46 -14
  37. package/dist/xstate.development.cjs.mjs +1 -0
  38. package/dist/xstate.development.esm.js +42 -11
  39. package/dist/xstate.esm.js +42 -11
  40. package/dist/xstate.umd.min.js +1 -1
  41. package/dist/xstate.umd.min.js.map +1 -1
  42. package/guards/dist/xstate-guards.cjs.js +1 -1
  43. package/guards/dist/xstate-guards.development.cjs.js +1 -1
  44. package/guards/dist/xstate-guards.development.esm.js +1 -1
  45. package/guards/dist/xstate-guards.esm.js +1 -1
  46. package/guards/dist/xstate-guards.umd.min.js +1 -1
  47. package/guards/dist/xstate-guards.umd.min.js.map +1 -1
  48. package/package.json +1 -1
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var guards_dist_xstateGuards = require('./raise-ed700d14.development.cjs.js');
3
+ var guards_dist_xstateGuards = require('./raise-b3fb3c65.development.cjs.js');
4
4
 
5
5
  function createSpawner(actorScope, {
6
6
  machine,
@@ -19,6 +19,7 @@ function createSpawner(actorScope, {
19
19
  const actorRef = guards_dist_xstateGuards.createActor(logic, {
20
20
  id: options.id,
21
21
  parent: actorScope.self,
22
+ syncSnapshot: options.syncSnapshot,
22
23
  input: typeof input === 'function' ? input({
23
24
  context,
24
25
  event,
@@ -28,42 +29,16 @@ function createSpawner(actorScope, {
28
29
  systemId
29
30
  });
30
31
  spawnedChildren[actorRef.id] = actorRef;
31
- if (options.syncSnapshot) {
32
- actorRef.subscribe({
33
- next: snapshot => {
34
- if (snapshot.status === 'active') {
35
- actorScope.self.send({
36
- type: `xstate.snapshot.${actorRef.id}`,
37
- snapshot
38
- });
39
- }
40
- },
41
- error: () => {}
42
- });
43
- }
44
32
  return actorRef;
45
33
  } else {
46
34
  const actorRef = guards_dist_xstateGuards.createActor(src, {
47
35
  id: options.id,
48
36
  parent: actorScope.self,
37
+ syncSnapshot: options.syncSnapshot,
49
38
  input: options.input,
50
39
  src,
51
40
  systemId
52
41
  });
53
- if (options.syncSnapshot) {
54
- actorRef.subscribe({
55
- next: snapshot => {
56
- if (snapshot.status === 'active') {
57
- actorScope.self.send({
58
- type: `xstate.snapshot.${actorRef.id}`,
59
- snapshot,
60
- id: actorRef.id
61
- });
62
- }
63
- },
64
- error: () => {}
65
- });
66
- }
67
42
  return actorRef;
68
43
  }
69
44
  };
@@ -3,8 +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 guards_dist_xstateGuards = require('./raise-fb6f017b.cjs.js');
7
- var send = require('./send-53e5693c.cjs.js');
6
+ var guards_dist_xstateGuards = require('./raise-fabffc3d.cjs.js');
7
+ var send = require('./send-c124176f.cjs.js');
8
8
  require('../dev/dist/xstate-dev.cjs.js');
9
9
 
10
10
  class SimulatedClock {
@@ -56,6 +56,20 @@ class SimulatedClock {
56
56
  }
57
57
  }
58
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
+
59
73
  const EMPTY_OBJECT = {};
60
74
  const toSerializableAction = action => {
61
75
  if (typeof action === 'string') {
@@ -248,7 +262,7 @@ class StateNode {
248
262
  * The logic invoked as actors by this state node.
249
263
  */
250
264
  get invoke() {
251
- return guards_dist_xstateGuards.memo(this, 'invoke', () => guards_dist_xstateGuards.toArray(this.config.invoke).map((invokeConfig, i) => {
265
+ return memo(this, 'invoke', () => guards_dist_xstateGuards.toArray(this.config.invoke).map((invokeConfig, i) => {
252
266
  const {
253
267
  src,
254
268
  systemId
@@ -281,7 +295,7 @@ class StateNode {
281
295
  * The mapping of events to transitions.
282
296
  */
283
297
  get on() {
284
- return guards_dist_xstateGuards.memo(this, 'on', () => {
298
+ return memo(this, 'on', () => {
285
299
  const transitions = this.transitions;
286
300
  return [...transitions].flatMap(([descriptor, t]) => t.map(t => [descriptor, t])).reduce((map, [descriptor, transition]) => {
287
301
  map[descriptor] = map[descriptor] || [];
@@ -291,16 +305,16 @@ class StateNode {
291
305
  });
292
306
  }
293
307
  get after() {
294
- return guards_dist_xstateGuards.memo(this, 'delayedTransitions', () => guards_dist_xstateGuards.getDelayedTransitions(this));
308
+ return memo(this, 'delayedTransitions', () => guards_dist_xstateGuards.getDelayedTransitions(this));
295
309
  }
296
310
  get initial() {
297
- 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));
298
312
  }
299
313
  next(state, event) {
300
314
  const eventType = event.type;
301
315
  const actions = [];
302
316
  let selectedTransition;
303
- 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));
304
318
  for (const candidate of candidates) {
305
319
  const {
306
320
  guard
@@ -326,7 +340,7 @@ class StateNode {
326
340
  * All the event types accepted by this state node and its descendants.
327
341
  */
328
342
  get events() {
329
- return guards_dist_xstateGuards.memo(this, 'events', () => {
343
+ return memo(this, 'events', () => {
330
344
  const {
331
345
  states
332
346
  } = this;
@@ -448,12 +462,12 @@ class StateMachine {
448
462
  }
449
463
  resolveState(config) {
450
464
  const resolvedStateValue = guards_dist_xstateGuards.resolveStateValue(this.root, config.value);
451
- 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));
452
466
  return guards_dist_xstateGuards.createMachineSnapshot({
453
- configuration: [...configurationSet],
467
+ _nodes: [...nodeSet],
454
468
  context: config.context || {},
455
469
  children: {},
456
- 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',
457
471
  output: config.output,
458
472
  error: config.error,
459
473
  historyValue: config.historyValue
@@ -469,7 +483,7 @@ class StateMachine {
469
483
  */
470
484
  transition(state, event, actorScope) {
471
485
  // TODO: handle error events in a better way
472
- if (guards_dist_xstateGuards.isErrorActorEvent(event) && !state.nextEvents.some(nextEvent => nextEvent === event.type)) {
486
+ if (guards_dist_xstateGuards.isErrorActorEvent(event) && !state.getNextEvents().some(nextEvent => nextEvent === event.type)) {
473
487
  return guards_dist_xstateGuards.cloneMachineSnapshot(state, {
474
488
  status: 'error',
475
489
  error: event.data
@@ -505,7 +519,7 @@ class StateMachine {
505
519
  } = this.config;
506
520
  const preInitial = guards_dist_xstateGuards.createMachineSnapshot({
507
521
  context: typeof context !== 'function' && context ? context : {},
508
- configuration: [this.root],
522
+ _nodes: [this.root],
509
523
  children: {},
510
524
  status: 'active'
511
525
  }, this);
@@ -583,6 +597,7 @@ class StateMachine {
583
597
  const actorRef = guards_dist_xstateGuards.createActor(logic, {
584
598
  id: actorId,
585
599
  parent: _actorScope?.self,
600
+ syncSnapshot: actorData.syncSnapshot,
586
601
  state: actorState,
587
602
  src,
588
603
  systemId: actorData.systemId
@@ -592,7 +607,7 @@ class StateMachine {
592
607
  const restoredSnapshot = guards_dist_xstateGuards.createMachineSnapshot({
593
608
  ...snapshot,
594
609
  children,
595
- 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)))
596
611
  }, this);
597
612
  let seen = new Set();
598
613
  function reviveContext(contextPart, children) {
@@ -693,6 +708,22 @@ function createMachine(config, implementations) {
693
708
  return new StateMachine(config, implementations);
694
709
  }
695
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
+
696
727
  exports.createEmptyActor = actors_dist_xstateActors.createEmptyActor;
697
728
  exports.fromCallback = actors_dist_xstateActors.fromCallback;
698
729
  exports.fromEventObservable = actors_dist_xstateActors.fromEventObservable;
@@ -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;
@@ -30,6 +30,7 @@ export {
30
30
  raise,
31
31
  sendParent,
32
32
  sendTo,
33
+ setup,
33
34
  spawn,
34
35
  stateIn,
35
36
  stop,
@@ -3,8 +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 guards_dist_xstateGuards = require('./raise-ed700d14.development.cjs.js');
7
- var send = require('./send-00466e37.development.cjs.js');
6
+ var guards_dist_xstateGuards = require('./raise-b3fb3c65.development.cjs.js');
7
+ var send = require('./send-d0bc7eed.development.cjs.js');
8
8
  require('../dev/dist/xstate-dev.development.cjs.js');
9
9
 
10
10
  class SimulatedClock {
@@ -56,6 +56,20 @@ class SimulatedClock {
56
56
  }
57
57
  }
58
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
+
59
73
  const EMPTY_OBJECT = {};
60
74
  const toSerializableAction = action => {
61
75
  if (typeof action === 'string') {
@@ -248,7 +262,7 @@ class StateNode {
248
262
  * The logic invoked as actors by this state node.
249
263
  */
250
264
  get invoke() {
251
- return guards_dist_xstateGuards.memo(this, 'invoke', () => guards_dist_xstateGuards.toArray(this.config.invoke).map((invokeConfig, i) => {
265
+ return memo(this, 'invoke', () => guards_dist_xstateGuards.toArray(this.config.invoke).map((invokeConfig, i) => {
252
266
  const {
253
267
  src,
254
268
  systemId
@@ -281,7 +295,7 @@ class StateNode {
281
295
  * The mapping of events to transitions.
282
296
  */
283
297
  get on() {
284
- return guards_dist_xstateGuards.memo(this, 'on', () => {
298
+ return memo(this, 'on', () => {
285
299
  const transitions = this.transitions;
286
300
  return [...transitions].flatMap(([descriptor, t]) => t.map(t => [descriptor, t])).reduce((map, [descriptor, transition]) => {
287
301
  map[descriptor] = map[descriptor] || [];
@@ -291,16 +305,16 @@ class StateNode {
291
305
  });
292
306
  }
293
307
  get after() {
294
- return guards_dist_xstateGuards.memo(this, 'delayedTransitions', () => guards_dist_xstateGuards.getDelayedTransitions(this));
308
+ return memo(this, 'delayedTransitions', () => guards_dist_xstateGuards.getDelayedTransitions(this));
295
309
  }
296
310
  get initial() {
297
- 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));
298
312
  }
299
313
  next(state, event) {
300
314
  const eventType = event.type;
301
315
  const actions = [];
302
316
  let selectedTransition;
303
- 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));
304
318
  for (const candidate of candidates) {
305
319
  const {
306
320
  guard
@@ -326,7 +340,7 @@ class StateNode {
326
340
  * All the event types accepted by this state node and its descendants.
327
341
  */
328
342
  get events() {
329
- return guards_dist_xstateGuards.memo(this, 'events', () => {
343
+ return memo(this, 'events', () => {
330
344
  const {
331
345
  states
332
346
  } = this;
@@ -451,12 +465,12 @@ class StateMachine {
451
465
  }
452
466
  resolveState(config) {
453
467
  const resolvedStateValue = guards_dist_xstateGuards.resolveStateValue(this.root, config.value);
454
- 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));
455
469
  return guards_dist_xstateGuards.createMachineSnapshot({
456
- configuration: [...configurationSet],
470
+ _nodes: [...nodeSet],
457
471
  context: config.context || {},
458
472
  children: {},
459
- 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',
460
474
  output: config.output,
461
475
  error: config.error,
462
476
  historyValue: config.historyValue
@@ -472,7 +486,7 @@ class StateMachine {
472
486
  */
473
487
  transition(state, event, actorScope) {
474
488
  // TODO: handle error events in a better way
475
- if (guards_dist_xstateGuards.isErrorActorEvent(event) && !state.nextEvents.some(nextEvent => nextEvent === event.type)) {
489
+ if (guards_dist_xstateGuards.isErrorActorEvent(event) && !state.getNextEvents().some(nextEvent => nextEvent === event.type)) {
476
490
  return guards_dist_xstateGuards.cloneMachineSnapshot(state, {
477
491
  status: 'error',
478
492
  error: event.data
@@ -508,7 +522,7 @@ class StateMachine {
508
522
  } = this.config;
509
523
  const preInitial = guards_dist_xstateGuards.createMachineSnapshot({
510
524
  context: typeof context !== 'function' && context ? context : {},
511
- configuration: [this.root],
525
+ _nodes: [this.root],
512
526
  children: {},
513
527
  status: 'active'
514
528
  }, this);
@@ -586,6 +600,7 @@ class StateMachine {
586
600
  const actorRef = guards_dist_xstateGuards.createActor(logic, {
587
601
  id: actorId,
588
602
  parent: _actorScope?.self,
603
+ syncSnapshot: actorData.syncSnapshot,
589
604
  state: actorState,
590
605
  src,
591
606
  systemId: actorData.systemId
@@ -595,7 +610,7 @@ class StateMachine {
595
610
  const restoredSnapshot = guards_dist_xstateGuards.createMachineSnapshot({
596
611
  ...snapshot,
597
612
  children,
598
- 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)))
599
614
  }, this);
600
615
  let seen = new Set();
601
616
  function reviveContext(contextPart, children) {
@@ -699,6 +714,22 @@ function createMachine(config, implementations) {
699
714
  return new StateMachine(config, implementations);
700
715
  }
701
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
+
702
733
  exports.createEmptyActor = actors_dist_xstateActors.createEmptyActor;
703
734
  exports.fromCallback = actors_dist_xstateActors.fromCallback;
704
735
  exports.fromEventObservable = actors_dist_xstateActors.fromEventObservable;
@@ -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;
@@ -30,6 +30,7 @@ export {
30
30
  raise,
31
31
  sendParent,
32
32
  sendTo,
33
+ setup,
33
34
  spawn,
34
35
  stateIn,
35
36
  stop,
@@ -1,8 +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, f as formatTransitions, a as toTransitionConfigArray, b as formatTransition, N as NULL_EVENT, c as memo, e as evaluateGuard, d as createInvokeId, g as getDelayedTransitions, h as formatInitialTransition, i as getCandidates, r as resolveStateValue, j as getConfiguration, k as getStateNodes, l as createMachineSnapshot, n as isInFinalState, o as isErrorActorEvent, p as cloneMachineSnapshot, q as macrostep, s as transitionNode, u as resolveActionsAndContext, v as createInitEvent, w as microstep, x as getInitialStateNodes, y as isStateId, z as getStateNodeByPath, A as getPersistedState, B as resolveReferencedActor, C as createActor, $ as $$ACTOR_TYPE } from './raise-348cc74e.development.esm.js';
3
- export { D as Actor, J as and, O as cancel, C as createActor, k as getStateNodes, E as interpret, F as isMachineSnapshot, G as matchesState, K as not, L as or, H as pathToStateValue, P as raise, R as spawn, M as stateIn, Q as stop, I as toObserver } from './raise-348cc74e.development.esm.js';
4
- import { a as assign } from './send-a0193bdb.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-a0193bdb.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';
6
6
  import '../dev/dist/xstate-dev.development.esm.js';
7
7
 
8
8
  class SimulatedClock {
@@ -54,6 +54,20 @@ class SimulatedClock {
54
54
  }
55
55
  }
56
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
+
57
71
  const EMPTY_OBJECT = {};
58
72
  const toSerializableAction = action => {
59
73
  if (typeof action === 'string') {
@@ -449,12 +463,12 @@ class StateMachine {
449
463
  }
450
464
  resolveState(config) {
451
465
  const resolvedStateValue = resolveStateValue(this.root, config.value);
452
- const configurationSet = getConfiguration(getStateNodes(this.root, resolvedStateValue));
466
+ const nodeSet = getAllStateNodes(getStateNodes(this.root, resolvedStateValue));
453
467
  return createMachineSnapshot({
454
- configuration: [...configurationSet],
468
+ _nodes: [...nodeSet],
455
469
  context: config.context || {},
456
470
  children: {},
457
- status: isInFinalState(configurationSet, this.root) ? 'done' : config.status || 'active',
471
+ status: isInFinalState(nodeSet, this.root) ? 'done' : config.status || 'active',
458
472
  output: config.output,
459
473
  error: config.error,
460
474
  historyValue: config.historyValue
@@ -470,7 +484,7 @@ class StateMachine {
470
484
  */
471
485
  transition(state, event, actorScope) {
472
486
  // TODO: handle error events in a better way
473
- if (isErrorActorEvent(event) && !state.nextEvents.some(nextEvent => nextEvent === event.type)) {
487
+ if (isErrorActorEvent(event) && !state.getNextEvents().some(nextEvent => nextEvent === event.type)) {
474
488
  return cloneMachineSnapshot(state, {
475
489
  status: 'error',
476
490
  error: event.data
@@ -506,7 +520,7 @@ class StateMachine {
506
520
  } = this.config;
507
521
  const preInitial = createMachineSnapshot({
508
522
  context: typeof context !== 'function' && context ? context : {},
509
- configuration: [this.root],
523
+ _nodes: [this.root],
510
524
  children: {},
511
525
  status: 'active'
512
526
  }, this);
@@ -584,6 +598,7 @@ class StateMachine {
584
598
  const actorRef = createActor(logic, {
585
599
  id: actorId,
586
600
  parent: _actorScope?.self,
601
+ syncSnapshot: actorData.syncSnapshot,
587
602
  state: actorState,
588
603
  src,
589
604
  systemId: actorData.systemId
@@ -593,7 +608,7 @@ class StateMachine {
593
608
  const restoredSnapshot = createMachineSnapshot({
594
609
  ...snapshot,
595
610
  children,
596
- configuration: Array.from(getConfiguration(getStateNodes(this.root, snapshot.value)))
611
+ _nodes: Array.from(getAllStateNodes(getStateNodes(this.root, snapshot.value)))
597
612
  }, this);
598
613
  let seen = new Set();
599
614
  function reviveContext(contextPart, children) {
@@ -697,4 +712,20 @@ function createMachine(config, implementations) {
697
712
  return new StateMachine(config, implementations);
698
713
  }
699
714
 
700
- 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,8 +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, f as formatTransitions, a as toTransitionConfigArray, b as formatTransition, N as NULL_EVENT, c as memo, e as evaluateGuard, d as createInvokeId, g as getDelayedTransitions, h as formatInitialTransition, i as getCandidates, r as resolveStateValue, j as getConfiguration, k as getStateNodes, l as createMachineSnapshot, n as isInFinalState, o as isErrorActorEvent, p as cloneMachineSnapshot, q as macrostep, s as transitionNode, u as resolveActionsAndContext, v as createInitEvent, w as microstep, x as getInitialStateNodes, y as isStateId, z as getStateNodeByPath, A as getPersistedState, B as resolveReferencedActor, C as createActor, $ as $$ACTOR_TYPE } from './raise-5854eaca.esm.js';
3
- export { D as Actor, J as and, O as cancel, C as createActor, k as getStateNodes, E as interpret, F as isMachineSnapshot, G as matchesState, K as not, L as or, H as pathToStateValue, P as raise, R as spawn, M as stateIn, Q as stop, I as toObserver } from './raise-5854eaca.esm.js';
4
- import { a as assign } from './send-b7b4befa.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-b7b4befa.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';
6
6
  import '../dev/dist/xstate-dev.esm.js';
7
7
 
8
8
  class SimulatedClock {
@@ -54,6 +54,20 @@ class SimulatedClock {
54
54
  }
55
55
  }
56
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
+
57
71
  const EMPTY_OBJECT = {};
58
72
  const toSerializableAction = action => {
59
73
  if (typeof action === 'string') {
@@ -446,12 +460,12 @@ class StateMachine {
446
460
  }
447
461
  resolveState(config) {
448
462
  const resolvedStateValue = resolveStateValue(this.root, config.value);
449
- const configurationSet = getConfiguration(getStateNodes(this.root, resolvedStateValue));
463
+ const nodeSet = getAllStateNodes(getStateNodes(this.root, resolvedStateValue));
450
464
  return createMachineSnapshot({
451
- configuration: [...configurationSet],
465
+ _nodes: [...nodeSet],
452
466
  context: config.context || {},
453
467
  children: {},
454
- status: isInFinalState(configurationSet, this.root) ? 'done' : config.status || 'active',
468
+ status: isInFinalState(nodeSet, this.root) ? 'done' : config.status || 'active',
455
469
  output: config.output,
456
470
  error: config.error,
457
471
  historyValue: config.historyValue
@@ -467,7 +481,7 @@ class StateMachine {
467
481
  */
468
482
  transition(state, event, actorScope) {
469
483
  // TODO: handle error events in a better way
470
- if (isErrorActorEvent(event) && !state.nextEvents.some(nextEvent => nextEvent === event.type)) {
484
+ if (isErrorActorEvent(event) && !state.getNextEvents().some(nextEvent => nextEvent === event.type)) {
471
485
  return cloneMachineSnapshot(state, {
472
486
  status: 'error',
473
487
  error: event.data
@@ -503,7 +517,7 @@ class StateMachine {
503
517
  } = this.config;
504
518
  const preInitial = createMachineSnapshot({
505
519
  context: typeof context !== 'function' && context ? context : {},
506
- configuration: [this.root],
520
+ _nodes: [this.root],
507
521
  children: {},
508
522
  status: 'active'
509
523
  }, this);
@@ -581,6 +595,7 @@ class StateMachine {
581
595
  const actorRef = createActor(logic, {
582
596
  id: actorId,
583
597
  parent: _actorScope?.self,
598
+ syncSnapshot: actorData.syncSnapshot,
584
599
  state: actorState,
585
600
  src,
586
601
  systemId: actorData.systemId
@@ -590,7 +605,7 @@ class StateMachine {
590
605
  const restoredSnapshot = createMachineSnapshot({
591
606
  ...snapshot,
592
607
  children,
593
- configuration: Array.from(getConfiguration(getStateNodes(this.root, snapshot.value)))
608
+ _nodes: Array.from(getAllStateNodes(getStateNodes(this.root, snapshot.value)))
594
609
  }, this);
595
610
  let seen = new Set();
596
611
  function reviveContext(contextPart, children) {
@@ -691,4 +706,20 @@ function createMachine(config, implementations) {
691
706
  return new StateMachine(config, implementations);
692
707
  }
693
708
 
694
- 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 };