xstate 5.16.0 → 5.17.1

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 (46) 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 +1 -1
  8. package/actors/dist/xstate-actors.development.cjs.js +1 -1
  9. package/actors/dist/xstate-actors.development.esm.js +1 -1
  10. package/actors/dist/xstate-actors.esm.js +1 -1
  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/{raise-a6298350.cjs.js → State-30c95050.cjs.js} +199 -191
  14. package/dist/{raise-7d030497.development.esm.js → State-34039d2a.development.esm.js} +215 -207
  15. package/dist/{raise-bad6a97b.development.cjs.js → State-a2464a1e.development.cjs.js} +214 -206
  16. package/dist/{raise-2cfe6b8f.esm.js → State-cdbc7940.esm.js} +200 -192
  17. package/dist/declarations/src/State.d.ts +12 -11
  18. package/dist/declarations/src/StateMachine.d.ts +11 -14
  19. package/dist/declarations/src/StateNode.d.ts +1 -0
  20. package/dist/declarations/src/actions/stopChild.d.ts +1 -0
  21. package/dist/declarations/src/actors/callback.d.ts +3 -2
  22. package/dist/declarations/src/createActor.d.ts +6 -6
  23. package/dist/declarations/src/createMachine.d.ts +3 -2
  24. package/dist/declarations/src/index.d.ts +11 -12
  25. package/dist/declarations/src/inspection.d.ts +3 -2
  26. package/dist/declarations/src/setup.d.ts +1 -1
  27. package/dist/declarations/src/stateUtils.d.ts +2 -14
  28. package/dist/declarations/src/system.d.ts +3 -2
  29. package/dist/declarations/src/types.d.ts +22 -12
  30. package/dist/declarations/src/utils.d.ts +1 -5
  31. package/dist/{log-f9587b82.cjs.js → log-19086852.cjs.js} +1 -1
  32. package/dist/{log-8320f5e6.esm.js → log-4a38a98a.esm.js} +1 -1
  33. package/dist/{log-17f4495d.development.esm.js → log-62f17756.development.esm.js} +1 -1
  34. package/dist/{log-31321d85.development.cjs.js → log-ec36113c.development.cjs.js} +1 -1
  35. package/dist/xstate.cjs.js +92 -92
  36. package/dist/xstate.development.cjs.js +95 -95
  37. package/dist/xstate.development.esm.js +91 -91
  38. package/dist/xstate.esm.js +88 -88
  39. package/dist/xstate.umd.min.js +1 -1
  40. package/dist/xstate.umd.min.js.map +1 -1
  41. package/guards/dist/xstate-guards.cjs.js +1 -1
  42. package/guards/dist/xstate-guards.development.cjs.js +1 -1
  43. package/guards/dist/xstate-guards.development.esm.js +1 -1
  44. package/guards/dist/xstate-guards.esm.js +1 -1
  45. package/guards/dist/xstate-guards.umd.min.js.map +1 -1
  46. package/package.json +1 -3
@@ -2,9 +2,9 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
+ var guards_dist_xstateGuards = require('./State-a2464a1e.development.cjs.js');
6
+ var log = require('./log-ec36113c.development.cjs.js');
5
7
  var actors_dist_xstateActors = require('../actors/dist/xstate-actors.development.cjs.js');
6
- var guards_dist_xstateGuards = require('./raise-bad6a97b.development.cjs.js');
7
- var log = require('./log-31321d85.development.cjs.js');
8
8
  require('../dev/dist/xstate-dev.development.cjs.js');
9
9
 
10
10
  class SimulatedClock {
@@ -601,78 +601,35 @@ class StateMachine {
601
601
  }
602
602
  }
603
603
 
604
- const defaultWaitForOptions = {
605
- timeout: Infinity // much more than 10 seconds
606
- };
607
-
608
604
  /**
609
- * Subscribes to an actor ref and waits for its emitted value to satisfy a
610
- * predicate, and then resolves with that value. Will throw if the desired state
611
- * is not reached after an optional timeout. (defaults to Infinity).
605
+ * Asserts that the given event object is of the specified type or types. Throws
606
+ * an error if the event object is not of the specified types.
612
607
  *
613
608
  * @example
614
609
  *
615
- * ```js
616
- * const state = await waitFor(someService, (state) => {
617
- * return state.hasTag('loaded');
618
- * });
610
+ * ```ts
611
+ * // ...
612
+ * entry: ({ event }) => {
613
+ * assertEvent(event, 'doNothing');
614
+ * // event is { type: 'doNothing' }
615
+ * },
616
+ * // ...
617
+ * exit: ({ event }) => {
618
+ * assertEvent(event, 'greet');
619
+ * // event is { type: 'greet'; message: string }
619
620
  *
620
- * state.hasTag('loaded'); // true
621
+ * assertEvent(event, ['greet', 'notify']);
622
+ * // event is { type: 'greet'; message: string }
623
+ * // or { type: 'notify'; message: string; level: 'info' | 'error' }
624
+ * },
621
625
  * ```
622
- *
623
- * @param actorRef The actor ref to subscribe to
624
- * @param predicate Determines if a value matches the condition to wait for
625
- * @param options
626
- * @returns A promise that eventually resolves to the emitted value that matches
627
- * the condition
628
626
  */
629
- function waitFor(actorRef, predicate, options) {
630
- const resolvedOptions = {
631
- ...defaultWaitForOptions,
632
- ...options
633
- };
634
- return new Promise((res, rej) => {
635
- let done = false;
636
- if (resolvedOptions.timeout < 0) {
637
- console.error('`timeout` passed to `waitFor` is negative and it will reject its internal promise immediately.');
638
- }
639
- const handle = resolvedOptions.timeout === Infinity ? undefined : setTimeout(() => {
640
- sub.unsubscribe();
641
- rej(new Error(`Timeout of ${resolvedOptions.timeout} ms exceeded`));
642
- }, resolvedOptions.timeout);
643
- const dispose = () => {
644
- clearTimeout(handle);
645
- done = true;
646
- sub?.unsubscribe();
647
- };
648
- function checkEmitted(emitted) {
649
- if (predicate(emitted)) {
650
- dispose();
651
- res(emitted);
652
- }
653
- }
654
- let sub; // avoid TDZ when disposing synchronously
655
-
656
- // See if the current snapshot already matches the predicate
657
- checkEmitted(actorRef.getSnapshot());
658
- if (done) {
659
- return;
660
- }
661
- sub = actorRef.subscribe({
662
- next: checkEmitted,
663
- error: err => {
664
- dispose();
665
- rej(err);
666
- },
667
- complete: () => {
668
- dispose();
669
- rej(new Error(`Actor terminated without satisfying predicate`));
670
- }
671
- });
672
- if (done) {
673
- sub.unsubscribe();
674
- }
675
- });
627
+ function assertEvent(event, type) {
628
+ const types = guards_dist_xstateGuards.toArray(type);
629
+ if (!types.includes(event.type)) {
630
+ const typesText = types.length === 1 ? `type "${types[0]}"` : `one of types "${types.join('", "')}"`;
631
+ throw new Error(`Expected event ${JSON.stringify(event)} to have ${typesText}`);
632
+ }
676
633
  }
677
634
 
678
635
  // this is not 100% accurate since we can't make parallel regions required in the result
@@ -838,43 +795,80 @@ function toPromise(actor) {
838
795
  });
839
796
  }
840
797
 
798
+ const defaultWaitForOptions = {
799
+ timeout: Infinity // much more than 10 seconds
800
+ };
801
+
841
802
  /**
842
- * Asserts that the given event object is of the specified type or types. Throws
843
- * an error if the event object is not of the specified types.
803
+ * Subscribes to an actor ref and waits for its emitted value to satisfy a
804
+ * predicate, and then resolves with that value. Will throw if the desired state
805
+ * is not reached after an optional timeout. (defaults to Infinity).
844
806
  *
845
807
  * @example
846
808
  *
847
- * ```ts
848
- * // ...
849
- * entry: ({ event }) => {
850
- * assertEvent(event, 'doNothing');
851
- * // event is { type: 'doNothing' }
852
- * },
853
- * // ...
854
- * exit: ({ event }) => {
855
- * assertEvent(event, 'greet');
856
- * // event is { type: 'greet'; message: string }
809
+ * ```js
810
+ * const state = await waitFor(someService, (state) => {
811
+ * return state.hasTag('loaded');
812
+ * });
857
813
  *
858
- * assertEvent(event, ['greet', 'notify']);
859
- * // event is { type: 'greet'; message: string }
860
- * // or { type: 'notify'; message: string; level: 'info' | 'error' }
861
- * },
814
+ * state.hasTag('loaded'); // true
862
815
  * ```
816
+ *
817
+ * @param actorRef The actor ref to subscribe to
818
+ * @param predicate Determines if a value matches the condition to wait for
819
+ * @param options
820
+ * @returns A promise that eventually resolves to the emitted value that matches
821
+ * the condition
863
822
  */
864
- function assertEvent(event, type) {
865
- const types = guards_dist_xstateGuards.toArray(type);
866
- if (!types.includes(event.type)) {
867
- const typesText = types.length === 1 ? `type "${types[0]}"` : `one of types "${types.join('", "')}"`;
868
- throw new Error(`Expected event ${JSON.stringify(event)} to have ${typesText}`);
869
- }
823
+ function waitFor(actorRef, predicate, options) {
824
+ const resolvedOptions = {
825
+ ...defaultWaitForOptions,
826
+ ...options
827
+ };
828
+ return new Promise((res, rej) => {
829
+ let done = false;
830
+ if (resolvedOptions.timeout < 0) {
831
+ console.error('`timeout` passed to `waitFor` is negative and it will reject its internal promise immediately.');
832
+ }
833
+ const handle = resolvedOptions.timeout === Infinity ? undefined : setTimeout(() => {
834
+ sub.unsubscribe();
835
+ rej(new Error(`Timeout of ${resolvedOptions.timeout} ms exceeded`));
836
+ }, resolvedOptions.timeout);
837
+ const dispose = () => {
838
+ clearTimeout(handle);
839
+ done = true;
840
+ sub?.unsubscribe();
841
+ };
842
+ function checkEmitted(emitted) {
843
+ if (predicate(emitted)) {
844
+ dispose();
845
+ res(emitted);
846
+ }
847
+ }
848
+ let sub; // avoid TDZ when disposing synchronously
849
+
850
+ // See if the current snapshot already matches the predicate
851
+ checkEmitted(actorRef.getSnapshot());
852
+ if (done) {
853
+ return;
854
+ }
855
+ sub = actorRef.subscribe({
856
+ next: checkEmitted,
857
+ error: err => {
858
+ dispose();
859
+ rej(err);
860
+ },
861
+ complete: () => {
862
+ dispose();
863
+ rej(new Error(`Actor terminated without satisfying predicate`));
864
+ }
865
+ });
866
+ if (done) {
867
+ sub.unsubscribe();
868
+ }
869
+ });
870
870
  }
871
871
 
872
- exports.createEmptyActor = actors_dist_xstateActors.createEmptyActor;
873
- exports.fromCallback = actors_dist_xstateActors.fromCallback;
874
- exports.fromEventObservable = actors_dist_xstateActors.fromEventObservable;
875
- exports.fromObservable = actors_dist_xstateActors.fromObservable;
876
- exports.fromPromise = actors_dist_xstateActors.fromPromise;
877
- exports.fromTransition = actors_dist_xstateActors.fromTransition;
878
872
  exports.Actor = guards_dist_xstateGuards.Actor;
879
873
  exports.__unsafe_getAllOwnEventDescriptors = guards_dist_xstateGuards.getAllOwnEventDescriptors;
880
874
  exports.and = guards_dist_xstateGuards.and;
@@ -901,6 +895,12 @@ exports.forwardTo = log.forwardTo;
901
895
  exports.log = log.log;
902
896
  exports.sendParent = log.sendParent;
903
897
  exports.sendTo = log.sendTo;
898
+ exports.createEmptyActor = actors_dist_xstateActors.createEmptyActor;
899
+ exports.fromCallback = actors_dist_xstateActors.fromCallback;
900
+ exports.fromEventObservable = actors_dist_xstateActors.fromEventObservable;
901
+ exports.fromObservable = actors_dist_xstateActors.fromObservable;
902
+ exports.fromPromise = actors_dist_xstateActors.fromPromise;
903
+ exports.fromTransition = actors_dist_xstateActors.fromTransition;
904
904
  exports.SimulatedClock = SimulatedClock;
905
905
  exports.StateMachine = StateMachine;
906
906
  exports.StateNode = StateNode;
@@ -1,8 +1,8 @@
1
+ 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 macrostep, o as transitionNode, p as resolveActionsAndContext, q as createInitEvent, s as microstep, u as getInitialStateNodes, v as toStatePath, w as isStateId, x as getStateNodeByPath, y as getPersistedSnapshot, z as resolveReferencedActor, A as createActor, $ as $$ACTOR_TYPE } from './State-34039d2a.development.esm.js';
2
+ export { C as Actor, I as __unsafe_getAllOwnEventDescriptors, E as and, M as cancel, A as createActor, j as getStateNodes, D as interpret, B as isMachineSnapshot, J as matchesState, F as not, G as or, K as pathToStateValue, O as raise, P as spawnChild, H as stateIn, Q as stop, R as stopChild, L as toObserver } from './State-34039d2a.development.esm.js';
3
+ import { a as assign } from './log-62f17756.development.esm.js';
4
+ export { S as SpecialTargets, a as assign, e as emit, b as enqueueActions, f as forwardTo, l as log, s as sendParent, c as sendTo } from './log-62f17756.development.esm.js';
1
5
  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, 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 macrostep, o as transitionNode, p as resolveActionsAndContext, q as createInitEvent, s as microstep, u as getInitialStateNodes, v as toStatePath, w as isStateId, x as getStateNodeByPath, y as getPersistedSnapshot, z as resolveReferencedActor, A as createActor, $ as $$ACTOR_TYPE } from './raise-7d030497.development.esm.js';
3
- export { B as Actor, I as __unsafe_getAllOwnEventDescriptors, E as and, M as cancel, A as createActor, j as getStateNodes, C as interpret, D as isMachineSnapshot, J as matchesState, F as not, G as or, K as pathToStateValue, O as raise, P as spawnChild, H as stateIn, Q as stop, R as stopChild, L as toObserver } from './raise-7d030497.development.esm.js';
4
- import { a as assign } from './log-17f4495d.development.esm.js';
5
- export { S as SpecialTargets, a as assign, e as emit, b as enqueueActions, f as forwardTo, l as log, s as sendParent, c as sendTo } from './log-17f4495d.development.esm.js';
6
6
  import '../dev/dist/xstate-dev.development.esm.js';
7
7
 
8
8
  class SimulatedClock {
@@ -599,78 +599,35 @@ class StateMachine {
599
599
  }
600
600
  }
601
601
 
602
- const defaultWaitForOptions = {
603
- timeout: Infinity // much more than 10 seconds
604
- };
605
-
606
602
  /**
607
- * Subscribes to an actor ref and waits for its emitted value to satisfy a
608
- * predicate, and then resolves with that value. Will throw if the desired state
609
- * is not reached after an optional timeout. (defaults to Infinity).
603
+ * Asserts that the given event object is of the specified type or types. Throws
604
+ * an error if the event object is not of the specified types.
610
605
  *
611
606
  * @example
612
607
  *
613
- * ```js
614
- * const state = await waitFor(someService, (state) => {
615
- * return state.hasTag('loaded');
616
- * });
608
+ * ```ts
609
+ * // ...
610
+ * entry: ({ event }) => {
611
+ * assertEvent(event, 'doNothing');
612
+ * // event is { type: 'doNothing' }
613
+ * },
614
+ * // ...
615
+ * exit: ({ event }) => {
616
+ * assertEvent(event, 'greet');
617
+ * // event is { type: 'greet'; message: string }
617
618
  *
618
- * state.hasTag('loaded'); // true
619
+ * assertEvent(event, ['greet', 'notify']);
620
+ * // event is { type: 'greet'; message: string }
621
+ * // or { type: 'notify'; message: string; level: 'info' | 'error' }
622
+ * },
619
623
  * ```
620
- *
621
- * @param actorRef The actor ref to subscribe to
622
- * @param predicate Determines if a value matches the condition to wait for
623
- * @param options
624
- * @returns A promise that eventually resolves to the emitted value that matches
625
- * the condition
626
624
  */
627
- function waitFor(actorRef, predicate, options) {
628
- const resolvedOptions = {
629
- ...defaultWaitForOptions,
630
- ...options
631
- };
632
- return new Promise((res, rej) => {
633
- let done = false;
634
- if (resolvedOptions.timeout < 0) {
635
- console.error('`timeout` passed to `waitFor` is negative and it will reject its internal promise immediately.');
636
- }
637
- const handle = resolvedOptions.timeout === Infinity ? undefined : setTimeout(() => {
638
- sub.unsubscribe();
639
- rej(new Error(`Timeout of ${resolvedOptions.timeout} ms exceeded`));
640
- }, resolvedOptions.timeout);
641
- const dispose = () => {
642
- clearTimeout(handle);
643
- done = true;
644
- sub?.unsubscribe();
645
- };
646
- function checkEmitted(emitted) {
647
- if (predicate(emitted)) {
648
- dispose();
649
- res(emitted);
650
- }
651
- }
652
- let sub; // avoid TDZ when disposing synchronously
653
-
654
- // See if the current snapshot already matches the predicate
655
- checkEmitted(actorRef.getSnapshot());
656
- if (done) {
657
- return;
658
- }
659
- sub = actorRef.subscribe({
660
- next: checkEmitted,
661
- error: err => {
662
- dispose();
663
- rej(err);
664
- },
665
- complete: () => {
666
- dispose();
667
- rej(new Error(`Actor terminated without satisfying predicate`));
668
- }
669
- });
670
- if (done) {
671
- sub.unsubscribe();
672
- }
673
- });
625
+ function assertEvent(event, type) {
626
+ const types = toArray(type);
627
+ if (!types.includes(event.type)) {
628
+ const typesText = types.length === 1 ? `type "${types[0]}"` : `one of types "${types.join('", "')}"`;
629
+ throw new Error(`Expected event ${JSON.stringify(event)} to have ${typesText}`);
630
+ }
674
631
  }
675
632
 
676
633
  // this is not 100% accurate since we can't make parallel regions required in the result
@@ -836,35 +793,78 @@ function toPromise(actor) {
836
793
  });
837
794
  }
838
795
 
796
+ const defaultWaitForOptions = {
797
+ timeout: Infinity // much more than 10 seconds
798
+ };
799
+
839
800
  /**
840
- * Asserts that the given event object is of the specified type or types. Throws
841
- * an error if the event object is not of the specified types.
801
+ * Subscribes to an actor ref and waits for its emitted value to satisfy a
802
+ * predicate, and then resolves with that value. Will throw if the desired state
803
+ * is not reached after an optional timeout. (defaults to Infinity).
842
804
  *
843
805
  * @example
844
806
  *
845
- * ```ts
846
- * // ...
847
- * entry: ({ event }) => {
848
- * assertEvent(event, 'doNothing');
849
- * // event is { type: 'doNothing' }
850
- * },
851
- * // ...
852
- * exit: ({ event }) => {
853
- * assertEvent(event, 'greet');
854
- * // event is { type: 'greet'; message: string }
807
+ * ```js
808
+ * const state = await waitFor(someService, (state) => {
809
+ * return state.hasTag('loaded');
810
+ * });
855
811
  *
856
- * assertEvent(event, ['greet', 'notify']);
857
- * // event is { type: 'greet'; message: string }
858
- * // or { type: 'notify'; message: string; level: 'info' | 'error' }
859
- * },
812
+ * state.hasTag('loaded'); // true
860
813
  * ```
814
+ *
815
+ * @param actorRef The actor ref to subscribe to
816
+ * @param predicate Determines if a value matches the condition to wait for
817
+ * @param options
818
+ * @returns A promise that eventually resolves to the emitted value that matches
819
+ * the condition
861
820
  */
862
- function assertEvent(event, type) {
863
- const types = toArray(type);
864
- if (!types.includes(event.type)) {
865
- const typesText = types.length === 1 ? `type "${types[0]}"` : `one of types "${types.join('", "')}"`;
866
- throw new Error(`Expected event ${JSON.stringify(event)} to have ${typesText}`);
867
- }
821
+ function waitFor(actorRef, predicate, options) {
822
+ const resolvedOptions = {
823
+ ...defaultWaitForOptions,
824
+ ...options
825
+ };
826
+ return new Promise((res, rej) => {
827
+ let done = false;
828
+ if (resolvedOptions.timeout < 0) {
829
+ console.error('`timeout` passed to `waitFor` is negative and it will reject its internal promise immediately.');
830
+ }
831
+ const handle = resolvedOptions.timeout === Infinity ? undefined : setTimeout(() => {
832
+ sub.unsubscribe();
833
+ rej(new Error(`Timeout of ${resolvedOptions.timeout} ms exceeded`));
834
+ }, resolvedOptions.timeout);
835
+ const dispose = () => {
836
+ clearTimeout(handle);
837
+ done = true;
838
+ sub?.unsubscribe();
839
+ };
840
+ function checkEmitted(emitted) {
841
+ if (predicate(emitted)) {
842
+ dispose();
843
+ res(emitted);
844
+ }
845
+ }
846
+ let sub; // avoid TDZ when disposing synchronously
847
+
848
+ // See if the current snapshot already matches the predicate
849
+ checkEmitted(actorRef.getSnapshot());
850
+ if (done) {
851
+ return;
852
+ }
853
+ sub = actorRef.subscribe({
854
+ next: checkEmitted,
855
+ error: err => {
856
+ dispose();
857
+ rej(err);
858
+ },
859
+ complete: () => {
860
+ dispose();
861
+ rej(new Error(`Actor terminated without satisfying predicate`));
862
+ }
863
+ });
864
+ if (done) {
865
+ sub.unsubscribe();
866
+ }
867
+ });
868
868
  }
869
869
 
870
870
  export { SimulatedClock, StateMachine, StateNode, assertEvent, createMachine, getInitialSnapshot, getNextSnapshot, setup, toPromise, waitFor };
@@ -1,8 +1,8 @@
1
+ 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 macrostep, o as transitionNode, p as resolveActionsAndContext, q as createInitEvent, s as microstep, u as getInitialStateNodes, v as toStatePath, w as isStateId, x as getStateNodeByPath, y as getPersistedSnapshot, z as resolveReferencedActor, A as createActor, $ as $$ACTOR_TYPE } from './State-cdbc7940.esm.js';
2
+ export { C as Actor, I as __unsafe_getAllOwnEventDescriptors, E as and, M as cancel, A as createActor, j as getStateNodes, D as interpret, B as isMachineSnapshot, J as matchesState, F as not, G as or, K as pathToStateValue, O as raise, P as spawnChild, H as stateIn, Q as stop, R as stopChild, L as toObserver } from './State-cdbc7940.esm.js';
3
+ import { a as assign } from './log-4a38a98a.esm.js';
4
+ export { S as SpecialTargets, a as assign, e as emit, b as enqueueActions, f as forwardTo, l as log, s as sendParent, c as sendTo } from './log-4a38a98a.esm.js';
1
5
  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, 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 macrostep, o as transitionNode, p as resolveActionsAndContext, q as createInitEvent, s as microstep, u as getInitialStateNodes, v as toStatePath, w as isStateId, x as getStateNodeByPath, y as getPersistedSnapshot, z as resolveReferencedActor, A as createActor, $ as $$ACTOR_TYPE } from './raise-2cfe6b8f.esm.js';
3
- export { B as Actor, I as __unsafe_getAllOwnEventDescriptors, E as and, M as cancel, A as createActor, j as getStateNodes, C as interpret, D as isMachineSnapshot, J as matchesState, F as not, G as or, K as pathToStateValue, O as raise, P as spawnChild, H as stateIn, Q as stop, R as stopChild, L as toObserver } from './raise-2cfe6b8f.esm.js';
4
- import { a as assign } from './log-8320f5e6.esm.js';
5
- export { S as SpecialTargets, a as assign, e as emit, b as enqueueActions, f as forwardTo, l as log, s as sendParent, c as sendTo } from './log-8320f5e6.esm.js';
6
6
  import '../dev/dist/xstate-dev.esm.js';
7
7
 
8
8
  class SimulatedClock {
@@ -596,75 +596,35 @@ class StateMachine {
596
596
  }
597
597
  }
598
598
 
599
- const defaultWaitForOptions = {
600
- timeout: Infinity // much more than 10 seconds
601
- };
602
-
603
599
  /**
604
- * Subscribes to an actor ref and waits for its emitted value to satisfy a
605
- * predicate, and then resolves with that value. Will throw if the desired state
606
- * is not reached after an optional timeout. (defaults to Infinity).
600
+ * Asserts that the given event object is of the specified type or types. Throws
601
+ * an error if the event object is not of the specified types.
607
602
  *
608
603
  * @example
609
604
  *
610
- * ```js
611
- * const state = await waitFor(someService, (state) => {
612
- * return state.hasTag('loaded');
613
- * });
605
+ * ```ts
606
+ * // ...
607
+ * entry: ({ event }) => {
608
+ * assertEvent(event, 'doNothing');
609
+ * // event is { type: 'doNothing' }
610
+ * },
611
+ * // ...
612
+ * exit: ({ event }) => {
613
+ * assertEvent(event, 'greet');
614
+ * // event is { type: 'greet'; message: string }
614
615
  *
615
- * state.hasTag('loaded'); // true
616
+ * assertEvent(event, ['greet', 'notify']);
617
+ * // event is { type: 'greet'; message: string }
618
+ * // or { type: 'notify'; message: string; level: 'info' | 'error' }
619
+ * },
616
620
  * ```
617
- *
618
- * @param actorRef The actor ref to subscribe to
619
- * @param predicate Determines if a value matches the condition to wait for
620
- * @param options
621
- * @returns A promise that eventually resolves to the emitted value that matches
622
- * the condition
623
621
  */
624
- function waitFor(actorRef, predicate, options) {
625
- const resolvedOptions = {
626
- ...defaultWaitForOptions,
627
- ...options
628
- };
629
- return new Promise((res, rej) => {
630
- let done = false;
631
- const handle = resolvedOptions.timeout === Infinity ? undefined : setTimeout(() => {
632
- sub.unsubscribe();
633
- rej(new Error(`Timeout of ${resolvedOptions.timeout} ms exceeded`));
634
- }, resolvedOptions.timeout);
635
- const dispose = () => {
636
- clearTimeout(handle);
637
- done = true;
638
- sub?.unsubscribe();
639
- };
640
- function checkEmitted(emitted) {
641
- if (predicate(emitted)) {
642
- dispose();
643
- res(emitted);
644
- }
645
- }
646
- let sub; // avoid TDZ when disposing synchronously
647
-
648
- // See if the current snapshot already matches the predicate
649
- checkEmitted(actorRef.getSnapshot());
650
- if (done) {
651
- return;
652
- }
653
- sub = actorRef.subscribe({
654
- next: checkEmitted,
655
- error: err => {
656
- dispose();
657
- rej(err);
658
- },
659
- complete: () => {
660
- dispose();
661
- rej(new Error(`Actor terminated without satisfying predicate`));
662
- }
663
- });
664
- if (done) {
665
- sub.unsubscribe();
666
- }
667
- });
622
+ function assertEvent(event, type) {
623
+ const types = toArray(type);
624
+ if (!types.includes(event.type)) {
625
+ const typesText = types.length === 1 ? `type "${types[0]}"` : `one of types "${types.join('", "')}"`;
626
+ throw new Error(`Expected event ${JSON.stringify(event)} to have ${typesText}`);
627
+ }
668
628
  }
669
629
 
670
630
  // this is not 100% accurate since we can't make parallel regions required in the result
@@ -830,35 +790,75 @@ function toPromise(actor) {
830
790
  });
831
791
  }
832
792
 
793
+ const defaultWaitForOptions = {
794
+ timeout: Infinity // much more than 10 seconds
795
+ };
796
+
833
797
  /**
834
- * Asserts that the given event object is of the specified type or types. Throws
835
- * an error if the event object is not of the specified types.
798
+ * Subscribes to an actor ref and waits for its emitted value to satisfy a
799
+ * predicate, and then resolves with that value. Will throw if the desired state
800
+ * is not reached after an optional timeout. (defaults to Infinity).
836
801
  *
837
802
  * @example
838
803
  *
839
- * ```ts
840
- * // ...
841
- * entry: ({ event }) => {
842
- * assertEvent(event, 'doNothing');
843
- * // event is { type: 'doNothing' }
844
- * },
845
- * // ...
846
- * exit: ({ event }) => {
847
- * assertEvent(event, 'greet');
848
- * // event is { type: 'greet'; message: string }
804
+ * ```js
805
+ * const state = await waitFor(someService, (state) => {
806
+ * return state.hasTag('loaded');
807
+ * });
849
808
  *
850
- * assertEvent(event, ['greet', 'notify']);
851
- * // event is { type: 'greet'; message: string }
852
- * // or { type: 'notify'; message: string; level: 'info' | 'error' }
853
- * },
809
+ * state.hasTag('loaded'); // true
854
810
  * ```
811
+ *
812
+ * @param actorRef The actor ref to subscribe to
813
+ * @param predicate Determines if a value matches the condition to wait for
814
+ * @param options
815
+ * @returns A promise that eventually resolves to the emitted value that matches
816
+ * the condition
855
817
  */
856
- function assertEvent(event, type) {
857
- const types = toArray(type);
858
- if (!types.includes(event.type)) {
859
- const typesText = types.length === 1 ? `type "${types[0]}"` : `one of types "${types.join('", "')}"`;
860
- throw new Error(`Expected event ${JSON.stringify(event)} to have ${typesText}`);
861
- }
818
+ function waitFor(actorRef, predicate, options) {
819
+ const resolvedOptions = {
820
+ ...defaultWaitForOptions,
821
+ ...options
822
+ };
823
+ return new Promise((res, rej) => {
824
+ let done = false;
825
+ const handle = resolvedOptions.timeout === Infinity ? undefined : setTimeout(() => {
826
+ sub.unsubscribe();
827
+ rej(new Error(`Timeout of ${resolvedOptions.timeout} ms exceeded`));
828
+ }, resolvedOptions.timeout);
829
+ const dispose = () => {
830
+ clearTimeout(handle);
831
+ done = true;
832
+ sub?.unsubscribe();
833
+ };
834
+ function checkEmitted(emitted) {
835
+ if (predicate(emitted)) {
836
+ dispose();
837
+ res(emitted);
838
+ }
839
+ }
840
+ let sub; // avoid TDZ when disposing synchronously
841
+
842
+ // See if the current snapshot already matches the predicate
843
+ checkEmitted(actorRef.getSnapshot());
844
+ if (done) {
845
+ return;
846
+ }
847
+ sub = actorRef.subscribe({
848
+ next: checkEmitted,
849
+ error: err => {
850
+ dispose();
851
+ rej(err);
852
+ },
853
+ complete: () => {
854
+ dispose();
855
+ rej(new Error(`Actor terminated without satisfying predicate`));
856
+ }
857
+ });
858
+ if (done) {
859
+ sub.unsubscribe();
860
+ }
861
+ });
862
862
  }
863
863
 
864
864
  export { SimulatedClock, StateMachine, StateNode, assertEvent, createMachine, getInitialSnapshot, getNextSnapshot, setup, toPromise, waitFor };