xstate 4.26.0-pr2674-202191175724 → 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 +60 -10
  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 +15 -15
  10. package/es/StateNode.js +50 -56
  11. package/es/_virtual/_tslib.js +8 -4
  12. package/es/actions.d.ts +21 -4
  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 +23 -17
  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 +6 -6
  26. package/es/stateUtils.js +8 -3
  27. package/es/types.d.ts +55 -69
  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 +15 -15
  36. package/lib/StateNode.js +47 -53
  37. package/lib/_virtual/_tslib.js +8 -4
  38. package/lib/actions.d.ts +21 -4
  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 +23 -17
  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 +6 -6
  56. package/lib/stateUtils.js +7 -1
  57. package/lib/types.d.ts +55 -69
  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 -78
  64. package/lib/typegenTypes.d.ts +0 -78
  65. package/lib/typegenTypes.js +0 -2
@@ -1,10 +1,9 @@
1
- import { Event, StateValue, MachineOptions, EventObject, HistoryValue, StateNodeDefinition, TransitionDefinition, DelayedTransitionDefinition, ActivityDefinition, StateNodeConfig, StateSchema, StateNodesConfig, InvokeDefinition, ActionObject, Mapper, PropertyMapper, SCXML, Typestate, TransitionDefinitionMap, MachineSchema, BaseActionObject } from './types';
1
+ import { Event, StateValue, StateTransition, MachineOptions, EventObject, HistoryValue, StateNodeDefinition, TransitionDefinition, DelayedTransitionDefinition, ActivityDefinition, StateNodeConfig, StateSchema, StateNodesConfig, InvokeDefinition, ActionObject, Mapper, PropertyMapper, SCXML, Typestate, TransitionDefinitionMap, MachineSchema } from './types';
2
2
  import { State } from './State';
3
- import { MaybeTypegenMachineOptions, TypegenDisabled } from './typegenTypes';
4
3
  declare class StateNode<TContext = any, TStateSchema extends StateSchema = any, TEvent extends EventObject = EventObject, TTypestate extends Typestate<TContext> = {
5
4
  value: any;
6
5
  context: TContext;
7
- }, TResolvedTypesMeta = TypegenDisabled> {
6
+ }> {
8
7
  /**
9
8
  * The raw config used to create the machine.
10
9
  */
@@ -120,7 +119,7 @@ declare class StateNode<TContext = any, TStateSchema extends StateSchema = any,
120
119
  /**
121
120
  * The raw config used to create the machine.
122
121
  */
123
- config: StateNodeConfig<TContext, TStateSchema, TEvent>, options?: MachineOptions<TContext, TEvent>,
122
+ config: StateNodeConfig<TContext, TStateSchema, TEvent>, options?: Partial<MachineOptions<TContext, TEvent>>,
124
123
  /**
125
124
  * The initial extended state
126
125
  */
@@ -132,7 +131,7 @@ declare class StateNode<TContext = any, TStateSchema extends StateSchema = any,
132
131
  * @param options Options (actions, guards, activities, services) to recursively merge with the existing options.
133
132
  * @param context Custom context (will override predefined context)
134
133
  */
135
- withConfig(options: MaybeTypegenMachineOptions<TContext, TEvent, BaseActionObject, TResolvedTypesMeta, true>, context?: TContext | (() => TContext)): StateNode<TContext, TStateSchema, TEvent, TTypestate, TResolvedTypesMeta>;
134
+ withConfig(options: Partial<MachineOptions<TContext, TEvent>>, context?: TContext | (() => TContext)): StateNode<TContext, TStateSchema, TEvent, TTypestate>;
136
135
  /**
137
136
  * Clones this state machine with custom context.
138
137
  *
@@ -164,7 +163,7 @@ declare class StateNode<TContext = any, TStateSchema extends StateSchema = any,
164
163
  *
165
164
  * @param state The state value or State instance
166
165
  */
167
- getStateNodes(state: StateValue | State<TContext, TEvent, any, TTypestate, TResolvedTypesMeta>): Array<StateNode<TContext, any, TEvent, TTypestate, TResolvedTypesMeta>>;
166
+ getStateNodes(state: StateValue | State<TContext, TEvent, any, TTypestate>): Array<StateNode<TContext, any, TEvent, TTypestate>>;
168
167
  /**
169
168
  * Returns `true` if this state node explicitly handles the given event.
170
169
  *
@@ -178,11 +177,12 @@ declare class StateNode<TContext = any, TStateSchema extends StateSchema = any,
178
177
  *
179
178
  * @param state The state to resolve
180
179
  */
181
- resolveState(state: State<TContext, TEvent, any, any, TResolvedTypesMeta>): State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>;
180
+ resolveState(state: State<TContext, TEvent, any, any>): State<TContext, TEvent, TStateSchema, TTypestate>;
182
181
  private transitionLeafNode;
183
182
  private transitionCompoundNode;
184
183
  private transitionParallelNode;
185
184
  private _transition;
185
+ getTransitionData(state: State<TContext, TEvent, any, any>, event: Event<TEvent> | SCXML.Event<TEvent>): StateTransition<TContext, TEvent> | undefined;
186
186
  private next;
187
187
  private nodesFromChild;
188
188
  /**
@@ -198,25 +198,25 @@ declare class StateNode<TContext = any, TStateSchema extends StateSchema = any,
198
198
  * @param event The event that was sent at the current state
199
199
  * @param context The current context (extended state) of the current state
200
200
  */
201
- transition(state: StateValue | State<TContext, TEvent, any, TTypestate, TResolvedTypesMeta> | undefined, event: Event<TEvent> | SCXML.Event<TEvent>, context?: TContext): State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>;
201
+ transition(state: StateValue | State<TContext, TEvent, any, TTypestate> | undefined, event: Event<TEvent> | SCXML.Event<TEvent>, context?: TContext): State<TContext, TEvent, TStateSchema, TTypestate>;
202
202
  private resolveRaisedTransition;
203
203
  private resolveTransition;
204
204
  /**
205
205
  * Returns the child state node from its relative `stateKey`, or throws.
206
206
  */
207
- getStateNode(stateKey: string): StateNode<TContext, any, TEvent, TTypestate, TResolvedTypesMeta>;
207
+ getStateNode(stateKey: string): StateNode<TContext, any, TEvent, TTypestate>;
208
208
  /**
209
209
  * Returns the state node with the given `stateId`, or throws.
210
210
  *
211
211
  * @param stateId The state ID. The prefix "#" is removed.
212
212
  */
213
- getStateNodeById(stateId: string): StateNode<TContext, any, TEvent, any, TResolvedTypesMeta>;
213
+ getStateNodeById(stateId: string): StateNode<TContext, any, TEvent, any>;
214
214
  /**
215
215
  * Returns the relative state node from the given `statePath`, or throws.
216
216
  *
217
217
  * @param statePath The string or string array relative path to the state node.
218
218
  */
219
- getStateNodeByPath(statePath: string | string[]): StateNode<TContext, any, TEvent, any, any>;
219
+ getStateNodeByPath(statePath: string | string[]): StateNode<TContext, any, TEvent, any>;
220
220
  /**
221
221
  * Resolves a partial state value with its full representation in this machine.
222
222
  *
@@ -225,12 +225,12 @@ declare class StateNode<TContext = any, TStateSchema extends StateSchema = any,
225
225
  resolve(stateValue: StateValue): StateValue;
226
226
  private getResolvedPath;
227
227
  private get initialStateValue();
228
- getInitialState(stateValue: StateValue, context?: TContext): State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>;
228
+ getInitialState(stateValue: StateValue, context?: TContext): State<TContext, TEvent, TStateSchema, TTypestate>;
229
229
  /**
230
230
  * The initial State instance, which includes all actions to be executed from
231
231
  * entering the initial state.
232
232
  */
233
- get initialState(): State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>;
233
+ get initialState(): State<TContext, TEvent, TStateSchema, TTypestate>;
234
234
  /**
235
235
  * The target state value of the history state node, if it exists. This represents the
236
236
  * default state value to transition to if no history value exists yet.
@@ -244,14 +244,14 @@ declare class StateNode<TContext = any, TStateSchema extends StateSchema = any,
244
244
  * @param resolve Whether state nodes should resolve to initial child state nodes
245
245
  */
246
246
  getRelativeStateNodes(relativeStateId: StateNode<TContext, any, TEvent>, historyValue?: HistoryValue, resolve?: boolean): Array<StateNode<TContext, any, TEvent>>;
247
- get initialStateNodes(): Array<StateNode<TContext, any, TEvent, any, any>>;
247
+ get initialStateNodes(): Array<StateNode<TContext, any, TEvent, any>>;
248
248
  /**
249
249
  * Retrieves state nodes from a relative path to this state node.
250
250
  *
251
251
  * @param relativePath The relative path from this state node
252
252
  * @param historyValue
253
253
  */
254
- getFromRelativePath(relativePath: string[]): Array<StateNode<TContext, any, TEvent, any, any>>;
254
+ getFromRelativePath(relativePath: string[]): Array<StateNode<TContext, any, TEvent, any>>;
255
255
  private historyValue;
256
256
  /**
257
257
  * Resolves to the historical value(s) of the parent state node,
package/lib/StateNode.js CHANGED
@@ -37,8 +37,8 @@ var validateArrayifiedTransitions = function (stateNode, event, transitions) {
37
37
  var hasNonLastUnguardedTarget = transitions.slice(0, -1).some(function (transition) {
38
38
  return !('cond' in transition) && !('in' in transition) && (utils.isString(transition.target) || utils.isMachine(transition.target));
39
39
  });
40
- var eventText = event === NULL_EVENT ? 'the transient event' : "event '" + event + "'";
41
- utils.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.");
40
+ var eventText = event === NULL_EVENT ? 'the transient event' : "event '".concat(event, "'");
41
+ utils.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.");
42
42
  };
43
43
 
44
44
  var StateNode =
@@ -90,14 +90,14 @@ function () {
90
90
  this.machine = this.parent ? this.parent.machine : this;
91
91
  this.path = this.parent ? this.parent.path.concat(this.key) : [];
92
92
  this.delimiter = this.config.delimiter || (this.parent ? this.parent.delimiter : constants.STATE_DELIMITER);
93
- this.id = this.config.id || _tslib.__spreadArray([this.machine.key], _tslib.__read(this.path)).join(this.delimiter);
93
+ this.id = this.config.id || _tslib.__spreadArray([this.machine.key], _tslib.__read(this.path), false).join(this.delimiter);
94
94
  this.version = this.parent ? this.parent.version : this.config.version;
95
95
  this.type = this.config.type || (this.config.parallel ? 'parallel' : this.config.states && utils.keys(this.config.states).length ? 'compound' : this.config.history ? 'history' : 'atomic');
96
96
  this.schema = this.parent ? this.machine.schema : (_a = this.config.schema) !== null && _a !== void 0 ? _a : {};
97
97
  this.description = this.config.description;
98
98
 
99
99
  if (!environment.IS_PRODUCTION) {
100
- utils.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.");
100
+ utils.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."));
101
101
  }
102
102
 
103
103
  this.initial = this.config.initial;
@@ -170,7 +170,7 @@ function () {
170
170
  src: invokeConfig.src
171
171
  }));
172
172
  } else if (utils.isMachine(invokeConfig.src) || utils.isFunction(invokeConfig.src)) {
173
- var invokeSrc = _this.id + ":invocation[" + i + "]"; // TODO: util function
173
+ var invokeSrc = "".concat(_this.id, ":invocation[").concat(i, "]"); // TODO: util function
174
174
 
175
175
  _this.machine.options.services = _tslib.__assign((_b = {}, _b[invokeSrc] = invokeConfig.src, _b), _this.machine.options.services);
176
176
  return invokeUtils.toInvokeDefinition(_tslib.__assign(_tslib.__assign({
@@ -273,7 +273,8 @@ function () {
273
273
  order: this.order || -1,
274
274
  data: this.doneData,
275
275
  invoke: this.invoke,
276
- description: this.description
276
+ description: this.description,
277
+ tags: this.tags
277
278
  };
278
279
  },
279
280
  enumerable: false,
@@ -350,7 +351,7 @@ function () {
350
351
  }
351
352
 
352
353
  var mutateEntryExit = function (delay, i) {
353
- var delayRef = utils.isFunction(delay) ? _this.id + ":delay[" + i + "]" : delay;
354
+ var delayRef = utils.isFunction(delay) ? "".concat(_this.id, ":delay[").concat(i, "]") : delay;
354
355
  var eventType = actions.after(delayRef, _this.id);
355
356
 
356
357
  _this.onEntry.push(actions.send(eventType, {
@@ -412,15 +413,11 @@ function () {
412
413
  }
413
414
 
414
415
  var subStateKeys = utils.keys(stateValue);
415
- var subStateNodes = subStateKeys.map(function (subStateKey) {
416
- return _this.getStateNode(subStateKey);
417
- });
418
- subStateNodes.push(this);
419
- return subStateNodes.concat(subStateKeys.reduce(function (allSubStateNodes, subStateKey) {
420
- var subStateNode = _this.getStateNode(subStateKey).getStateNodes(stateValue[subStateKey]);
421
-
422
- return allSubStateNodes.concat(subStateNode);
423
- }, []));
416
+ var subStateNodes = [this];
417
+ subStateNodes.push.apply(subStateNodes, _tslib.__spreadArray([], _tslib.__read(utils.flatten(subStateKeys.map(function (subStateKey) {
418
+ return _this.getStateNode(subStateKey).getStateNodes(stateValue[subStateKey]);
419
+ }))), false));
420
+ return subStateNodes;
424
421
  };
425
422
  /**
426
423
  * Returns `true` if this state node explicitly handles the given event.
@@ -447,7 +444,8 @@ function () {
447
444
  return new State.State(_tslib.__assign(_tslib.__assign({}, state), {
448
445
  value: this.resolve(state.value),
449
446
  configuration: configuration,
450
- done: stateUtils.isInFinalState(configuration, this)
447
+ done: stateUtils.isInFinalState(configuration, this),
448
+ tags: stateUtils.getTagsFromConfiguration(configuration)
451
449
  }));
452
450
  };
453
451
 
@@ -558,6 +556,10 @@ function () {
558
556
  return this.transitionParallelNode(stateValue, state, _event);
559
557
  };
560
558
 
559
+ StateNode.prototype.getTransitionData = function (state, event) {
560
+ return this._transition(state.value, state, utils.toSCXMLEvent(event));
561
+ };
562
+
561
563
  StateNode.prototype.next = function (state, _event) {
562
564
  var e_3, _a;
563
565
 
@@ -582,7 +584,7 @@ function () {
582
584
  try {
583
585
  guardPassed = !cond || utils.evaluateGuard(this.machine, cond, resolvedContext, _event, state);
584
586
  } catch (err) {
585
- throw new Error("Unable to evaluate guard '" + (cond.name || cond.type) + "' in transition for event '" + eventName + "' in state node '" + this.id + "':\n" + err.message);
587
+ 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));
586
588
  }
587
589
 
588
590
  if (guardPassed && isInState) {
@@ -590,7 +592,7 @@ function () {
590
592
  nextStateNodes = candidate.target;
591
593
  }
592
594
 
593
- actions.push.apply(actions, _tslib.__spreadArray([], _tslib.__read(candidate.actions)));
595
+ actions.push.apply(actions, _tslib.__spreadArray([], _tslib.__read(candidate.actions), false));
594
596
  selectedTransition = candidate;
595
597
  break;
596
598
  }
@@ -726,12 +728,6 @@ function () {
726
728
  }
727
729
  }
728
730
 
729
- if (!transition.source) {
730
- transition.exitSet = []; // Ensure that root StateNode (machine) is entered
731
-
732
- transition.entrySet.push(this);
733
- }
734
-
735
731
  var doneEvents = utils.flatten(transition.entrySet.map(function (sn) {
736
732
  var events = [];
737
733
 
@@ -771,11 +767,11 @@ function () {
771
767
  var _c = _tslib.__read([utils.flatten(Array.from(entryStates).map(function (stateNode) {
772
768
  return _tslib.__spreadArray(_tslib.__spreadArray([], _tslib.__read(stateNode.activities.map(function (activity) {
773
769
  return actions.start(activity);
774
- }))), _tslib.__read(stateNode.onEntry));
770
+ })), false), _tslib.__read(stateNode.onEntry), false);
775
771
  })).concat(doneEvents.map(actions.raise)), utils.flatten(Array.from(exitStates).map(function (stateNode) {
776
- return _tslib.__spreadArray(_tslib.__spreadArray([], _tslib.__read(stateNode.onExit)), _tslib.__read(stateNode.activities.map(function (activity) {
772
+ return _tslib.__spreadArray(_tslib.__spreadArray([], _tslib.__read(stateNode.onExit), false), _tslib.__read(stateNode.activities.map(function (activity) {
777
773
  return actions.stop(activity);
778
- })));
774
+ })), false);
779
775
  }))], 2),
780
776
  entryActions = _c[0],
781
777
  exitActions = _c[1];
@@ -810,12 +806,12 @@ function () {
810
806
  }
811
807
 
812
808
  if (!environment.IS_PRODUCTION && _event.name === WILDCARD) {
813
- throw new Error("An event cannot have the wildcard type ('" + WILDCARD + "')");
809
+ throw new Error("An event cannot have the wildcard type ('".concat(WILDCARD, "')"));
814
810
  }
815
811
 
816
812
  if (this.strict) {
817
813
  if (!this.events.includes(_event.name) && !utils.isBuiltInEvent(_event.name)) {
818
- throw new Error("Machine '" + this.id + "' does not accept event '" + _event.name + "'");
814
+ throw new Error("Machine '".concat(this.id, "' does not accept event '").concat(_event.name, "'"));
819
815
  }
820
816
  }
821
817
 
@@ -829,7 +825,7 @@ function () {
829
825
  };
830
826
  var prevConfig = stateUtils.getConfiguration([], this.getStateNodes(currentState.value));
831
827
  var resolvedConfig = stateTransition.configuration.length ? stateUtils.getConfiguration(prevConfig, stateTransition.configuration) : prevConfig;
832
- stateTransition.configuration = _tslib.__spreadArray([], _tslib.__read(resolvedConfig));
828
+ stateTransition.configuration = _tslib.__spreadArray([], _tslib.__read(resolvedConfig), false);
833
829
  return this.resolveTransition(stateTransition, currentState, _event);
834
830
  };
835
831
 
@@ -843,7 +839,7 @@ function () {
843
839
  state._event = originalEvent;
844
840
  state.event = originalEvent.data;
845
841
 
846
- (_a = state.actions).unshift.apply(_a, _tslib.__spreadArray([], _tslib.__read(currentActions)));
842
+ (_a = state.actions).unshift.apply(_a, _tslib.__spreadArray([], _tslib.__read(currentActions), false));
847
843
 
848
844
  return state;
849
845
  };
@@ -980,9 +976,7 @@ function () {
980
976
  maybeNextState.changed = changed; // Preserve original history after raised events
981
977
 
982
978
  maybeNextState.history = history;
983
- maybeNextState.tags = new Set(utils.flatten(maybeNextState.configuration.map(function (sn) {
984
- return sn.tags;
985
- })));
979
+ maybeNextState.tags = stateUtils.getTagsFromConfiguration(maybeNextState.configuration);
986
980
  return maybeNextState;
987
981
  };
988
982
  /**
@@ -996,13 +990,13 @@ function () {
996
990
  }
997
991
 
998
992
  if (!this.states) {
999
- throw new Error("Unable to retrieve child state '" + stateKey + "' from '" + this.id + "'; no child states exist.");
993
+ throw new Error("Unable to retrieve child state '".concat(stateKey, "' from '").concat(this.id, "'; no child states exist."));
1000
994
  }
1001
995
 
1002
996
  var result = this.states[stateKey];
1003
997
 
1004
998
  if (!result) {
1005
- throw new Error("Child state '" + stateKey + "' does not exist on '" + this.id + "'");
999
+ throw new Error("Child state '".concat(stateKey, "' does not exist on '").concat(this.id, "'"));
1006
1000
  }
1007
1001
 
1008
1002
  return result;
@@ -1024,7 +1018,7 @@ function () {
1024
1018
  var stateNode = this.machine.idMap[resolvedStateId];
1025
1019
 
1026
1020
  if (!stateNode) {
1027
- throw new Error("Child state node '#" + resolvedStateId + "' does not exist on machine '" + this.id + "'");
1021
+ throw new Error("Child state node '#".concat(resolvedStateId, "' does not exist on machine '").concat(this.id, "'"));
1028
1022
  }
1029
1023
 
1030
1024
  return stateNode;
@@ -1111,7 +1105,7 @@ function () {
1111
1105
  var stateNode = this.machine.idMap[stateIdentifier.slice(STATE_IDENTIFIER.length)];
1112
1106
 
1113
1107
  if (!stateNode) {
1114
- throw new Error("Unable to find state node '" + stateIdentifier + "'");
1108
+ throw new Error("Unable to find state node '".concat(stateIdentifier, "'"));
1115
1109
  }
1116
1110
 
1117
1111
  return stateNode.path;
@@ -1138,7 +1132,7 @@ function () {
1138
1132
  });
1139
1133
  } else if (this.initial !== undefined) {
1140
1134
  if (!this.states[this.initial]) {
1141
- throw new Error("Initial state '" + this.initial + "' not found on '" + this.key + "'");
1135
+ throw new Error("Initial state '".concat(this.initial, "' not found on '").concat(this.key, "'"));
1142
1136
  }
1143
1137
 
1144
1138
  initialStateValue = stateUtils.isLeafNode(this.states[this.initial]) ? this.initial : (_a = {}, _a[this.initial] = this.states[this.initial].initialStateValue, _a);
@@ -1178,7 +1172,7 @@ function () {
1178
1172
  var initialStateValue = this.initialStateValue;
1179
1173
 
1180
1174
  if (!initialStateValue) {
1181
- throw new Error("Cannot retrieve initial state from simple state '" + this.id + "'.");
1175
+ throw new Error("Cannot retrieve initial state from simple state '".concat(this.id, "'."));
1182
1176
  }
1183
1177
 
1184
1178
  return this.getInitialState(initialStateValue);
@@ -1236,7 +1230,7 @@ function () {
1236
1230
 
1237
1231
  if (this.type === 'compound' && !this.initial) {
1238
1232
  if (!environment.IS_PRODUCTION) {
1239
- utils.warn(false, "Compound state node '" + this.id + "' has no initial state.");
1233
+ utils.warn(false, "Compound state node '".concat(this.id, "' has no initial state."));
1240
1234
  }
1241
1235
 
1242
1236
  return [this];
@@ -1267,7 +1261,7 @@ function () {
1267
1261
  childStatePath = _a.slice(1);
1268
1262
 
1269
1263
  if (!this.states) {
1270
- throw new Error("Cannot retrieve subPath '" + stateKey + "' from node with no states");
1264
+ throw new Error("Cannot retrieve subPath '".concat(stateKey, "' from node with no states"));
1271
1265
  }
1272
1266
 
1273
1267
  var childStateNode = this.getStateNode(stateKey);
@@ -1277,7 +1271,7 @@ function () {
1277
1271
  }
1278
1272
 
1279
1273
  if (!this.states[stateKey]) {
1280
- throw new Error("Child state '" + stateKey + "' does not exist on '" + this.id + "'");
1274
+ throw new Error("Child state '".concat(stateKey, "' does not exist on '").concat(this.id, "'"));
1281
1275
  }
1282
1276
 
1283
1277
  return this.states[stateKey].getFromRelativePath(childStatePath);
@@ -1376,7 +1370,7 @@ function () {
1376
1370
  try {
1377
1371
  for (var _e = (e_8 = void 0, _tslib.__values(state.events)), _f = _e.next(); !_f.done; _f = _e.next()) {
1378
1372
  var event_1 = _f.value;
1379
- events.add("" + event_1);
1373
+ events.add("".concat(event_1));
1380
1374
  }
1381
1375
  } catch (e_8_1) {
1382
1376
  e_8 = {
@@ -1455,7 +1449,7 @@ function () {
1455
1449
 
1456
1450
  return targetStateNode;
1457
1451
  } catch (err) {
1458
- throw new Error("Invalid transition definition for state node '" + _this.id + "':\n" + err.message);
1452
+ throw new Error("Invalid transition definition for state node '".concat(_this.id, "':\n").concat(err.message));
1459
1453
  }
1460
1454
  } else {
1461
1455
  return _this.getStateNodeByPath(resolvedTarget);
@@ -1483,9 +1477,9 @@ function () {
1483
1477
  toJSON: function () {
1484
1478
  return _tslib.__assign(_tslib.__assign({}, transition), {
1485
1479
  target: transition.target ? transition.target.map(function (t) {
1486
- return "#" + t.id;
1480
+ return "#".concat(t.id);
1487
1481
  }) : undefined,
1488
- source: "#" + _this.id
1482
+ source: "#".concat(_this.id)
1489
1483
  });
1490
1484
  }
1491
1485
  });
@@ -1513,7 +1507,7 @@ function () {
1513
1507
 
1514
1508
  onConfig = utils.flatten(utils.keys(strictTransitionConfigs_1).map(function (key) {
1515
1509
  if (!environment.IS_PRODUCTION && key === NULL_EVENT) {
1516
- utils.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 + "\"."));
1510
+ utils.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, "\"."));
1517
1511
  }
1518
1512
 
1519
1513
  var transitionConfigArray = utils.toTransitionConfigArray(key, strictTransitionConfigs_1[key]);
@@ -1530,24 +1524,24 @@ function () {
1530
1524
  var doneConfig = this.config.onDone ? utils.toTransitionConfigArray(String(actions.done(this.id)), this.config.onDone) : [];
1531
1525
 
1532
1526
  if (!environment.IS_PRODUCTION) {
1533
- utils.warn(!(this.config.onDone && !this.parent), "Root nodes cannot have an \".onDone\" transition. Please check the config of \"" + this.id + "\".");
1527
+ utils.warn(!(this.config.onDone && !this.parent), "Root nodes cannot have an \".onDone\" transition. Please check the config of \"".concat(this.id, "\"."));
1534
1528
  }
1535
1529
 
1536
1530
  var invokeConfig = utils.flatten(this.invoke.map(function (invokeDef) {
1537
1531
  var settleTransitions = [];
1538
1532
 
1539
1533
  if (invokeDef.onDone) {
1540
- settleTransitions.push.apply(settleTransitions, _tslib.__spreadArray([], _tslib.__read(utils.toTransitionConfigArray(String(actions.doneInvoke(invokeDef.id)), invokeDef.onDone))));
1534
+ settleTransitions.push.apply(settleTransitions, _tslib.__spreadArray([], _tslib.__read(utils.toTransitionConfigArray(String(actions.doneInvoke(invokeDef.id)), invokeDef.onDone)), false));
1541
1535
  }
1542
1536
 
1543
1537
  if (invokeDef.onError) {
1544
- settleTransitions.push.apply(settleTransitions, _tslib.__spreadArray([], _tslib.__read(utils.toTransitionConfigArray(String(actions.error(invokeDef.id)), invokeDef.onError))));
1538
+ settleTransitions.push.apply(settleTransitions, _tslib.__spreadArray([], _tslib.__read(utils.toTransitionConfigArray(String(actions.error(invokeDef.id)), invokeDef.onError)), false));
1545
1539
  }
1546
1540
 
1547
1541
  return settleTransitions;
1548
1542
  }));
1549
1543
  var delayedTransitions = this.after;
1550
- var formattedTransitions = utils.flatten(_tslib.__spreadArray(_tslib.__spreadArray(_tslib.__spreadArray(_tslib.__spreadArray([], _tslib.__read(doneConfig)), _tslib.__read(invokeConfig)), _tslib.__read(onConfig)), _tslib.__read(eventlessConfig)).map(function (transitionConfig) {
1544
+ var formattedTransitions = utils.flatten(_tslib.__spreadArray(_tslib.__spreadArray(_tslib.__spreadArray(_tslib.__spreadArray([], _tslib.__read(doneConfig), false), _tslib.__read(invokeConfig), false), _tslib.__read(onConfig), false), _tslib.__read(eventlessConfig), false).map(function (transitionConfig) {
1551
1545
  return utils.toArray(transitionConfig).map(function (transition) {
1552
1546
  return _this.formatTransition(transition);
1553
1547
  });
@@ -69,10 +69,14 @@ function __read(o, n) {
69
69
  return ar;
70
70
  }
71
71
 
72
- function __spreadArray(to, from) {
73
- for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
74
- to[j] = from[i];
75
- return to;
72
+ function __spreadArray(to, from, pack) {
73
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
74
+ if (ar || !(i in from)) {
75
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
76
+ ar[i] = from[i];
77
+ }
78
+ }
79
+ return to.concat(ar || Array.prototype.slice.call(from));
76
80
  }
77
81
 
78
82
  exports.__read = __read;
package/lib/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, ChooseConditon, 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
  */
@@ -133,6 +150,6 @@ export declare function forwardTo<TContext, TEvent extends EventObject>(target:
133
150
  * @param options Options to pass into the send action creator.
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
- export declare function choose<TContext, TEvent extends EventObject>(conds: Array<ChooseConditon<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];
153
+ export declare function choose<TContext, TEvent extends EventObject>(conds: Array<ChooseCondition<TContext, TEvent>>): ChooseAction<TContext, TEvent>;
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/lib/actions.js CHANGED
@@ -287,8 +287,8 @@ var assign = function (assignment) {
287
287
  */
288
288
 
289
289
  function after(delayRef, id) {
290
- var idSuffix = id ? "#" + id : '';
291
- return types.ActionTypes.After + "(" + delayRef + ")" + idSuffix;
290
+ var idSuffix = id ? "#".concat(id) : '';
291
+ return "".concat(types.ActionTypes.After, "(").concat(delayRef, ")").concat(idSuffix);
292
292
  }
293
293
  /**
294
294
  * Returns an event that represents that a final state node
@@ -299,7 +299,7 @@ function after(delayRef, id) {
299
299
  */
300
300
 
301
301
  function done(id, data) {
302
- var type = types.ActionTypes.DoneState + "." + id;
302
+ var type = "".concat(types.ActionTypes.DoneState, ".").concat(id);
303
303
  var eventObject = {
304
304
  type: type,
305
305
  data: data
@@ -322,7 +322,7 @@ function done(id, data) {
322
322
  */
323
323
 
324
324
  function doneInvoke(id, data) {
325
- var type = types.ActionTypes.DoneInvoke + "." + id;
325
+ var type = "".concat(types.ActionTypes.DoneInvoke, ".").concat(id);
326
326
  var eventObject = {
327
327
  type: type,
328
328
  data: data
@@ -335,7 +335,7 @@ function doneInvoke(id, data) {
335
335
  return eventObject;
336
336
  }
337
337
  function error(id, data) {
338
- var type = types.ActionTypes.ErrorPlatform + "." + id;
338
+ var type = "".concat(types.ActionTypes.ErrorPlatform, ".").concat(id);
339
339
  var eventObject = {
340
340
  type: type,
341
341
  data: data
@@ -417,7 +417,7 @@ function resolveActions(machine, currentState, currentContext, _event, actions,
417
417
  if (!environment.IS_PRODUCTION) {
418
418
  // warn after resolving as we can create better contextual message here
419
419
  utils.warn(!utils.isString(actionObject.delay) || typeof sendAction.delay === 'number', // tslint:disable-next-line:max-line-length
420
- "No delay reference for delay expression '" + actionObject.delay + "' was found on machine '" + machine.id + "'");
420
+ "No delay reference for delay expression '".concat(actionObject.delay, "' was found on machine '").concat(machine.id, "'"));
421
421
  }
422
422
 
423
423
  return sendAction;
@@ -489,7 +489,7 @@ function resolveActions(machine, currentState, currentContext, _event, actions,
489
489
  args[_i - 1] = arguments[_i];
490
490
  }
491
491
 
492
- exec_1.apply(void 0, _tslib.__spreadArray([preservedContexts[contextIndex_1]], _tslib.__read(args)));
492
+ exec_1.apply(void 0, _tslib.__spreadArray([preservedContexts[contextIndex_1]], _tslib.__read(args), false));
493
493
  }
494
494
  });
495
495
  }
@@ -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/lib/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/lib/devTools.js CHANGED
@@ -4,6 +4,10 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  // From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis
6
6
  function getGlobal() {
7
+ if (typeof globalThis !== 'undefined') {
8
+ return globalThis;
9
+ }
10
+
7
11
  if (typeof self !== 'undefined') {
8
12
  return self;
9
13
  }
package/lib/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/lib/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