xstate 5.0.0-beta.7 → 5.0.0-beta.9

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 (62) hide show
  1. package/actions/dist/xstate-actions.cjs.d.mts +2 -0
  2. package/actions/dist/xstate-actions.cjs.d.mts.map +1 -0
  3. package/actions/dist/xstate-actions.cjs.d.ts +1 -0
  4. package/actions/dist/xstate-actions.cjs.d.ts.map +1 -0
  5. package/actions/dist/xstate-actions.cjs.dev.js +2 -1
  6. package/actions/dist/xstate-actions.cjs.mjs +25 -0
  7. package/actions/dist/xstate-actions.cjs.prod.js +3 -2
  8. package/actions/dist/xstate-actions.esm.js +1 -1
  9. package/actions/dist/xstate-actions.umd.min.js +1 -1
  10. package/actions/dist/xstate-actions.umd.min.js.map +1 -1
  11. package/actors/dist/xstate-actors.cjs.d.mts +2 -0
  12. package/actors/dist/xstate-actors.cjs.d.mts.map +1 -0
  13. package/actors/dist/xstate-actors.cjs.d.ts +1 -0
  14. package/actors/dist/xstate-actors.cjs.d.ts.map +1 -0
  15. package/actors/dist/xstate-actors.cjs.dev.js +2 -1
  16. package/actors/dist/xstate-actors.cjs.mjs +15 -0
  17. package/actors/dist/xstate-actors.cjs.prod.js +3 -2
  18. package/actors/dist/xstate-actors.esm.js +1 -1
  19. package/actors/dist/xstate-actors.umd.min.js +1 -1
  20. package/actors/dist/xstate-actors.umd.min.js.map +1 -1
  21. package/dev/dist/xstate-dev.cjs.d.mts +2 -0
  22. package/dev/dist/xstate-dev.cjs.d.mts.map +1 -0
  23. package/dev/dist/xstate-dev.cjs.d.ts +1 -0
  24. package/dev/dist/xstate-dev.cjs.d.ts.map +1 -0
  25. package/dev/dist/xstate-dev.cjs.mjs +5 -0
  26. package/dev/dist/xstate-dev.cjs.prod.js +6 -43
  27. package/dev/dist/xstate-dev.umd.min.js.map +1 -1
  28. package/dist/{actions-0fcf4fd9.cjs.dev.js → actions-b6357569.cjs.dev.js} +252 -157
  29. package/dist/{actions-a1a641d3.cjs.prod.js → actions-bd4a184d.cjs.prod.js} +279 -160
  30. package/dist/{actions-b334e916.esm.js → actions-de434a04.esm.js} +208 -147
  31. package/dist/declarations/src/StateMachine.d.ts +2 -2
  32. package/dist/declarations/src/actions.d.ts +1 -0
  33. package/dist/declarations/src/actors/index.d.ts +2 -1
  34. package/dist/declarations/src/actors/observable.d.ts +1 -2
  35. package/dist/declarations/src/actors/promise.d.ts +1 -2
  36. package/dist/declarations/src/index.d.ts +12 -28
  37. package/dist/declarations/src/interpreter.d.ts +3 -2
  38. package/dist/declarations/src/typegenTypes.d.ts +7 -1
  39. package/dist/declarations/src/types.d.ts +5 -4
  40. package/dist/declarations/src/waitFor.d.ts +33 -0
  41. package/dist/index-0f3fdf0c.cjs.prod.js +52 -0
  42. package/dist/xstate.cjs.d.mts +2 -0
  43. package/dist/xstate.cjs.d.mts.map +1 -0
  44. package/dist/xstate.cjs.d.ts +1 -0
  45. package/dist/xstate.cjs.d.ts.map +1 -0
  46. package/dist/xstate.cjs.dev.js +97 -68
  47. package/dist/xstate.cjs.mjs +39 -0
  48. package/dist/xstate.cjs.prod.js +95 -69
  49. package/dist/xstate.esm.js +80 -57
  50. package/dist/xstate.umd.min.js +1 -1
  51. package/dist/xstate.umd.min.js.map +1 -1
  52. package/guards/dist/xstate-guards.cjs.d.mts +2 -0
  53. package/guards/dist/xstate-guards.cjs.d.mts.map +1 -0
  54. package/guards/dist/xstate-guards.cjs.d.ts +1 -0
  55. package/guards/dist/xstate-guards.cjs.d.ts.map +1 -0
  56. package/guards/dist/xstate-guards.cjs.dev.js +1 -1
  57. package/guards/dist/xstate-guards.cjs.mjs +8 -0
  58. package/guards/dist/xstate-guards.cjs.prod.js +2 -2
  59. package/guards/dist/xstate-guards.esm.js +1 -1
  60. package/guards/dist/xstate-guards.umd.min.js.map +1 -1
  61. package/package.json +7 -1
  62. package/dist/declarations/src/schema.d.ts +0 -2
@@ -2,29 +2,8 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var actors_dist_xstateActors = require('./actions-a1a641d3.cjs.prod.js');
6
- require('../dev/dist/xstate-dev.cjs.prod.js');
7
-
8
- function pure(getActions) {
9
- return actors_dist_xstateActors.createDynamicAction({
10
- type: actors_dist_xstateActors.pure,
11
- params: {
12
- get: getActions
13
- }
14
- }, function (_event, _ref) {
15
- var _toArray;
16
- var state = _ref.state;
17
- return [state, {
18
- type: actors_dist_xstateActors.pure,
19
- params: {
20
- actions: (_toArray = actors_dist_xstateActors.toArray(actors_dist_xstateActors.toActionObjects(getActions({
21
- context: state.context,
22
- event: _event.data
23
- })))) !== null && _toArray !== void 0 ? _toArray : []
24
- }
25
- }];
26
- });
27
- }
5
+ var actors_dist_xstateActors = require('./actions-bd4a184d.cjs.prod.js');
6
+ require('./index-0f3fdf0c.cjs.prod.js');
28
7
 
29
8
  var _excluded = ["onDone", "onError"];
30
9
  var EMPTY_OBJECT = {};
@@ -235,9 +214,9 @@ var StateNode = /*#__PURE__*/function () {
235
214
  id: resolvedId,
236
215
  systemId: systemId,
237
216
  toJSON: function toJSON() {
238
- var onDone = invokeConfig.onDone,
239
- onError = invokeConfig.onError,
240
- invokeDefValues = actors_dist_xstateActors._objectWithoutProperties(invokeConfig, _excluded);
217
+ invokeConfig.onDone;
218
+ invokeConfig.onError;
219
+ var invokeDefValues = actors_dist_xstateActors._objectWithoutProperties(invokeConfig, _excluded);
241
220
  return actors_dist_xstateActors._objectSpread2(actors_dist_xstateActors._objectSpread2({}, invokeDefValues), {}, {
242
221
  type: actors_dist_xstateActors.invoke,
243
222
  src: resolvedSrc,
@@ -426,13 +405,13 @@ var StateMachine = /*#__PURE__*/function () {
426
405
  * The raw config used to create the machine.
427
406
  */
428
407
  config, options) {
429
- var _this$config$schema;
408
+ var _this$config$types;
430
409
  actors_dist_xstateActors._classCallCheck(this, StateMachine);
431
410
  this.config = config;
432
411
  actors_dist_xstateActors._defineProperty(this, "version", void 0);
433
412
  actors_dist_xstateActors._defineProperty(this, "delimiter", void 0);
434
413
  actors_dist_xstateActors._defineProperty(this, "options", void 0);
435
- actors_dist_xstateActors._defineProperty(this, "schema", void 0);
414
+ actors_dist_xstateActors._defineProperty(this, "types", void 0);
436
415
  actors_dist_xstateActors._defineProperty(this, "__xstatenode", true);
437
416
  actors_dist_xstateActors._defineProperty(this, "idMap", new Map());
438
417
  actors_dist_xstateActors._defineProperty(this, "root", void 0);
@@ -448,7 +427,7 @@ var StateMachine = /*#__PURE__*/function () {
448
427
  this.options = Object.assign(createDefaultOptions(), options);
449
428
  this.delimiter = this.config.delimiter || actors_dist_xstateActors.STATE_DELIMITER;
450
429
  this.version = this.config.version;
451
- this.schema = (_this$config$schema = this.config.schema) !== null && _this$config$schema !== void 0 ? _this$config$schema : {};
430
+ this.types = (_this$config$types = this.config.types) !== null && _this$config$types !== void 0 ? _this$config$types : {};
452
431
  this.transition = this.transition.bind(this);
453
432
  this.root = new StateNode(config, {
454
433
  _key: this.id,
@@ -780,11 +759,6 @@ function mapState(stateMap, stateId) {
780
759
  return stateMap[foundStateId];
781
760
  }
782
761
 
783
- function createSchema(schema) {
784
- return schema;
785
- }
786
- var t = createSchema;
787
-
788
762
  var SimulatedClock = /*#__PURE__*/function () {
789
763
  function SimulatedClock() {
790
764
  actors_dist_xstateActors._classCallCheck(this, SimulatedClock);
@@ -832,12 +806,12 @@ var SimulatedClock = /*#__PURE__*/function () {
832
806
  value: function flushTimeouts() {
833
807
  var _this = this;
834
808
  actors_dist_xstateActors._toConsumableArray(this.timeouts).sort(function (_ref, _ref2) {
835
- var _ref3 = actors_dist_xstateActors._slicedToArray(_ref, 2),
836
- _idA = _ref3[0],
837
- timeoutA = _ref3[1];
838
- var _ref4 = actors_dist_xstateActors._slicedToArray(_ref2, 2),
839
- _idB = _ref4[0],
840
- timeoutB = _ref4[1];
809
+ var _ref3 = actors_dist_xstateActors._slicedToArray(_ref, 2);
810
+ _ref3[0];
811
+ var timeoutA = _ref3[1];
812
+ var _ref4 = actors_dist_xstateActors._slicedToArray(_ref2, 2);
813
+ _ref4[0];
814
+ var timeoutB = _ref4[1];
841
815
  var endA = timeoutA.start + timeoutA.timeout;
842
816
  var endB = timeoutB.start + timeoutB.timeout;
843
817
  return endB > endA ? -1 : 1;
@@ -861,61 +835,113 @@ var SimulatedClock = /*#__PURE__*/function () {
861
835
  return SimulatedClock;
862
836
  }();
863
837
 
864
- var actions = {
865
- raise: actors_dist_xstateActors.raise,
866
- send: actors_dist_xstateActors.send,
867
- sendParent: actors_dist_xstateActors.sendParent,
868
- sendTo: actors_dist_xstateActors.sendTo,
869
- log: actors_dist_xstateActors.log,
870
- cancel: actors_dist_xstateActors.cancel,
871
- stop: actors_dist_xstateActors.stop,
872
- assign: actors_dist_xstateActors.assign,
873
- after: actors_dist_xstateActors.after,
874
- done: actors_dist_xstateActors.done,
875
- respond: actors_dist_xstateActors.respond,
876
- forwardTo: actors_dist_xstateActors.forwardTo,
877
- escalate: actors_dist_xstateActors.escalate,
878
- choose: actors_dist_xstateActors.choose,
879
- pure: pure
838
+ var defaultWaitForOptions = {
839
+ timeout: 10000 // 10 seconds
880
840
  };
881
841
 
842
+ /**
843
+ * Subscribes to an actor ref and waits for its emitted value to satisfy
844
+ * a predicate, and then resolves with that value.
845
+ * Will throw if the desired state is not reached after a timeout
846
+ * (defaults to 10 seconds).
847
+ *
848
+ * @example
849
+ * ```js
850
+ * const state = await waitFor(someService, state => {
851
+ * return state.hasTag('loaded');
852
+ * });
853
+ *
854
+ * state.hasTag('loaded'); // true
855
+ * ```
856
+ *
857
+ * @param actorRef The actor ref to subscribe to
858
+ * @param predicate Determines if a value matches the condition to wait for
859
+ * @param options
860
+ * @returns A promise that eventually resolves to the emitted value
861
+ * that matches the condition
862
+ */
863
+ function waitFor(actorRef, predicate, options) {
864
+ var resolvedOptions = actors_dist_xstateActors._objectSpread2(actors_dist_xstateActors._objectSpread2({}, defaultWaitForOptions), options);
865
+ return new Promise(function (res, rej) {
866
+ var done = false;
867
+ var handle = resolvedOptions.timeout === Infinity ? undefined : setTimeout(function () {
868
+ sub.unsubscribe();
869
+ rej(new Error("Timeout of ".concat(resolvedOptions.timeout, " ms exceeded")));
870
+ }, resolvedOptions.timeout);
871
+ var dispose = function dispose() {
872
+ clearTimeout(handle);
873
+ done = true;
874
+ sub === null || sub === void 0 ? void 0 : sub.unsubscribe();
875
+ };
876
+ function checkEmitted(emitted) {
877
+ if (predicate(emitted)) {
878
+ dispose();
879
+ res(emitted);
880
+ }
881
+ }
882
+
883
+ // See if the current snapshot already matches the predicate
884
+ checkEmitted(actorRef.getSnapshot());
885
+ var sub = actorRef.subscribe({
886
+ next: checkEmitted,
887
+ error: function error(err) {
888
+ dispose();
889
+ rej(err);
890
+ },
891
+ complete: function complete() {
892
+ dispose();
893
+ rej(new Error("Actor terminated without satisfying predicate"));
894
+ }
895
+ });
896
+ if (done) {
897
+ sub.unsubscribe();
898
+ }
899
+ });
900
+ }
901
+
882
902
  Object.defineProperty(exports, 'ActionTypes', {
883
903
  enumerable: true,
884
- get: function () {
885
- return actors_dist_xstateActors.ActionTypes;
886
- }
904
+ get: function () { return actors_dist_xstateActors.ActionTypes; }
887
905
  });
888
906
  exports.Interpreter = actors_dist_xstateActors.Interpreter;
889
907
  Object.defineProperty(exports, 'InterpreterStatus', {
890
908
  enumerable: true,
891
- get: function () {
892
- return actors_dist_xstateActors.ActorStatus;
893
- }
909
+ get: function () { return actors_dist_xstateActors.ActorStatus; }
894
910
  });
895
911
  Object.defineProperty(exports, 'SpecialTargets', {
896
912
  enumerable: true,
897
- get: function () {
898
- return actors_dist_xstateActors.SpecialTargets;
899
- }
913
+ get: function () { return actors_dist_xstateActors.SpecialTargets; }
900
914
  });
901
915
  exports.State = actors_dist_xstateActors.State;
916
+ exports.and = actors_dist_xstateActors.and;
902
917
  exports.assign = actors_dist_xstateActors.assign;
918
+ exports.cancel = actors_dist_xstateActors.cancel;
919
+ exports.choose = actors_dist_xstateActors.choose;
903
920
  exports.doneInvoke = actors_dist_xstateActors.doneInvoke;
904
921
  exports.forwardTo = actors_dist_xstateActors.forwardTo;
922
+ exports.fromCallback = actors_dist_xstateActors.fromCallback;
923
+ exports.fromEventObservable = actors_dist_xstateActors.fromEventObservable;
924
+ exports.fromObservable = actors_dist_xstateActors.fromObservable;
925
+ exports.fromPromise = actors_dist_xstateActors.fromPromise;
926
+ exports.fromTransition = actors_dist_xstateActors.fromTransition;
905
927
  exports.getStateNodes = actors_dist_xstateActors.getStateNodes;
906
928
  exports.interpret = actors_dist_xstateActors.interpret;
929
+ exports.log = actors_dist_xstateActors.log;
907
930
  exports.matchesState = actors_dist_xstateActors.matchesState;
931
+ exports.not = actors_dist_xstateActors.not;
932
+ exports.or = actors_dist_xstateActors.or;
908
933
  exports.pathToStateValue = actors_dist_xstateActors.pathToStateValue;
909
- exports.send = actors_dist_xstateActors.send;
934
+ exports.pure = actors_dist_xstateActors.pure;
935
+ exports.raise = actors_dist_xstateActors.raise;
910
936
  exports.sendParent = actors_dist_xstateActors.sendParent;
911
937
  exports.sendTo = actors_dist_xstateActors.sendTo;
938
+ exports.stateIn = actors_dist_xstateActors.stateIn;
939
+ exports.stop = actors_dist_xstateActors.stop;
912
940
  exports.toObserver = actors_dist_xstateActors.toObserver;
913
941
  exports.toSCXMLEvent = actors_dist_xstateActors.toSCXMLEvent;
914
942
  exports.SimulatedClock = SimulatedClock;
915
943
  exports.StateMachine = StateMachine;
916
944
  exports.StateNode = StateNode;
917
- exports.actions = actions;
918
945
  exports.createMachine = createMachine;
919
- exports.createSchema = createSchema;
920
946
  exports.mapState = mapState;
921
- exports.t = t;
947
+ exports.waitFor = waitFor;
@@ -1,28 +1,7 @@
1
- import { c as createDynamicAction, p as pure$1, t as toArray, a as toActionObjects, _ as _createClass, f as formatTransitions, b as toTransitionConfigArray, N as NULL_EVENT, d as formatTransition, m as mapValues, e as memo, g as _createForOfIteratorHelper, h as evaluateGuard, i as _toConsumableArray, j as flatten, k as _classCallCheck, l as _defineProperty, n as createInvokeId, o as toInvokeConfig, q as _objectSpread2, r as invoke, s as _objectWithoutProperties, u as getDelayedTransitions, v as formatInitialTransition, w as getCandidates, x as isString, y as createSpawner, z as createInitEvent, A as getConfiguration, B as getStateNodes, C as resolveStateValue, D as isInFinalState, S as State, E as toSCXMLEvent, F as isSCXMLErrorEvent, G as macrostep, H as transitionNode, I as _slicedToArray, J as getInitialConfiguration, K as resolveActionsAndContext, L as microstep, M as error, O as isStateId, P as getStateNodeByPath, Q as getPersistedState, R as resolveReferencedActor, T as interpret, U as STATE_DELIMITER, V as initEvent, W as matchesState, X as raise, Y as send, Z as sendParent, $ as sendTo, a0 as log, a1 as cancel, a2 as stop, a3 as assign, a4 as after, a5 as done, a6 as respond, a7 as forwardTo, a8 as escalate, a9 as choose } from './actions-b334e916.esm.js';
2
- export { af as ActionTypes, aa as Interpreter, ab as InterpreterStatus, ag as SpecialTargets, S as State, a3 as assign, ac as doneInvoke, a7 as forwardTo, B as getStateNodes, T as interpret, W as matchesState, ad as pathToStateValue, Y as send, Z as sendParent, $ as sendTo, ae as toObserver, E as toSCXMLEvent } from './actions-b334e916.esm.js';
1
+ import { _ as _createClass, f as formatTransitions, t as toTransitionConfigArray, N as NULL_EVENT, a as formatTransition, m as mapValues, b as memo, c as _createForOfIteratorHelper, e as evaluateGuard, d as _toConsumableArray, g as flatten, h as _classCallCheck, i as _defineProperty, j as toActionObjects, k as toArray, l as createInvokeId, n as toInvokeConfig, o as _objectSpread2, p as invoke, q as _objectWithoutProperties, r as getDelayedTransitions, s as formatInitialTransition, u as getCandidates, v as isString, w as createSpawner, x as createInitEvent, y as getConfiguration, z as getStateNodes, A as resolveStateValue, B as isInFinalState, S as State, C as toSCXMLEvent, D as isSCXMLErrorEvent, E as macrostep, F as transitionNode, G as _slicedToArray, H as getInitialConfiguration, I as resolveActionsAndContext, J as microstep, K as error, L as isStateId, M as getStateNodeByPath, O as getPersistedState, P as resolveReferencedActor, Q as interpret, R as STATE_DELIMITER, T as initEvent, U as matchesState } from './actions-de434a04.esm.js';
2
+ export { ai as ActionTypes, Y as Interpreter, Z as InterpreterStatus, aj as SpecialTargets, S as State, ag as and, a0 as assign, a1 as cancel, a2 as choose, $ as doneInvoke, X as forwardTo, ab as fromCallback, ac as fromEventObservable, aa as fromObservable, a9 as fromPromise, ad as fromTransition, z as getStateNodes, Q as interpret, a3 as log, U as matchesState, af as not, ah as or, a7 as pathToStateValue, a4 as pure, a5 as raise, W as sendParent, V as sendTo, ae as stateIn, a6 as stop, a8 as toObserver, C as toSCXMLEvent } from './actions-de434a04.esm.js';
3
3
  import './index-50bd0aff.esm.js';
4
4
 
5
- function pure(getActions) {
6
- return createDynamicAction({
7
- type: pure$1,
8
- params: {
9
- get: getActions
10
- }
11
- }, function (_event, _ref) {
12
- var _toArray;
13
- var state = _ref.state;
14
- return [state, {
15
- type: pure$1,
16
- params: {
17
- actions: (_toArray = toArray(toActionObjects(getActions({
18
- context: state.context,
19
- event: _event.data
20
- })))) !== null && _toArray !== void 0 ? _toArray : []
21
- }
22
- }];
23
- });
24
- }
25
-
26
5
  var _excluded = ["onDone", "onError"];
27
6
  var EMPTY_OBJECT = {};
28
7
  var StateNode = /*#__PURE__*/function () {
@@ -232,9 +211,9 @@ var StateNode = /*#__PURE__*/function () {
232
211
  id: resolvedId,
233
212
  systemId: systemId,
234
213
  toJSON: function toJSON() {
235
- var onDone = invokeConfig.onDone,
236
- onError = invokeConfig.onError,
237
- invokeDefValues = _objectWithoutProperties(invokeConfig, _excluded);
214
+ invokeConfig.onDone;
215
+ invokeConfig.onError;
216
+ var invokeDefValues = _objectWithoutProperties(invokeConfig, _excluded);
238
217
  return _objectSpread2(_objectSpread2({}, invokeDefValues), {}, {
239
218
  type: invoke,
240
219
  src: resolvedSrc,
@@ -423,13 +402,13 @@ var StateMachine = /*#__PURE__*/function () {
423
402
  * The raw config used to create the machine.
424
403
  */
425
404
  config, options) {
426
- var _this$config$schema;
405
+ var _this$config$types;
427
406
  _classCallCheck(this, StateMachine);
428
407
  this.config = config;
429
408
  _defineProperty(this, "version", void 0);
430
409
  _defineProperty(this, "delimiter", void 0);
431
410
  _defineProperty(this, "options", void 0);
432
- _defineProperty(this, "schema", void 0);
411
+ _defineProperty(this, "types", void 0);
433
412
  _defineProperty(this, "__xstatenode", true);
434
413
  _defineProperty(this, "idMap", new Map());
435
414
  _defineProperty(this, "root", void 0);
@@ -445,7 +424,7 @@ var StateMachine = /*#__PURE__*/function () {
445
424
  this.options = Object.assign(createDefaultOptions(), options);
446
425
  this.delimiter = this.config.delimiter || STATE_DELIMITER;
447
426
  this.version = this.config.version;
448
- this.schema = (_this$config$schema = this.config.schema) !== null && _this$config$schema !== void 0 ? _this$config$schema : {};
427
+ this.types = (_this$config$types = this.config.types) !== null && _this$config$types !== void 0 ? _this$config$types : {};
449
428
  this.transition = this.transition.bind(this);
450
429
  this.root = new StateNode(config, {
451
430
  _key: this.id,
@@ -777,11 +756,6 @@ function mapState(stateMap, stateId) {
777
756
  return stateMap[foundStateId];
778
757
  }
779
758
 
780
- function createSchema(schema) {
781
- return schema;
782
- }
783
- var t = createSchema;
784
-
785
759
  var SimulatedClock = /*#__PURE__*/function () {
786
760
  function SimulatedClock() {
787
761
  _classCallCheck(this, SimulatedClock);
@@ -829,12 +803,12 @@ var SimulatedClock = /*#__PURE__*/function () {
829
803
  value: function flushTimeouts() {
830
804
  var _this = this;
831
805
  _toConsumableArray(this.timeouts).sort(function (_ref, _ref2) {
832
- var _ref3 = _slicedToArray(_ref, 2),
833
- _idA = _ref3[0],
834
- timeoutA = _ref3[1];
835
- var _ref4 = _slicedToArray(_ref2, 2),
836
- _idB = _ref4[0],
837
- timeoutB = _ref4[1];
806
+ var _ref3 = _slicedToArray(_ref, 2);
807
+ _ref3[0];
808
+ var timeoutA = _ref3[1];
809
+ var _ref4 = _slicedToArray(_ref2, 2);
810
+ _ref4[0];
811
+ var timeoutB = _ref4[1];
838
812
  var endA = timeoutA.start + timeoutA.timeout;
839
813
  var endB = timeoutB.start + timeoutB.timeout;
840
814
  return endB > endA ? -1 : 1;
@@ -858,22 +832,71 @@ var SimulatedClock = /*#__PURE__*/function () {
858
832
  return SimulatedClock;
859
833
  }();
860
834
 
861
- var actions = {
862
- raise: raise,
863
- send: send,
864
- sendParent: sendParent,
865
- sendTo: sendTo,
866
- log: log,
867
- cancel: cancel,
868
- stop: stop,
869
- assign: assign,
870
- after: after,
871
- done: done,
872
- respond: respond,
873
- forwardTo: forwardTo,
874
- escalate: escalate,
875
- choose: choose,
876
- pure: pure
835
+ var defaultWaitForOptions = {
836
+ timeout: 10000 // 10 seconds
877
837
  };
878
838
 
879
- export { SimulatedClock, StateMachine, StateNode, actions, createMachine, createSchema, mapState, t };
839
+ /**
840
+ * Subscribes to an actor ref and waits for its emitted value to satisfy
841
+ * a predicate, and then resolves with that value.
842
+ * Will throw if the desired state is not reached after a timeout
843
+ * (defaults to 10 seconds).
844
+ *
845
+ * @example
846
+ * ```js
847
+ * const state = await waitFor(someService, state => {
848
+ * return state.hasTag('loaded');
849
+ * });
850
+ *
851
+ * state.hasTag('loaded'); // true
852
+ * ```
853
+ *
854
+ * @param actorRef The actor ref to subscribe to
855
+ * @param predicate Determines if a value matches the condition to wait for
856
+ * @param options
857
+ * @returns A promise that eventually resolves to the emitted value
858
+ * that matches the condition
859
+ */
860
+ function waitFor(actorRef, predicate, options) {
861
+ var resolvedOptions = _objectSpread2(_objectSpread2({}, defaultWaitForOptions), options);
862
+ return new Promise(function (res, rej) {
863
+ var done = false;
864
+ if (process.env.NODE_ENV !== 'production' && resolvedOptions.timeout < 0) {
865
+ console.error('`timeout` passed to `waitFor` is negative and it will reject its internal promise immediately.');
866
+ }
867
+ var handle = resolvedOptions.timeout === Infinity ? undefined : setTimeout(function () {
868
+ sub.unsubscribe();
869
+ rej(new Error("Timeout of ".concat(resolvedOptions.timeout, " ms exceeded")));
870
+ }, resolvedOptions.timeout);
871
+ var dispose = function dispose() {
872
+ clearTimeout(handle);
873
+ done = true;
874
+ sub === null || sub === void 0 ? void 0 : sub.unsubscribe();
875
+ };
876
+ function checkEmitted(emitted) {
877
+ if (predicate(emitted)) {
878
+ dispose();
879
+ res(emitted);
880
+ }
881
+ }
882
+
883
+ // See if the current snapshot already matches the predicate
884
+ checkEmitted(actorRef.getSnapshot());
885
+ var sub = actorRef.subscribe({
886
+ next: checkEmitted,
887
+ error: function error(err) {
888
+ dispose();
889
+ rej(err);
890
+ },
891
+ complete: function complete() {
892
+ dispose();
893
+ rej(new Error("Actor terminated without satisfying predicate"));
894
+ }
895
+ });
896
+ if (done) {
897
+ sub.unsubscribe();
898
+ }
899
+ });
900
+ }
901
+
902
+ export { SimulatedClock, StateMachine, StateNode, createMachine, mapState, waitFor };