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
@@ -59,39 +59,39 @@ var SpecialTargets;
59
59
  })(SpecialTargets || (SpecialTargets = {}));
60
60
 
61
61
  // xstate-specific action types
62
- var stop = ActionTypes.Stop;
63
- var raise = ActionTypes.Raise;
64
- var send = ActionTypes.Send;
65
- var cancel = ActionTypes.Cancel;
66
- var assign = ActionTypes.Assign;
67
- var after = ActionTypes.After;
62
+ var stop$1 = ActionTypes.Stop;
63
+ var raise$1 = ActionTypes.Raise;
64
+ var send$1 = ActionTypes.Send;
65
+ var cancel$1 = ActionTypes.Cancel;
66
+ var assign$1 = ActionTypes.Assign;
67
+ var after$1 = ActionTypes.After;
68
68
  var doneState = ActionTypes.DoneState;
69
- var log = ActionTypes.Log;
69
+ var log$1 = ActionTypes.Log;
70
70
  var init = ActionTypes.Init;
71
- var invoke = ActionTypes.Invoke;
71
+ var invoke$1 = ActionTypes.Invoke;
72
72
  var errorExecution = ActionTypes.ErrorExecution;
73
73
  var errorPlatform = ActionTypes.ErrorPlatform;
74
- var error = ActionTypes.ErrorCustom;
75
- var choose = ActionTypes.Choose;
76
- var pure = ActionTypes.Pure;
74
+ var error$1 = ActionTypes.ErrorCustom;
75
+ var choose$1 = ActionTypes.Choose;
76
+ var pure$1 = ActionTypes.Pure;
77
77
 
78
78
  var actionTypes = /*#__PURE__*/Object.freeze({
79
79
  __proto__: null,
80
- stop: stop,
81
- raise: raise,
82
- send: send,
83
- cancel: cancel,
84
- assign: assign,
85
- after: after,
80
+ stop: stop$1,
81
+ raise: raise$1,
82
+ send: send$1,
83
+ cancel: cancel$1,
84
+ assign: assign$1,
85
+ after: after$1,
86
86
  doneState: doneState,
87
- log: log,
87
+ log: log$1,
88
88
  init: init,
89
- invoke: invoke,
89
+ invoke: invoke$1,
90
90
  errorExecution: errorExecution,
91
91
  errorPlatform: errorPlatform,
92
- error: error,
93
- choose: choose,
94
- pure: pure
92
+ error: error$1,
93
+ choose: choose$1,
94
+ pure: pure$1
95
95
  });
96
96
 
97
97
  function _toPrimitive(input, hint) {
@@ -535,9 +535,9 @@ function isDynamicAction(action) {
535
535
  * - `delay` - The number of milliseconds to delay the sending of the event.
536
536
  * - `to` - The target of this event (by default, the machine the event was sent from).
537
537
  */
538
- function send$1(eventOrExpr, options) {
538
+ function send(eventOrExpr, options) {
539
539
  return createDynamicAction({
540
- type: send,
540
+ type: send$1,
541
541
  params: {
542
542
  to: options ? options.to : undefined,
543
543
  delay: options ? options.delay : undefined,
@@ -566,6 +566,9 @@ function send$1(eventOrExpr, options) {
566
566
  var delaysMap = state.machine.options.delays;
567
567
 
568
568
  // TODO: helper function for resolving Expr
569
+ if (typeof eventOrExpr === 'string') {
570
+ throw new Error("Only event objects may be used with sendTo; use sendTo({ type: \"".concat(eventOrExpr, "\" }) instead"));
571
+ }
569
572
  var resolvedEvent = toSCXMLEvent(isFunction(eventOrExpr) ? eventOrExpr(args) : eventOrExpr);
570
573
  var resolvedDelay;
571
574
  if (isString(params.delay)) {
@@ -595,7 +598,7 @@ function send$1(eventOrExpr, options) {
595
598
  targetActorRef = resolvedTarget || (actorContext === null || actorContext === void 0 ? void 0 : actorContext.self);
596
599
  }
597
600
  var resolvedAction = {
598
- type: send,
601
+ type: send$1,
599
602
  params: _objectSpread2(_objectSpread2({}, params), {}, {
600
603
  to: targetActorRef,
601
604
  _event: resolvedEvent,
@@ -614,7 +617,7 @@ function send$1(eventOrExpr, options) {
614
617
  actorCtx.defer(function () {
615
618
  var origin = actorCtx.self;
616
619
  var resolvedEvent = _objectSpread2(_objectSpread2({}, _event2), {}, {
617
- name: _event2.name === error ? "".concat(error$1(origin.id)) : _event2.name,
620
+ name: _event2.name === error$1 ? "".concat(error(origin.id)) : _event2.name,
618
621
  origin: origin
619
622
  });
620
623
  target.send(resolvedEvent);
@@ -633,7 +636,7 @@ function send$1(eventOrExpr, options) {
633
636
  * @param options Options to pass into the send event.
634
637
  */
635
638
  function sendParent(event, options) {
636
- return send$1(event, _objectSpread2(_objectSpread2({}, options), {}, {
639
+ return send(event, _objectSpread2(_objectSpread2({}, options), {}, {
637
640
  to: SpecialTargets.Parent
638
641
  }));
639
642
  }
@@ -645,7 +648,7 @@ function sendParent(event, options) {
645
648
  * @param options Options to pass into the send event
646
649
  */
647
650
  function respond(event, options) {
648
- return send$1(event, _objectSpread2(_objectSpread2({}, options), {}, {
651
+ return send(event, _objectSpread2(_objectSpread2({}, options), {}, {
649
652
  to: function to(_ref2) {
650
653
  var _event = _ref2._event;
651
654
  return _event.origin; // TODO: handle when _event.origin is undefined
@@ -670,7 +673,7 @@ function forwardTo(target, options) {
670
673
  return resolvedTarget;
671
674
  };
672
675
  }
673
- return send$1(function (_ref3) {
676
+ return send(function (_ref3) {
674
677
  var event = _ref3.event;
675
678
  return event;
676
679
  }, _objectSpread2(_objectSpread2({}, options), {}, {
@@ -688,7 +691,7 @@ function forwardTo(target, options) {
688
691
  function escalate(errorData, options) {
689
692
  return sendParent(function (arg) {
690
693
  return {
691
- type: error,
694
+ type: error$1,
692
695
  data: isFunction(errorData) ? errorData(arg) : errorData
693
696
  };
694
697
  }, _objectSpread2(_objectSpread2({}, options), {}, {
@@ -705,7 +708,7 @@ function escalate(errorData, options) {
705
708
  * @returns An XState send action object
706
709
  */
707
710
  function sendTo(actor, event, options) {
708
- return send$1(event, _objectSpread2(_objectSpread2({}, options), {}, {
711
+ return send(event, _objectSpread2(_objectSpread2({}, options), {}, {
709
712
  to: actor
710
713
  }));
711
714
  }
@@ -863,25 +866,28 @@ promiseCreator) {
863
866
  var behavior = {
864
867
  transition: function transition(state, event) {
865
868
  var _event = toSCXMLEvent(event);
866
- if (state.canceled) {
869
+ if (state.status !== 'active') {
867
870
  return state;
868
871
  }
869
872
  var eventObject = _event.data;
870
873
  switch (_event.name) {
871
874
  case resolveEventType:
872
- state.status = 'done';
873
- state.data = eventObject.data;
874
- delete state.input;
875
- return state;
875
+ return _objectSpread2(_objectSpread2({}, state), {}, {
876
+ status: 'done',
877
+ data: eventObject.data,
878
+ input: undefined
879
+ });
876
880
  case rejectEventType:
877
- state.status = 'error';
878
- state.data = eventObject.data;
879
- delete state.input;
880
- return state;
881
+ return _objectSpread2(_objectSpread2({}, state), {}, {
882
+ status: 'error',
883
+ data: eventObject.data,
884
+ input: undefined
885
+ });
881
886
  case stopSignalType:
882
- state.canceled = true;
883
- delete state.input;
884
- return state;
887
+ return _objectSpread2(_objectSpread2({}, state), {}, {
888
+ status: 'canceled',
889
+ input: undefined
890
+ });
885
891
  default:
886
892
  return state;
887
893
  }
@@ -897,11 +903,19 @@ promiseCreator) {
897
903
  input: state.input
898
904
  }));
899
905
  resolvedPromise.then(function (response) {
906
+ // TODO: remove this condition once dead letter queue lands
907
+ if (self._state.status !== 'active') {
908
+ return;
909
+ }
900
910
  self.send({
901
911
  type: resolveEventType,
902
912
  data: response
903
913
  });
904
914
  }, function (errorData) {
915
+ // TODO: remove this condition once dead letter queue lands
916
+ if (self._state.status !== 'active') {
917
+ return;
918
+ }
905
919
  self.send({
906
920
  type: rejectEventType,
907
921
  data: errorData
@@ -910,7 +924,6 @@ promiseCreator) {
910
924
  },
911
925
  getInitialState: function getInitialState(_, input) {
912
926
  return {
913
- canceled: false,
914
927
  status: 'active',
915
928
  data: undefined,
916
929
  input: input
@@ -945,12 +958,11 @@ function fromObservable(observableCreator) {
945
958
  id = _ref.id,
946
959
  defer = _ref.defer;
947
960
  var _event = toSCXMLEvent(event);
948
- if (state.canceled) {
961
+ if (state.status !== 'active') {
949
962
  return state;
950
963
  }
951
964
  switch (_event.name) {
952
965
  case nextEventType:
953
- state.data = event.data.data;
954
966
  // match the exact timing of events sent by machines
955
967
  // send actions are not executed immediately
956
968
  defer(function () {
@@ -962,21 +974,29 @@ function fromObservable(observableCreator) {
962
974
  origin: self
963
975
  }));
964
976
  });
965
- return state;
977
+ return _objectSpread2(_objectSpread2({}, state), {}, {
978
+ data: event.data.data
979
+ });
966
980
  case errorEventType:
967
- state.status = 'error';
968
- delete state.input;
969
- state.data = _event.data.data;
970
- return state;
981
+ return _objectSpread2(_objectSpread2({}, state), {}, {
982
+ status: 'error',
983
+ input: undefined,
984
+ data: _event.data.data,
985
+ subscription: undefined
986
+ });
971
987
  case completeEventType:
972
- state.status = 'done';
973
- delete state.input;
974
- return state;
988
+ return _objectSpread2(_objectSpread2({}, state), {}, {
989
+ status: 'done',
990
+ input: undefined,
991
+ subscription: undefined
992
+ });
975
993
  case stopSignalType:
976
- state.canceled = true;
977
- delete state.input;
978
994
  state.subscription.unsubscribe();
979
- return state;
995
+ return _objectSpread2(_objectSpread2({}, state), {}, {
996
+ status: 'canceled',
997
+ input: undefined,
998
+ subscription: undefined
999
+ });
980
1000
  default:
981
1001
  return state;
982
1002
  }
@@ -984,7 +1004,6 @@ function fromObservable(observableCreator) {
984
1004
  getInitialState: function getInitialState(_, input) {
985
1005
  return {
986
1006
  subscription: undefined,
987
- canceled: false,
988
1007
  status: 'active',
989
1008
  data: undefined,
990
1009
  input: input
@@ -1022,12 +1041,10 @@ function fromObservable(observableCreator) {
1022
1041
  return state.data;
1023
1042
  },
1024
1043
  getPersistedState: function getPersistedState(_ref3) {
1025
- var canceled = _ref3.canceled,
1026
- status = _ref3.status,
1044
+ var status = _ref3.status,
1027
1045
  data = _ref3.data,
1028
1046
  input = _ref3.input;
1029
1047
  return {
1030
- canceled: canceled,
1031
1048
  status: status,
1032
1049
  data: data,
1033
1050
  input: input
@@ -1062,24 +1079,30 @@ function fromEventObservable(lazyObservable) {
1062
1079
  var behavior = {
1063
1080
  transition: function transition(state, event) {
1064
1081
  var _event = toSCXMLEvent(event);
1065
- if (state.canceled) {
1082
+ if (state.status !== 'active') {
1066
1083
  return state;
1067
1084
  }
1068
1085
  switch (_event.name) {
1069
1086
  case errorEventType:
1070
- state.status = 'error';
1071
- delete state.input;
1072
- state.data = _event.data.data;
1073
- return state;
1087
+ return _objectSpread2(_objectSpread2({}, state), {}, {
1088
+ status: 'error',
1089
+ input: undefined,
1090
+ data: _event.data.data,
1091
+ subscription: undefined
1092
+ });
1074
1093
  case completeEventType:
1075
- state.status = 'done';
1076
- delete state.input;
1077
- return state;
1094
+ return _objectSpread2(_objectSpread2({}, state), {}, {
1095
+ status: 'done',
1096
+ input: undefined,
1097
+ subscription: undefined
1098
+ });
1078
1099
  case stopSignalType:
1079
- state.canceled = true;
1080
- delete state.input;
1081
1100
  state.subscription.unsubscribe();
1082
- return state;
1101
+ return _objectSpread2(_objectSpread2({}, state), {}, {
1102
+ status: 'canceled',
1103
+ input: undefined,
1104
+ subscription: undefined
1105
+ });
1083
1106
  default:
1084
1107
  return state;
1085
1108
  }
@@ -1087,7 +1110,6 @@ function fromEventObservable(lazyObservable) {
1087
1110
  getInitialState: function getInitialState() {
1088
1111
  return {
1089
1112
  subscription: undefined,
1090
- canceled: false,
1091
1113
  status: 'active',
1092
1114
  data: undefined
1093
1115
  };
@@ -1124,12 +1146,10 @@ function fromEventObservable(lazyObservable) {
1124
1146
  return undefined;
1125
1147
  },
1126
1148
  getPersistedState: function getPersistedState(_ref5) {
1127
- var canceled = _ref5.canceled,
1128
- status = _ref5.status,
1149
+ var status = _ref5.status,
1129
1150
  data = _ref5.data,
1130
1151
  input = _ref5.input;
1131
1152
  return {
1132
- canceled: canceled,
1133
1153
  status: status,
1134
1154
  data: data,
1135
1155
  input: input
@@ -1163,7 +1183,7 @@ function fromCallback(invokeCallback) {
1163
1183
  var sender = function sender(eventForParent) {
1164
1184
  var _self$_parent;
1165
1185
  if (state.canceled) {
1166
- return state;
1186
+ return;
1167
1187
  }
1168
1188
  (_self$_parent = self._parent) === null || _self$_parent === void 0 ? void 0 : _self$_parent.send(toSCXMLEvent(eventForParent, {
1169
1189
  origin: self
@@ -1184,7 +1204,7 @@ function fromCallback(invokeCallback) {
1184
1204
  state.canceled = true;
1185
1205
  }, function (errorData) {
1186
1206
  var _self$_parent3;
1187
- var errorEvent = error$1(id, errorData);
1207
+ var errorEvent = error(id, errorData);
1188
1208
  (_self$_parent3 = self._parent) === null || _self$_parent3 === void 0 ? void 0 : _self$_parent3.send(toSCXMLEvent(errorEvent, {
1189
1209
  origin: self
1190
1210
  }));
@@ -1278,6 +1298,12 @@ function toActorRef(actorRefLike) {
1278
1298
  return void 0;
1279
1299
  }), _objectSpread2$1), actorRefLike);
1280
1300
  }
1301
+ var emptyBehavior = fromTransition(function (_) {
1302
+ return undefined;
1303
+ }, undefined);
1304
+ function createEmptyActor() {
1305
+ return interpret(emptyBehavior);
1306
+ }
1281
1307
 
1282
1308
  function createSystem() {
1283
1309
  var sessionIdCounter = 0;
@@ -1471,9 +1497,9 @@ var Interpreter = /*#__PURE__*/function () {
1471
1497
  _step;
1472
1498
  try {
1473
1499
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
1474
- var _observer2$next;
1475
- var _observer2 = _step.value;
1476
- (_observer2$next = _observer2.next) === null || _observer2$next === void 0 ? void 0 : _observer2$next.call(_observer2, snapshot);
1500
+ var _observer$next;
1501
+ var _observer = _step.value;
1502
+ (_observer$next = _observer.next) === null || _observer$next === void 0 ? void 0 : _observer$next.call(_observer, snapshot);
1477
1503
  }
1478
1504
  } catch (err) {
1479
1505
  _iterator.e(err);
@@ -1483,30 +1509,20 @@ var Interpreter = /*#__PURE__*/function () {
1483
1509
  var status = (_this$behavior$getSta = (_this$behavior = this.behavior).getStatus) === null || _this$behavior$getSta === void 0 ? void 0 : _this$behavior$getSta.call(_this$behavior, state);
1484
1510
  switch (status === null || status === void 0 ? void 0 : status.status) {
1485
1511
  case 'done':
1512
+ this._stopProcedure();
1486
1513
  this._doneEvent = doneInvoke(this.id, status.data);
1487
1514
  (_this$_parent = this._parent) === null || _this$_parent === void 0 ? void 0 : _this$_parent.send(toSCXMLEvent(this._doneEvent, {
1488
1515
  origin: this,
1489
1516
  invokeid: this.id
1490
1517
  }));
1491
- this._stopProcedure();
1518
+ this._complete();
1492
1519
  break;
1493
1520
  case 'error':
1494
- (_this$_parent2 = this._parent) === null || _this$_parent2 === void 0 ? void 0 : _this$_parent2.send(toSCXMLEvent(error$1(this.id, status.data), {
1521
+ this._stopProcedure();
1522
+ (_this$_parent2 = this._parent) === null || _this$_parent2 === void 0 ? void 0 : _this$_parent2.send(toSCXMLEvent(error(this.id, status.data), {
1495
1523
  origin: this
1496
1524
  }));
1497
- var _iterator2 = _createForOfIteratorHelper(this.observers),
1498
- _step2;
1499
- try {
1500
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
1501
- var _observer$error;
1502
- var _observer = _step2.value;
1503
- (_observer$error = _observer.error) === null || _observer$error === void 0 ? void 0 : _observer$error.call(_observer, status.data);
1504
- }
1505
- } catch (err) {
1506
- _iterator2.e(err);
1507
- } finally {
1508
- _iterator2.f();
1509
- }
1525
+ this._error(status.data);
1510
1526
  break;
1511
1527
  }
1512
1528
  }
@@ -1587,13 +1603,14 @@ var Interpreter = /*#__PURE__*/function () {
1587
1603
  this.update(nextState);
1588
1604
  if (event.name === stopSignalType) {
1589
1605
  this._stopProcedure();
1606
+ this._complete();
1590
1607
  }
1591
1608
  } catch (err) {
1592
1609
  // TODO: properly handle errors
1593
1610
  if (this.observers.size > 0) {
1594
1611
  this.observers.forEach(function (observer) {
1595
- var _observer$error2;
1596
- (_observer$error2 = observer.error) === null || _observer$error2 === void 0 ? void 0 : _observer$error2.call(observer, err);
1612
+ var _observer$error;
1613
+ (_observer$error = observer.error) === null || _observer$error === void 0 ? void 0 : _observer$error.call(observer, err);
1597
1614
  });
1598
1615
  this.stop();
1599
1616
  } else {
@@ -1632,13 +1649,31 @@ var Interpreter = /*#__PURE__*/function () {
1632
1649
  }, {
1633
1650
  key: "_complete",
1634
1651
  value: function _complete() {
1652
+ var _iterator2 = _createForOfIteratorHelper(this.observers),
1653
+ _step2;
1654
+ try {
1655
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
1656
+ var _observer2$complete;
1657
+ var _observer2 = _step2.value;
1658
+ (_observer2$complete = _observer2.complete) === null || _observer2$complete === void 0 ? void 0 : _observer2$complete.call(_observer2);
1659
+ }
1660
+ } catch (err) {
1661
+ _iterator2.e(err);
1662
+ } finally {
1663
+ _iterator2.f();
1664
+ }
1665
+ this.observers.clear();
1666
+ }
1667
+ }, {
1668
+ key: "_error",
1669
+ value: function _error(data) {
1635
1670
  var _iterator3 = _createForOfIteratorHelper(this.observers),
1636
1671
  _step3;
1637
1672
  try {
1638
1673
  for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
1639
- var _observer3$complete;
1674
+ var _observer3$error;
1640
1675
  var _observer3 = _step3.value;
1641
- (_observer3$complete = _observer3.complete) === null || _observer3$complete === void 0 ? void 0 : _observer3$complete.call(_observer3);
1676
+ (_observer3$error = _observer3.error) === null || _observer3$error === void 0 ? void 0 : _observer3$error.call(_observer3, data);
1642
1677
  }
1643
1678
  } catch (err) {
1644
1679
  _iterator3.e(err);
@@ -1650,7 +1685,6 @@ var Interpreter = /*#__PURE__*/function () {
1650
1685
  }, {
1651
1686
  key: "_stopProcedure",
1652
1687
  value: function _stopProcedure() {
1653
- this._complete();
1654
1688
  if (this.status !== ActorStatus.Running) {
1655
1689
  // Interpreter already stopped; do nothing
1656
1690
  return this;
@@ -1682,6 +1716,9 @@ var Interpreter = /*#__PURE__*/function () {
1682
1716
  }, {
1683
1717
  key: "send",
1684
1718
  value: function send(event) {
1719
+ if (typeof event === 'string') {
1720
+ throw new Error("Only event objects may be sent to actors; use .send({ type: \"".concat(event, "\" }) instead"));
1721
+ }
1685
1722
  var _event = toSCXMLEvent(event);
1686
1723
  if (this.status === ActorStatus.Stopped) {
1687
1724
  // do nothing
@@ -1774,10 +1811,10 @@ function interpret(behavior, options) {
1774
1811
  * @param actorRef The actor to stop.
1775
1812
  */
1776
1813
 
1777
- function stop$1(actorRef) {
1814
+ function stop(actorRef) {
1778
1815
  var actor = actorRef;
1779
1816
  return createDynamicAction({
1780
- type: stop,
1817
+ type: stop$1,
1781
1818
  params: {
1782
1819
  actor: actor
1783
1820
  }
@@ -1827,11 +1864,11 @@ var defaultLogExpr = function defaultLogExpr(_ref) {
1827
1864
  * @param label The label to give to the logged expression.
1828
1865
  */
1829
1866
 
1830
- function log$1() {
1867
+ function log() {
1831
1868
  var expr = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultLogExpr;
1832
1869
  var label = arguments.length > 1 ? arguments[1] : undefined;
1833
1870
  return createDynamicAction({
1834
- type: log,
1871
+ type: log$1,
1835
1872
  params: {
1836
1873
  label: label,
1837
1874
  expr: expr
@@ -1874,9 +1911,9 @@ function log$1() {
1874
1911
  * @param sendId The `id` of the `send(...)` action to cancel.
1875
1912
  */
1876
1913
 
1877
- function cancel$1(sendId) {
1914
+ function cancel(sendId) {
1878
1915
  return createDynamicAction({
1879
- type: cancel,
1916
+ type: cancel$1,
1880
1917
  params: {
1881
1918
  sendId: sendId
1882
1919
  }
@@ -2287,13 +2324,13 @@ function getDelayedTransitions(stateNode) {
2287
2324
  }
2288
2325
  var mutateEntryExit = function mutateEntryExit(delay, i) {
2289
2326
  var delayRef = isFunction(delay) ? "".concat(stateNode.id, ":delay[").concat(i, "]") : delay;
2290
- var eventType = after$1(delayRef, stateNode.id);
2291
- stateNode.entry.push(send$1({
2327
+ var eventType = after(delayRef, stateNode.id);
2328
+ stateNode.entry.push(raise({
2292
2329
  type: eventType
2293
2330
  }, {
2294
2331
  delay: delay
2295
2332
  }));
2296
- stateNode.exit.push(cancel$1(eventType));
2333
+ stateNode.exit.push(cancel(eventType));
2297
2334
  return eventType;
2298
2335
  };
2299
2336
  var delayedTransitions = isArray(afterConfig) ? afterConfig.map(function (transition, i) {
@@ -2944,12 +2981,12 @@ function setChildren(currentState, nonRaisedActions) {
2944
2981
  try {
2945
2982
  for (_iterator21.s(); !(_step21 = _iterator21.n()).done;) {
2946
2983
  var action = _step21.value;
2947
- if (action.type === invoke && action.params.ref) {
2984
+ if (action.type === invoke$1 && action.params.ref) {
2948
2985
  var ref = action.params.ref;
2949
2986
  if (ref) {
2950
2987
  children[ref.id] = ref;
2951
2988
  }
2952
- } else if (action.type === stop) {
2989
+ } else if (action.type === stop$1) {
2953
2990
  var _ref = action.params.actor;
2954
2991
  if (_ref) {
2955
2992
  delete children[_ref.id];
@@ -3048,7 +3085,7 @@ function enterStates(filteredTransitions, mutConfiguration, actions, internalQue
3048
3085
  try {
3049
3086
  for (_iterator23.s(); !(_step23 = _iterator23.n()).done;) {
3050
3087
  var invokeDef = _step23.value;
3051
- actions.push(invoke$1(invokeDef));
3088
+ actions.push(invoke(invokeDef));
3052
3089
  }
3053
3090
 
3054
3091
  // Add entry actions
@@ -3358,7 +3395,7 @@ function exitStates(transitions, mutConfiguration, historyValue, actions) {
3358
3395
  for (_iterator40.s(); !(_step40 = _iterator40.n()).done;) {
3359
3396
  var s = _step40.value;
3360
3397
  actions.push.apply(actions, _toConsumableArray(s.exit.flat()).concat(_toConsumableArray(s.invoke.map(function (def) {
3361
- return stop$1(def.id);
3398
+ return stop(def.id);
3362
3399
  }))));
3363
3400
  mutConfiguration["delete"](s);
3364
3401
  }
@@ -3396,12 +3433,12 @@ function resolveActionsAndContext(actions, scxmlEvent, currentState, actorCtx) {
3396
3433
  resolvedAction = _executableActionObje2[1];
3397
3434
  var matchedActions = (_resolvedAction$param = resolvedAction.params) === null || _resolvedAction$param === void 0 ? void 0 : _resolvedAction$param.actions;
3398
3435
  intermediateState = nextState;
3399
- if ((resolvedAction.type === raise || resolvedAction.type === send && resolvedAction.params.internal) && typeof resolvedAction.params.delay !== 'number') {
3436
+ if ((resolvedAction.type === raise$1 || resolvedAction.type === send$1 && resolvedAction.params.internal) && typeof resolvedAction.params.delay !== 'number') {
3400
3437
  raiseActions.push(resolvedAction);
3401
3438
  }
3402
3439
 
3403
3440
  // TODO: remove the check; just handleAction
3404
- if (resolvedAction.type !== pure) {
3441
+ if (resolvedAction.type !== pure$1) {
3405
3442
  handleAction(resolvedAction);
3406
3443
  }
3407
3444
  toActionObjects(matchedActions).forEach(resolveAction);
@@ -3515,7 +3552,7 @@ function stopStep(scxmlEvent, nextState, actorCtx) {
3515
3552
  }
3516
3553
  for (var _i4 = 0, _Object$values = Object.values(nextState.children); _i4 < _Object$values.length; _i4++) {
3517
3554
  var child = _Object$values[_i4];
3518
- actions.push(stop$1(child));
3555
+ actions.push(stop(child));
3519
3556
  }
3520
3557
  var _resolveActionsAndCon2 = resolveActionsAndContext(actions, scxmlEvent, nextState, actorCtx),
3521
3558
  stoppedState = _resolveActionsAndCon2.nextState;
@@ -3688,11 +3725,11 @@ var State = /*#__PURE__*/function () {
3688
3725
  }, {
3689
3726
  key: "toJSON",
3690
3727
  value: function toJSON() {
3691
- var configuration = this.configuration,
3692
- transitions = this.transitions,
3693
- tags = this.tags,
3694
- machine = this.machine,
3695
- jsonValues = _objectWithoutProperties(this, _excluded);
3728
+ this.configuration;
3729
+ this.transitions;
3730
+ var tags = this.tags;
3731
+ this.machine;
3732
+ var jsonValues = _objectWithoutProperties(this, _excluded);
3696
3733
  return _objectSpread2(_objectSpread2({}, jsonValues), {}, {
3697
3734
  tags: Array.from(tags),
3698
3735
  meta: this.meta
@@ -3843,11 +3880,11 @@ function cloneState(state) {
3843
3880
  return new State(_objectSpread2(_objectSpread2({}, state), config), state.machine);
3844
3881
  }
3845
3882
  function getPersistedState(state) {
3846
- var configuration = state.configuration,
3847
- transitions = state.transitions,
3848
- tags = state.tags,
3849
- machine = state.machine,
3850
- children = state.children,
3883
+ state.configuration;
3884
+ state.transitions;
3885
+ state.tags;
3886
+ state.machine;
3887
+ var children = state.children,
3851
3888
  jsonValues = _objectWithoutProperties(state, _excluded2);
3852
3889
  var childrenJson = {};
3853
3890
  for (var id in children) {
@@ -3862,14 +3899,14 @@ function getPersistedState(state) {
3862
3899
  });
3863
3900
  }
3864
3901
 
3865
- function invoke$1(invokeDef) {
3902
+ function invoke(invokeDef) {
3866
3903
  return createDynamicAction({
3867
- type: invoke,
3904
+ type: invoke$1,
3868
3905
  params: invokeDef
3869
3906
  }, function (_event, _ref) {
3870
3907
  var state = _ref.state,
3871
3908
  actorContext = _ref.actorContext;
3872
- var type = invoke;
3909
+ var type = invoke$1;
3873
3910
  var id = invokeDef.id,
3874
3911
  src = invokeDef.src;
3875
3912
  var resolvedInvokeAction;
@@ -3931,7 +3968,7 @@ function invoke$1(invokeDef) {
3931
3968
  var _actorRef$start;
3932
3969
  (_actorRef$start = actorRef.start) === null || _actorRef$start === void 0 ? void 0 : _actorRef$start.call(actorRef);
3933
3970
  } catch (err) {
3934
- parent.send(error$1(id, err));
3971
+ parent.send(error(id, err));
3935
3972
  return;
3936
3973
  }
3937
3974
  });
@@ -3960,7 +3997,7 @@ function createSpawner(self, machine, context, _event, mutCapturedActions) {
3960
3997
  self: self
3961
3998
  }) : input
3962
3999
  });
3963
- mutCapturedActions.push(invoke$1({
4000
+ mutCapturedActions.push(invoke({
3964
4001
  id: actorRef.id,
3965
4002
  // @ts-ignore TODO: fix types
3966
4003
  src: actorRef,
@@ -3981,7 +4018,7 @@ function createSpawner(self, machine, context, _event, mutCapturedActions) {
3981
4018
  parent: self,
3982
4019
  input: options.input
3983
4020
  });
3984
- mutCapturedActions.push(invoke$1({
4021
+ mutCapturedActions.push(invoke({
3985
4022
  // @ts-ignore TODO: fix types
3986
4023
  src: _actorRef,
3987
4024
  ref: _actorRef,
@@ -3999,9 +4036,9 @@ function createSpawner(self, machine, context, _event, mutCapturedActions) {
3999
4036
  *
4000
4037
  * @param assignment An object that represents the partial context to update.
4001
4038
  */
4002
- function assign$1(assignment) {
4039
+ function assign(assignment) {
4003
4040
  return createDynamicAction({
4004
- type: assign,
4041
+ type: assign$1,
4005
4042
  params: {
4006
4043
  assignment: assignment
4007
4044
  }
@@ -4037,7 +4074,7 @@ function assign$1(assignment) {
4037
4074
  return [cloneState(state, {
4038
4075
  context: updatedContext
4039
4076
  }), {
4040
- type: assign,
4077
+ type: assign$1,
4041
4078
  params: {
4042
4079
  context: updatedContext,
4043
4080
  actions: capturedActions
@@ -4053,9 +4090,9 @@ function assign$1(assignment) {
4053
4090
  * @param eventType The event to raise.
4054
4091
  */
4055
4092
 
4056
- function raise$1(eventOrExpr, options) {
4093
+ function raise(eventOrExpr, options) {
4057
4094
  return createDynamicAction({
4058
- type: raise,
4095
+ type: raise$1,
4059
4096
  params: {
4060
4097
  delay: options ? options.delay : undefined,
4061
4098
  event: eventOrExpr,
@@ -4080,6 +4117,9 @@ function raise$1(eventOrExpr, options) {
4080
4117
  var delaysMap = state.machine.options.delays;
4081
4118
 
4082
4119
  // TODO: helper function for resolving Expr
4120
+ if (typeof eventOrExpr === 'string') {
4121
+ throw new Error("Only event objects may be used with raise; use raise({ type: \"".concat(eventOrExpr, "\" }) instead"));
4122
+ }
4083
4123
  var resolvedEvent = toSCXMLEvent(typeof eventOrExpr === 'function' ? eventOrExpr(args) : eventOrExpr);
4084
4124
  var resolvedDelay;
4085
4125
  if (typeof params.delay === 'string') {
@@ -4089,7 +4129,7 @@ function raise$1(eventOrExpr, options) {
4089
4129
  resolvedDelay = typeof params.delay === 'function' ? params.delay(args) : params.delay;
4090
4130
  }
4091
4131
  var resolvedAction = {
4092
- type: raise,
4132
+ type: raise$1,
4093
4133
  params: _objectSpread2(_objectSpread2({}, params), {}, {
4094
4134
  _event: resolvedEvent,
4095
4135
  event: resolvedEvent.data,
@@ -4106,9 +4146,9 @@ function raise$1(eventOrExpr, options) {
4106
4146
  });
4107
4147
  }
4108
4148
 
4109
- function choose$1(guards) {
4149
+ function choose(guards) {
4110
4150
  return createDynamicAction({
4111
- type: choose,
4151
+ type: choose$1,
4112
4152
  params: {
4113
4153
  guards: guards
4114
4154
  }
@@ -4122,7 +4162,7 @@ function choose$1(guards) {
4122
4162
  return !guard || evaluateGuard(guard, state.context, _event, state);
4123
4163
  })) === null || _guards$find === void 0 ? void 0 : _guards$find.actions;
4124
4164
  return [state, {
4125
- type: choose,
4165
+ type: choose$1,
4126
4166
  params: {
4127
4167
  actions: toActionObjects(matchedActions)
4128
4168
  }
@@ -4130,6 +4170,27 @@ function choose$1(guards) {
4130
4170
  });
4131
4171
  }
4132
4172
 
4173
+ function pure(getActions) {
4174
+ return createDynamicAction({
4175
+ type: pure$1,
4176
+ params: {
4177
+ get: getActions
4178
+ }
4179
+ }, function (_event, _ref) {
4180
+ var _toArray;
4181
+ var state = _ref.state;
4182
+ return [state, {
4183
+ type: pure$1,
4184
+ params: {
4185
+ actions: (_toArray = toArray(toActionObjects(getActions({
4186
+ context: state.context,
4187
+ event: _event.data
4188
+ })))) !== null && _toArray !== void 0 ? _toArray : []
4189
+ }
4190
+ }];
4191
+ });
4192
+ }
4193
+
4133
4194
  var initEvent = toSCXMLEvent({
4134
4195
  type: init
4135
4196
  });
@@ -4151,9 +4212,9 @@ function resolveActionObject(actionObject, actionFunctionMap) {
4151
4212
  execute: function execute(actorCtx) {
4152
4213
  return dereferencedAction({
4153
4214
  context: state.context,
4154
- event: state.event,
4215
+ event: _event.data,
4155
4216
  action: a,
4156
- _event: state._event,
4217
+ _event: _event,
4157
4218
  system: actorCtx.system,
4158
4219
  self: actorCtx.self
4159
4220
  });
@@ -4222,7 +4283,7 @@ var toActionObjects = function toActionObjects(action) {
4222
4283
  * @param delayRef The delay in milliseconds
4223
4284
  * @param id The state node ID where this event is handled
4224
4285
  */
4225
- function after$1(delayRef, id) {
4286
+ function after(delayRef, id) {
4226
4287
  var idSuffix = id ? "#".concat(id) : '';
4227
4288
  return "".concat(ActionTypes.After, "(").concat(delayRef, ")").concat(idSuffix);
4228
4289
  }
@@ -4266,7 +4327,7 @@ function doneInvoke(invokeId, output) {
4266
4327
  };
4267
4328
  return eventObject;
4268
4329
  }
4269
- function error$1(id, data) {
4330
+ function error(id, data) {
4270
4331
  var type = "".concat(ActionTypes.ErrorPlatform, ".").concat(id);
4271
4332
  var eventObject = {
4272
4333
  type: type,
@@ -4284,4 +4345,4 @@ function createInitEvent(input) {
4284
4345
  });
4285
4346
  }
4286
4347
 
4287
- export { sendTo as $, getConfiguration as A, getStateNodes as B, resolveStateValue as C, isInFinalState as D, toSCXMLEvent as E, isSCXMLErrorEvent as F, macrostep as G, transitionNode as H, _slicedToArray as I, getInitialConfiguration as J, resolveActionsAndContext as K, microstep as L, error$1 as M, NULL_EVENT as N, isStateId as O, getStateNodeByPath as P, getPersistedState as Q, resolveReferencedActor as R, State as S, interpret as T, STATE_DELIMITER as U, initEvent as V, matchesState as W, raise$1 as X, send$1 as Y, sendParent as Z, _createClass as _, toActionObjects as a, log$1 as a0, cancel$1 as a1, stop$1 as a2, assign$1 as a3, after$1 as a4, done as a5, respond as a6, forwardTo as a7, escalate as a8, choose$1 as a9, toActionObject as aA, Interpreter as aa, ActorStatus as ab, doneInvoke as ac, pathToStateValue as ad, toObserver as ae, ActionTypes as af, SpecialTargets as ag, startSignalType as ah, stopSignalType as ai, startSignal as aj, stopSignal as ak, isSignal as al, isActorRef as am, toActorRef as an, fromTransition as ao, fromPromise as ap, fromObservable as aq, fromEventObservable as ar, fromCallback as as, stateIn as at, not as au, and as av, or as aw, toGuardDefinition as ax, actionTypes as ay, resolveActionObject as az, toTransitionConfigArray as b, createDynamicAction as c, formatTransition as d, memo as e, formatTransitions as f, _createForOfIteratorHelper as g, evaluateGuard as h, _toConsumableArray as i, flatten as j, _classCallCheck as k, _defineProperty as l, mapValues as m, createInvokeId as n, toInvokeConfig as o, pure as p, _objectSpread2 as q, invoke as r, _objectWithoutProperties as s, toArray as t, getDelayedTransitions as u, formatInitialTransition as v, getCandidates as w, isString as x, createSpawner as y, createInitEvent as z };
4348
+ export { doneInvoke as $, resolveStateValue as A, isInFinalState as B, toSCXMLEvent as C, isSCXMLErrorEvent as D, macrostep as E, transitionNode as F, _slicedToArray as G, getInitialConfiguration as H, resolveActionsAndContext as I, microstep as J, error as K, isStateId as L, getStateNodeByPath as M, NULL_EVENT as N, getPersistedState as O, resolveReferencedActor as P, interpret as Q, STATE_DELIMITER as R, State as S, initEvent as T, matchesState as U, sendTo as V, sendParent as W, forwardTo as X, Interpreter as Y, ActorStatus as Z, _createClass as _, formatTransition as a, assign as a0, cancel as a1, choose as a2, log as a3, pure as a4, raise as a5, stop as a6, pathToStateValue as a7, toObserver as a8, fromPromise as a9, escalate as aA, fromObservable as aa, fromCallback as ab, fromEventObservable as ac, fromTransition as ad, stateIn as ae, not as af, and as ag, or as ah, ActionTypes as ai, SpecialTargets as aj, startSignalType as ak, stopSignalType as al, startSignal as am, stopSignal as an, isSignal as ao, isActorRef as ap, toActorRef as aq, createEmptyActor as ar, toGuardDefinition as as, actionTypes as at, resolveActionObject as au, toActionObject as av, after as aw, done as ax, send as ay, respond as az, memo as b, _createForOfIteratorHelper as c, _toConsumableArray as d, evaluateGuard as e, formatTransitions as f, flatten as g, _classCallCheck as h, _defineProperty as i, toActionObjects as j, toArray as k, createInvokeId as l, mapValues as m, toInvokeConfig as n, _objectSpread2 as o, invoke$1 as p, _objectWithoutProperties as q, getDelayedTransitions as r, formatInitialTransition as s, toTransitionConfigArray as t, getCandidates as u, isString as v, createSpawner as w, createInitEvent as x, getConfiguration as y, getStateNodes as z };