xstate 4.27.0-pr2674-2021926101023 → 4.27.0

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 (65) hide show
  1. package/CHANGELOG.md +24 -12
  2. package/dist/xstate.interpreter.js +1 -1
  3. package/dist/xstate.js +1 -1
  4. package/dist/xstate.web.js +2 -2
  5. package/es/Actor.d.ts +2 -1
  6. package/es/Machine.d.ts +4 -5
  7. package/es/State.d.ts +14 -13
  8. package/es/State.js +10 -3
  9. package/es/StateNode.d.ts +16 -20
  10. package/es/StateNode.js +51 -57
  11. package/es/_virtual/_tslib.js +8 -4
  12. package/es/actions.d.ts +20 -3
  13. package/es/actions.js +7 -7
  14. package/es/behaviors.d.ts +1 -1
  15. package/es/devTools.d.ts +2 -3
  16. package/es/devTools.js +4 -0
  17. package/es/each.d.ts +1 -1
  18. package/es/index.d.ts +0 -1
  19. package/es/interpreter.d.ts +25 -35
  20. package/es/interpreter.js +21 -16
  21. package/es/model.d.ts +2 -2
  22. package/es/model.types.d.ts +9 -8
  23. package/es/registry.js +1 -1
  24. package/es/scxml.d.ts +2 -2
  25. package/es/stateUtils.d.ts +5 -6
  26. package/es/stateUtils.js +1 -1
  27. package/es/types.d.ts +52 -104
  28. package/es/utils.d.ts +1 -1
  29. package/es/utils.js +10 -10
  30. package/lib/Actor.d.ts +2 -1
  31. package/lib/Machine.d.ts +4 -5
  32. package/lib/SimulatedClock.js +9 -5
  33. package/lib/State.d.ts +14 -13
  34. package/lib/State.js +10 -3
  35. package/lib/StateNode.d.ts +16 -20
  36. package/lib/StateNode.js +49 -55
  37. package/lib/_virtual/_tslib.js +8 -4
  38. package/lib/actions.d.ts +20 -3
  39. package/lib/actions.js +7 -7
  40. package/lib/behaviors.d.ts +1 -1
  41. package/lib/devTools.d.ts +2 -3
  42. package/lib/devTools.js +4 -0
  43. package/lib/each.d.ts +1 -1
  44. package/lib/index.d.ts +0 -1
  45. package/lib/interpreter.d.ts +25 -35
  46. package/lib/interpreter.js +21 -16
  47. package/lib/json.js +7 -7
  48. package/lib/model.d.ts +2 -2
  49. package/lib/model.js +14 -10
  50. package/lib/model.types.d.ts +9 -8
  51. package/lib/patterns.js +2 -2
  52. package/lib/registry.js +1 -1
  53. package/lib/scxml.d.ts +2 -2
  54. package/lib/scxml.js +29 -25
  55. package/lib/stateUtils.d.ts +5 -6
  56. package/lib/stateUtils.js +1 -1
  57. package/lib/types.d.ts +52 -104
  58. package/lib/utils.d.ts +1 -1
  59. package/lib/utils.js +10 -10
  60. package/package.json +4 -8
  61. package/dist/xstate.cjs.d.ts +0 -11
  62. package/dist/xstate.cjs.js +0 -16
  63. package/es/typegenTypes.d.ts +0 -92
  64. package/lib/typegenTypes.d.ts +0 -92
  65. package/lib/typegenTypes.js +0 -2
package/es/StateNode.js CHANGED
@@ -1,7 +1,7 @@
1
- import { __assign, __values, __spreadArray, __read, __rest } from './_virtual/_tslib.js';
1
+ import { __assign, __spreadArray, __read, __values, __rest } from './_virtual/_tslib.js';
2
2
  import { STATE_DELIMITER } from './constants.js';
3
3
  import { IS_PRODUCTION } from './environment.js';
4
- import { isFunction, mapValues, isArray, flatten, keys, toArray, toStateValue, isString, getEventType, matchesState, path, evaluateGuard, mapContext, toSCXMLEvent, pathToStateValue, isBuiltInEvent, partition, updateHistoryValue, toStatePath, mapFilterValues, warn, toStatePaths, nestedPath, normalizeTarget, toGuard, toTransitionConfigArray, isMachine } from './utils.js';
4
+ import { isFunction, mapValues, isArray, flatten, keys, toArray, toStateValue, isString, getEventType, toSCXMLEvent, matchesState, path, evaluateGuard, mapContext, pathToStateValue, isBuiltInEvent, partition, updateHistoryValue, toStatePath, mapFilterValues, warn, toStatePaths, nestedPath, normalizeTarget, toGuard, toTransitionConfigArray, isMachine } from './utils.js';
5
5
  import { SpecialTargets } from './types.js';
6
6
  import { getAllStateNodes, getConfiguration, isInFinalState, getTagsFromConfiguration, has, getChildren, getValue, isLeafNode } from './stateUtils.js';
7
7
  import { start as start$1, stop as stop$1, invoke, update, nullEvent, raise as raise$1, send as send$1 } from './actionTypes.js';
@@ -33,8 +33,8 @@ var validateArrayifiedTransitions = function (stateNode, event, transitions) {
33
33
  var hasNonLastUnguardedTarget = transitions.slice(0, -1).some(function (transition) {
34
34
  return !('cond' in transition) && !('in' in transition) && (isString(transition.target) || isMachine(transition.target));
35
35
  });
36
- var eventText = event === NULL_EVENT ? 'the transient event' : "event '" + event + "'";
37
- warn(!hasNonLastUnguardedTarget, "One or more transitions for " + eventText + " on state '" + stateNode.id + "' are unreachable. " + "Make sure that the default transition is the last one defined.");
36
+ var eventText = event === NULL_EVENT ? 'the transient event' : "event '".concat(event, "'");
37
+ warn(!hasNonLastUnguardedTarget, "One or more transitions for ".concat(eventText, " on state '").concat(stateNode.id, "' are unreachable. ") + "Make sure that the default transition is the last one defined.");
38
38
  };
39
39
 
40
40
  var StateNode =
@@ -50,8 +50,8 @@ function () {
50
50
  /**
51
51
  * The initial extended state
52
52
  */
53
- _context, // TODO: this is unsafe, but we're removing it in v5 anyway
54
- _stateInfo) {
53
+ _context // TODO: this is unsafe, but we're removing it in v5 anyway
54
+ ) {
55
55
  var _this = this;
56
56
 
57
57
  if (_context === void 0) {
@@ -81,28 +81,28 @@ function () {
81
81
  this.idMap = {};
82
82
  this.tags = [];
83
83
  this.options = Object.assign(createDefaultOptions(), options);
84
- this.parent = _stateInfo === null || _stateInfo === void 0 ? void 0 : _stateInfo.parent;
85
- this.key = this.config.key || (_stateInfo === null || _stateInfo === void 0 ? void 0 : _stateInfo.key) || this.config.id || '(machine)';
84
+ this.parent = this.options._parent;
85
+ this.key = this.config.key || this.options._key || this.config.id || '(machine)';
86
86
  this.machine = this.parent ? this.parent.machine : this;
87
87
  this.path = this.parent ? this.parent.path.concat(this.key) : [];
88
88
  this.delimiter = this.config.delimiter || (this.parent ? this.parent.delimiter : STATE_DELIMITER);
89
- this.id = this.config.id || __spreadArray([this.machine.key], __read(this.path)).join(this.delimiter);
89
+ this.id = this.config.id || __spreadArray([this.machine.key], __read(this.path), false).join(this.delimiter);
90
90
  this.version = this.parent ? this.parent.version : this.config.version;
91
91
  this.type = this.config.type || (this.config.parallel ? 'parallel' : this.config.states && keys(this.config.states).length ? 'compound' : this.config.history ? 'history' : 'atomic');
92
92
  this.schema = this.parent ? this.machine.schema : (_a = this.config.schema) !== null && _a !== void 0 ? _a : {};
93
93
  this.description = this.config.description;
94
94
 
95
95
  if (!IS_PRODUCTION) {
96
- warn(!('parallel' in this.config), "The \"parallel\" property is deprecated and will be removed in version 4.1. " + (this.config.parallel ? "Replace with `type: 'parallel'`" : "Use `type: '" + this.type + "'`") + " in the config for state node '" + this.id + "' instead.");
96
+ warn(!('parallel' in this.config), "The \"parallel\" property is deprecated and will be removed in version 4.1. ".concat(this.config.parallel ? "Replace with `type: 'parallel'`" : "Use `type: '".concat(this.type, "'`"), " in the config for state node '").concat(this.id, "' instead."));
97
97
  }
98
98
 
99
99
  this.initial = this.config.initial;
100
100
  this.states = this.config.states ? mapValues(this.config.states, function (stateConfig, key) {
101
101
  var _a;
102
102
 
103
- var stateNode = new StateNode(stateConfig, {}, undefined, {
104
- parent: _this,
105
- key: key
103
+ var stateNode = new StateNode(stateConfig, {
104
+ _parent: _this,
105
+ _key: key
106
106
  });
107
107
  Object.assign(_this.idMap, __assign((_a = {}, _a[stateNode.id] = stateNode, _a), stateNode.idMap));
108
108
  return stateNode;
@@ -166,7 +166,7 @@ function () {
166
166
  src: invokeConfig.src
167
167
  }));
168
168
  } else if (isMachine(invokeConfig.src) || isFunction(invokeConfig.src)) {
169
- var invokeSrc = _this.id + ":invocation[" + i + "]"; // TODO: util function
169
+ var invokeSrc = "".concat(_this.id, ":invocation[").concat(i, "]"); // TODO: util function
170
170
 
171
171
  _this.machine.options.services = __assign((_b = {}, _b[invokeSrc] = invokeConfig.src, _b), _this.machine.options.services);
172
172
  return toInvokeDefinition(__assign(__assign({
@@ -347,7 +347,7 @@ function () {
347
347
  }
348
348
 
349
349
  var mutateEntryExit = function (delay, i) {
350
- var delayRef = isFunction(delay) ? _this.id + ":delay[" + i + "]" : delay;
350
+ var delayRef = isFunction(delay) ? "".concat(_this.id, ":delay[").concat(i, "]") : delay;
351
351
  var eventType = after(delayRef, _this.id);
352
352
 
353
353
  _this.onEntry.push(send(eventType, {
@@ -409,15 +409,11 @@ function () {
409
409
  }
410
410
 
411
411
  var subStateKeys = keys(stateValue);
412
- var subStateNodes = subStateKeys.map(function (subStateKey) {
413
- return _this.getStateNode(subStateKey);
414
- });
415
- subStateNodes.push(this);
416
- return subStateNodes.concat(subStateKeys.reduce(function (allSubStateNodes, subStateKey) {
417
- var subStateNode = _this.getStateNode(subStateKey).getStateNodes(stateValue[subStateKey]);
418
-
419
- return allSubStateNodes.concat(subStateNode);
420
- }, []));
412
+ var subStateNodes = [this];
413
+ subStateNodes.push.apply(subStateNodes, __spreadArray([], __read(flatten(subStateKeys.map(function (subStateKey) {
414
+ return _this.getStateNode(subStateKey).getStateNodes(stateValue[subStateKey]);
415
+ }))), false));
416
+ return subStateNodes;
421
417
  };
422
418
  /**
423
419
  * Returns `true` if this state node explicitly handles the given event.
@@ -556,6 +552,10 @@ function () {
556
552
  return this.transitionParallelNode(stateValue, state, _event);
557
553
  };
558
554
 
555
+ StateNode.prototype.getTransitionData = function (state, event) {
556
+ return this._transition(state.value, state, toSCXMLEvent(event));
557
+ };
558
+
559
559
  StateNode.prototype.next = function (state, _event) {
560
560
  var e_3, _a;
561
561
 
@@ -580,7 +580,7 @@ function () {
580
580
  try {
581
581
  guardPassed = !cond || evaluateGuard(this.machine, cond, resolvedContext, _event, state);
582
582
  } catch (err) {
583
- throw new Error("Unable to evaluate guard '" + (cond.name || cond.type) + "' in transition for event '" + eventName + "' in state node '" + this.id + "':\n" + err.message);
583
+ throw new Error("Unable to evaluate guard '".concat(cond.name || cond.type, "' in transition for event '").concat(eventName, "' in state node '").concat(this.id, "':\n").concat(err.message));
584
584
  }
585
585
 
586
586
  if (guardPassed && isInState) {
@@ -588,7 +588,7 @@ function () {
588
588
  nextStateNodes = candidate.target;
589
589
  }
590
590
 
591
- actions.push.apply(actions, __spreadArray([], __read(candidate.actions)));
591
+ actions.push.apply(actions, __spreadArray([], __read(candidate.actions), false));
592
592
  selectedTransition = candidate;
593
593
  break;
594
594
  }
@@ -724,12 +724,6 @@ function () {
724
724
  }
725
725
  }
726
726
 
727
- if (!transition.source) {
728
- transition.exitSet = []; // Ensure that root StateNode (machine) is entered
729
-
730
- transition.entrySet.push(this);
731
- }
732
-
733
727
  var doneEvents = flatten(transition.entrySet.map(function (sn) {
734
728
  var events = [];
735
729
 
@@ -769,11 +763,11 @@ function () {
769
763
  var _c = __read([flatten(Array.from(entryStates).map(function (stateNode) {
770
764
  return __spreadArray(__spreadArray([], __read(stateNode.activities.map(function (activity) {
771
765
  return start(activity);
772
- }))), __read(stateNode.onEntry));
766
+ })), false), __read(stateNode.onEntry), false);
773
767
  })).concat(doneEvents.map(raise)), flatten(Array.from(exitStates).map(function (stateNode) {
774
- return __spreadArray(__spreadArray([], __read(stateNode.onExit)), __read(stateNode.activities.map(function (activity) {
768
+ return __spreadArray(__spreadArray([], __read(stateNode.onExit), false), __read(stateNode.activities.map(function (activity) {
775
769
  return stop(activity);
776
- })));
770
+ })), false);
777
771
  }))], 2),
778
772
  entryActions = _c[0],
779
773
  exitActions = _c[1];
@@ -808,12 +802,12 @@ function () {
808
802
  }
809
803
 
810
804
  if (!IS_PRODUCTION && _event.name === WILDCARD) {
811
- throw new Error("An event cannot have the wildcard type ('" + WILDCARD + "')");
805
+ throw new Error("An event cannot have the wildcard type ('".concat(WILDCARD, "')"));
812
806
  }
813
807
 
814
808
  if (this.strict) {
815
809
  if (!this.events.includes(_event.name) && !isBuiltInEvent(_event.name)) {
816
- throw new Error("Machine '" + this.id + "' does not accept event '" + _event.name + "'");
810
+ throw new Error("Machine '".concat(this.id, "' does not accept event '").concat(_event.name, "'"));
817
811
  }
818
812
  }
819
813
 
@@ -827,7 +821,7 @@ function () {
827
821
  };
828
822
  var prevConfig = getConfiguration([], this.getStateNodes(currentState.value));
829
823
  var resolvedConfig = stateTransition.configuration.length ? getConfiguration(prevConfig, stateTransition.configuration) : prevConfig;
830
- stateTransition.configuration = __spreadArray([], __read(resolvedConfig));
824
+ stateTransition.configuration = __spreadArray([], __read(resolvedConfig), false);
831
825
  return this.resolveTransition(stateTransition, currentState, _event);
832
826
  };
833
827
 
@@ -841,7 +835,7 @@ function () {
841
835
  state._event = originalEvent;
842
836
  state.event = originalEvent.data;
843
837
 
844
- (_a = state.actions).unshift.apply(_a, __spreadArray([], __read(currentActions)));
838
+ (_a = state.actions).unshift.apply(_a, __spreadArray([], __read(currentActions), false));
845
839
 
846
840
  return state;
847
841
  };
@@ -992,13 +986,13 @@ function () {
992
986
  }
993
987
 
994
988
  if (!this.states) {
995
- throw new Error("Unable to retrieve child state '" + stateKey + "' from '" + this.id + "'; no child states exist.");
989
+ throw new Error("Unable to retrieve child state '".concat(stateKey, "' from '").concat(this.id, "'; no child states exist."));
996
990
  }
997
991
 
998
992
  var result = this.states[stateKey];
999
993
 
1000
994
  if (!result) {
1001
- throw new Error("Child state '" + stateKey + "' does not exist on '" + this.id + "'");
995
+ throw new Error("Child state '".concat(stateKey, "' does not exist on '").concat(this.id, "'"));
1002
996
  }
1003
997
 
1004
998
  return result;
@@ -1020,7 +1014,7 @@ function () {
1020
1014
  var stateNode = this.machine.idMap[resolvedStateId];
1021
1015
 
1022
1016
  if (!stateNode) {
1023
- throw new Error("Child state node '#" + resolvedStateId + "' does not exist on machine '" + this.id + "'");
1017
+ throw new Error("Child state node '#".concat(resolvedStateId, "' does not exist on machine '").concat(this.id, "'"));
1024
1018
  }
1025
1019
 
1026
1020
  return stateNode;
@@ -1107,7 +1101,7 @@ function () {
1107
1101
  var stateNode = this.machine.idMap[stateIdentifier.slice(STATE_IDENTIFIER.length)];
1108
1102
 
1109
1103
  if (!stateNode) {
1110
- throw new Error("Unable to find state node '" + stateIdentifier + "'");
1104
+ throw new Error("Unable to find state node '".concat(stateIdentifier, "'"));
1111
1105
  }
1112
1106
 
1113
1107
  return stateNode.path;
@@ -1134,7 +1128,7 @@ function () {
1134
1128
  });
1135
1129
  } else if (this.initial !== undefined) {
1136
1130
  if (!this.states[this.initial]) {
1137
- throw new Error("Initial state '" + this.initial + "' not found on '" + this.key + "'");
1131
+ throw new Error("Initial state '".concat(this.initial, "' not found on '").concat(this.key, "'"));
1138
1132
  }
1139
1133
 
1140
1134
  initialStateValue = isLeafNode(this.states[this.initial]) ? this.initial : (_a = {}, _a[this.initial] = this.states[this.initial].initialStateValue, _a);
@@ -1174,7 +1168,7 @@ function () {
1174
1168
  var initialStateValue = this.initialStateValue;
1175
1169
 
1176
1170
  if (!initialStateValue) {
1177
- throw new Error("Cannot retrieve initial state from simple state '" + this.id + "'.");
1171
+ throw new Error("Cannot retrieve initial state from simple state '".concat(this.id, "'."));
1178
1172
  }
1179
1173
 
1180
1174
  return this.getInitialState(initialStateValue);
@@ -1232,7 +1226,7 @@ function () {
1232
1226
 
1233
1227
  if (this.type === 'compound' && !this.initial) {
1234
1228
  if (!IS_PRODUCTION) {
1235
- warn(false, "Compound state node '" + this.id + "' has no initial state.");
1229
+ warn(false, "Compound state node '".concat(this.id, "' has no initial state."));
1236
1230
  }
1237
1231
 
1238
1232
  return [this];
@@ -1263,7 +1257,7 @@ function () {
1263
1257
  childStatePath = _a.slice(1);
1264
1258
 
1265
1259
  if (!this.states) {
1266
- throw new Error("Cannot retrieve subPath '" + stateKey + "' from node with no states");
1260
+ throw new Error("Cannot retrieve subPath '".concat(stateKey, "' from node with no states"));
1267
1261
  }
1268
1262
 
1269
1263
  var childStateNode = this.getStateNode(stateKey);
@@ -1273,7 +1267,7 @@ function () {
1273
1267
  }
1274
1268
 
1275
1269
  if (!this.states[stateKey]) {
1276
- throw new Error("Child state '" + stateKey + "' does not exist on '" + this.id + "'");
1270
+ throw new Error("Child state '".concat(stateKey, "' does not exist on '").concat(this.id, "'"));
1277
1271
  }
1278
1272
 
1279
1273
  return this.states[stateKey].getFromRelativePath(childStatePath);
@@ -1372,7 +1366,7 @@ function () {
1372
1366
  try {
1373
1367
  for (var _e = (e_8 = void 0, __values(state.events)), _f = _e.next(); !_f.done; _f = _e.next()) {
1374
1368
  var event_1 = _f.value;
1375
- events.add("" + event_1);
1369
+ events.add("".concat(event_1));
1376
1370
  }
1377
1371
  } catch (e_8_1) {
1378
1372
  e_8 = {
@@ -1451,7 +1445,7 @@ function () {
1451
1445
 
1452
1446
  return targetStateNode;
1453
1447
  } catch (err) {
1454
- throw new Error("Invalid transition definition for state node '" + _this.id + "':\n" + err.message);
1448
+ throw new Error("Invalid transition definition for state node '".concat(_this.id, "':\n").concat(err.message));
1455
1449
  }
1456
1450
  } else {
1457
1451
  return _this.getStateNodeByPath(resolvedTarget);
@@ -1479,9 +1473,9 @@ function () {
1479
1473
  toJSON: function () {
1480
1474
  return __assign(__assign({}, transition), {
1481
1475
  target: transition.target ? transition.target.map(function (t) {
1482
- return "#" + t.id;
1476
+ return "#".concat(t.id);
1483
1477
  }) : undefined,
1484
- source: "#" + _this.id
1478
+ source: "#".concat(_this.id)
1485
1479
  });
1486
1480
  }
1487
1481
  });
@@ -1509,7 +1503,7 @@ function () {
1509
1503
 
1510
1504
  onConfig = flatten(keys(strictTransitionConfigs_1).map(function (key) {
1511
1505
  if (!IS_PRODUCTION && key === NULL_EVENT) {
1512
- warn(false, "Empty string transition configs (e.g., `{ on: { '': ... }}`) for transient transitions are deprecated. Specify the transition in the `{ always: ... }` property instead. " + ("Please check the `on` configuration for \"#" + _this.id + "\"."));
1506
+ warn(false, "Empty string transition configs (e.g., `{ on: { '': ... }}`) for transient transitions are deprecated. Specify the transition in the `{ always: ... }` property instead. " + "Please check the `on` configuration for \"#".concat(_this.id, "\"."));
1513
1507
  }
1514
1508
 
1515
1509
  var transitionConfigArray = toTransitionConfigArray(key, strictTransitionConfigs_1[key]);
@@ -1526,24 +1520,24 @@ function () {
1526
1520
  var doneConfig = this.config.onDone ? toTransitionConfigArray(String(done(this.id)), this.config.onDone) : [];
1527
1521
 
1528
1522
  if (!IS_PRODUCTION) {
1529
- warn(!(this.config.onDone && !this.parent), "Root nodes cannot have an \".onDone\" transition. Please check the config of \"" + this.id + "\".");
1523
+ warn(!(this.config.onDone && !this.parent), "Root nodes cannot have an \".onDone\" transition. Please check the config of \"".concat(this.id, "\"."));
1530
1524
  }
1531
1525
 
1532
1526
  var invokeConfig = flatten(this.invoke.map(function (invokeDef) {
1533
1527
  var settleTransitions = [];
1534
1528
 
1535
1529
  if (invokeDef.onDone) {
1536
- settleTransitions.push.apply(settleTransitions, __spreadArray([], __read(toTransitionConfigArray(String(doneInvoke(invokeDef.id)), invokeDef.onDone))));
1530
+ settleTransitions.push.apply(settleTransitions, __spreadArray([], __read(toTransitionConfigArray(String(doneInvoke(invokeDef.id)), invokeDef.onDone)), false));
1537
1531
  }
1538
1532
 
1539
1533
  if (invokeDef.onError) {
1540
- settleTransitions.push.apply(settleTransitions, __spreadArray([], __read(toTransitionConfigArray(String(error(invokeDef.id)), invokeDef.onError))));
1534
+ settleTransitions.push.apply(settleTransitions, __spreadArray([], __read(toTransitionConfigArray(String(error(invokeDef.id)), invokeDef.onError)), false));
1541
1535
  }
1542
1536
 
1543
1537
  return settleTransitions;
1544
1538
  }));
1545
1539
  var delayedTransitions = this.after;
1546
- var formattedTransitions = flatten(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], __read(doneConfig)), __read(invokeConfig)), __read(onConfig)), __read(eventlessConfig)).map(function (transitionConfig) {
1540
+ var formattedTransitions = flatten(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], __read(doneConfig), false), __read(invokeConfig), false), __read(onConfig), false), __read(eventlessConfig), false).map(function (transitionConfig) {
1547
1541
  return toArray(transitionConfig).map(function (transition) {
1548
1542
  return _this.formatTransition(transition);
1549
1543
  });
@@ -65,10 +65,14 @@ function __read(o, n) {
65
65
  return ar;
66
66
  }
67
67
 
68
- function __spreadArray(to, from) {
69
- for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
70
- to[j] = from[i];
71
- return to;
68
+ function __spreadArray(to, from, pack) {
69
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
70
+ if (ar || !(i in from)) {
71
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
72
+ ar[i] = from[i];
73
+ }
74
+ }
75
+ return to.concat(ar || Array.prototype.slice.call(from));
72
76
  }
73
77
 
74
78
  export { __assign, __read, __rest, __spreadArray, __values };
package/es/actions.d.ts CHANGED
@@ -1,14 +1,15 @@
1
- import { Action, Event, EventObject, SingleOrArray, SendAction, SendActionOptions, CancelAction, ActionObject, ActionType, Assigner, PropertyAssigner, AssignAction, ActionFunction, ActionFunctionMap, ActivityActionObject, ActionTypes, ActivityDefinition, RaiseAction, RaiseActionObject, DoneEvent, ErrorPlatformEvent, DoneEventObject, SendExpr, SendActionObject, PureAction, LogExpr, LogAction, LogActionObject, DelayFunctionMap, SCXML, ExprWithMeta, ChooseCondition, ChooseAction, AnyEventObject, Expr, StopAction, StopActionObject } from './types';
1
+ import { Action, Event, EventObject, SingleOrArray, SendAction, SendActionOptions, CancelAction, ActionObject, ActionType, Assigner, PropertyAssigner, AssignAction, ActionFunction, ActionFunctionMap, ActivityActionObject, ActionTypes, ActivityDefinition, RaiseAction, RaiseActionObject, DoneEvent, ErrorPlatformEvent, DoneEventObject, SendExpr, SendActionObject, PureAction, LogExpr, LogAction, LogActionObject, DelayFunctionMap, SCXML, ExprWithMeta, ChooseCondition, ChooseAction, AnyEventObject, Expr, Cast } from './types';
2
2
  import * as actionTypes from './actionTypes';
3
3
  import { State } from './State';
4
4
  import { StateNode } from './StateNode';
5
+ import { ActorRef, EventFrom, StopAction, StopActionObject } from '.';
5
6
  export { actionTypes };
6
7
  export declare const initEvent: SCXML.Event<{
7
8
  type: ActionTypes;
8
9
  }>;
9
10
  export declare function getActionFunction<TContext, TEvent extends EventObject>(actionType: ActionType, actionFunctionMap?: ActionFunctionMap<TContext, TEvent>): ActionObject<TContext, TEvent> | ActionFunction<TContext, TEvent> | undefined;
10
11
  export declare function toActionObject<TContext, TEvent extends EventObject>(action: Action<TContext, TEvent>, actionFunctionMap?: ActionFunctionMap<TContext, TEvent>): ActionObject<TContext, TEvent>;
11
- export declare const toActionObjects: <TContext, TEvent extends EventObject>(action?: SingleOrArray<Action<TContext, TEvent>> | undefined, actionFunctionMap?: ActionFunctionMap<TContext, TEvent, import("./types").BaseActionObject> | undefined) => ActionObject<TContext, TEvent>[];
12
+ export declare const toActionObjects: <TContext, TEvent extends EventObject>(action?: SingleOrArray<Action<TContext, TEvent>> | undefined, actionFunctionMap?: ActionFunctionMap<TContext, TEvent, ActionObject<TContext, TEvent>> | undefined) => ActionObject<TContext, TEvent>[];
12
13
  export declare function toActivityDefinition<TContext, TEvent extends EventObject>(action: string | ActivityDefinition<TContext, TEvent>): ActivityDefinition<TContext, TEvent>;
13
14
  /**
14
15
  * Raises an event. This places the event in the internal event queue, so that
@@ -37,6 +38,22 @@ export declare function resolveSend<TContext, TEvent extends EventObject, TSentE
37
38
  * @param options Options to pass into the send event.
38
39
  */
39
40
  export declare function sendParent<TContext, TEvent extends EventObject, TSentEvent extends EventObject = AnyEventObject>(event: Event<TSentEvent> | SendExpr<TContext, TEvent, TSentEvent>, options?: SendActionOptions<TContext, TEvent>): SendAction<TContext, TEvent, TSentEvent>;
41
+ declare type InferEvent<E extends EventObject> = {
42
+ [T in E['type']]: {
43
+ type: T;
44
+ } & Extract<E, {
45
+ type: T;
46
+ }>;
47
+ }[E['type']];
48
+ /**
49
+ * Sends an event to an actor.
50
+ *
51
+ * @param actor The `ActorRef` to send the event to.
52
+ * @param event The event to send, or an expression that evaluates to the event to send
53
+ * @param options Send action options
54
+ * @returns An XState send action object
55
+ */
56
+ export declare function sendTo<TContext, TEvent extends EventObject, TActor extends ActorRef<EventObject>>(actor: (ctx: TContext) => TActor, event: EventFrom<TActor> | SendExpr<TContext, TEvent, InferEvent<Cast<EventFrom<TActor>, EventObject>>>, options?: SendActionOptions<TContext, TEvent>): SendAction<TContext, TEvent, any>;
40
57
  /**
41
58
  * Sends an update event to this machine's parent.
42
59
  */
@@ -134,5 +151,5 @@ export declare function forwardTo<TContext, TEvent extends EventObject>(target:
134
151
  */
135
152
  export declare function escalate<TContext, TEvent extends EventObject, TErrorData = any>(errorData: TErrorData | ExprWithMeta<TContext, TEvent, TErrorData>, options?: SendActionOptions<TContext, TEvent>): SendAction<TContext, TEvent, AnyEventObject>;
136
153
  export declare function choose<TContext, TEvent extends EventObject>(conds: Array<ChooseCondition<TContext, TEvent>>): ChooseAction<TContext, TEvent>;
137
- export declare function resolveActions<TContext, TEvent extends EventObject>(machine: StateNode<TContext, any, TEvent, any, any>, currentState: State<TContext, TEvent> | undefined, currentContext: TContext, _event: SCXML.Event<TEvent>, actions: Array<ActionObject<TContext, TEvent>>, preserveActionOrder?: boolean): [Array<ActionObject<TContext, TEvent>>, TContext];
154
+ export declare function resolveActions<TContext, TEvent extends EventObject>(machine: StateNode<TContext, any, TEvent, any>, currentState: State<TContext, TEvent> | undefined, currentContext: TContext, _event: SCXML.Event<TEvent>, actions: Array<ActionObject<TContext, TEvent>>, preserveActionOrder?: boolean): [Array<ActionObject<TContext, TEvent>>, TContext];
138
155
  //# sourceMappingURL=actions.d.ts.map
package/es/actions.js CHANGED
@@ -283,8 +283,8 @@ var assign = function (assignment) {
283
283
  */
284
284
 
285
285
  function after(delayRef, id) {
286
- var idSuffix = id ? "#" + id : '';
287
- return ActionTypes.After + "(" + delayRef + ")" + idSuffix;
286
+ var idSuffix = id ? "#".concat(id) : '';
287
+ return "".concat(ActionTypes.After, "(").concat(delayRef, ")").concat(idSuffix);
288
288
  }
289
289
  /**
290
290
  * Returns an event that represents that a final state node
@@ -295,7 +295,7 @@ function after(delayRef, id) {
295
295
  */
296
296
 
297
297
  function done(id, data) {
298
- var type = ActionTypes.DoneState + "." + id;
298
+ var type = "".concat(ActionTypes.DoneState, ".").concat(id);
299
299
  var eventObject = {
300
300
  type: type,
301
301
  data: data
@@ -318,7 +318,7 @@ function done(id, data) {
318
318
  */
319
319
 
320
320
  function doneInvoke(id, data) {
321
- var type = ActionTypes.DoneInvoke + "." + id;
321
+ var type = "".concat(ActionTypes.DoneInvoke, ".").concat(id);
322
322
  var eventObject = {
323
323
  type: type,
324
324
  data: data
@@ -331,7 +331,7 @@ function doneInvoke(id, data) {
331
331
  return eventObject;
332
332
  }
333
333
  function error(id, data) {
334
- var type = ActionTypes.ErrorPlatform + "." + id;
334
+ var type = "".concat(ActionTypes.ErrorPlatform, ".").concat(id);
335
335
  var eventObject = {
336
336
  type: type,
337
337
  data: data
@@ -413,7 +413,7 @@ function resolveActions(machine, currentState, currentContext, _event, actions,
413
413
  if (!IS_PRODUCTION) {
414
414
  // warn after resolving as we can create better contextual message here
415
415
  warn(!isString(actionObject.delay) || typeof sendAction.delay === 'number', // tslint:disable-next-line:max-line-length
416
- "No delay reference for delay expression '" + actionObject.delay + "' was found on machine '" + machine.id + "'");
416
+ "No delay reference for delay expression '".concat(actionObject.delay, "' was found on machine '").concat(machine.id, "'"));
417
417
  }
418
418
 
419
419
  return sendAction;
@@ -485,7 +485,7 @@ function resolveActions(machine, currentState, currentContext, _event, actions,
485
485
  args[_i - 1] = arguments[_i];
486
486
  }
487
487
 
488
- exec_1.apply(void 0, __spreadArray([preservedContexts[contextIndex_1]], __read(args)));
488
+ exec_1.apply(void 0, __spreadArray([preservedContexts[contextIndex_1]], __read(args), false));
489
489
  }
490
490
  });
491
491
  }
package/es/behaviors.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ActorContext, ActorRef, Behavior, EventObject } from './types';
1
+ import { ActorContext, ActorRef, Behavior, EventObject } from '.';
2
2
  /**
3
3
  * Returns an actor behavior from a reducer and its initial state.
4
4
  *
package/es/devTools.d.ts CHANGED
@@ -1,6 +1,5 @@
1
- /// <reference types="node" />
1
+ import { Interpreter } from '.';
2
2
  import { AnyInterpreter } from './types';
3
- import { Interpreter } from './interpreter';
4
3
  declare type ServiceListener = (service: AnyInterpreter) => void;
5
4
  export interface XStateDevInterface {
6
5
  register: (service: Interpreter<any>) => void;
@@ -10,7 +9,7 @@ export interface XStateDevInterface {
10
9
  };
11
10
  services: Set<Interpreter<any>>;
12
11
  }
13
- export declare function getGlobal(): (Window & typeof globalThis) | (NodeJS.Global & typeof globalThis) | undefined;
12
+ export declare function getGlobal(): typeof globalThis | undefined;
14
13
  export declare function registerService(service: AnyInterpreter): void;
15
14
  export {};
16
15
  //# sourceMappingURL=devTools.d.ts.map
package/es/devTools.js CHANGED
@@ -1,5 +1,9 @@
1
1
  // From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis
2
2
  function getGlobal() {
3
+ if (typeof globalThis !== 'undefined') {
4
+ return globalThis;
5
+ }
6
+
3
7
  if (typeof self !== 'undefined') {
4
8
  return self;
5
9
  }
package/es/each.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { EventObject, SingleOrArray, ActionObject } from './types';
1
+ import { EventObject, SingleOrArray, ActionObject } from '.';
2
2
  export declare function each<TContext, TEvent extends EventObject>(collection: keyof TContext, item: keyof TContext, actions: SingleOrArray<ActionObject<TContext, TEvent>>): ActionObject<TContext, TEvent>;
3
3
  export declare function each<TContext, TEvent extends EventObject>(collection: keyof TContext, item: keyof TContext, index: keyof TContext, actions: SingleOrArray<ActionObject<TContext, TEvent>>): ActionObject<TContext, TEvent>;
4
4
  //# sourceMappingURL=each.d.ts.map
package/es/index.d.ts CHANGED
@@ -28,5 +28,4 @@ declare const actions: {
28
28
  };
29
29
  export { Actor, Machine, StateNode, State, matchesState, mapState, actions, assign, send, sendParent, sendUpdate, forwardTo, interpret, Interpreter, InterpreterStatus, matchState, spawn, doneInvoke, createMachine, createSchema };
30
30
  export * from './types';
31
- export * from './typegenTypes';
32
31
  //# sourceMappingURL=index.d.ts.map