xstate 4.26.0-pr2674-20219515814 → 4.26.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/CHANGELOG.md +37 -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 +10 -12
  8. package/es/State.js +1 -1
  9. package/es/StateNode.d.ts +14 -15
  10. package/es/StateNode.js +39 -39
  11. package/es/_virtual/_tslib.js +8 -4
  12. package/es/actions.d.ts +5 -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 +19 -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 +46 -60
  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 +10 -12
  34. package/lib/State.js +1 -1
  35. package/lib/StateNode.d.ts +14 -15
  36. package/lib/StateNode.js +38 -38
  37. package/lib/_virtual/_tslib.js +8 -4
  38. package/lib/actions.d.ts +5 -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 +19 -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 +46 -60
  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
package/lib/Machine.d.ts CHANGED
@@ -1,13 +1,12 @@
1
1
  import { Model } from './model.types';
2
- import { AnyEventObject, BaseActionObject, DefaultContext, EventObject, MachineConfig, MachineOptions, StateMachine, StateSchema, Typestate } from './types';
3
- import { MaybeTypegenMachineOptions, TypegenConstraint, TypegenDisabled, ResolveTypegenMeta } from './typegenTypes';
2
+ import { AnyEventObject, DefaultContext, EventObject, MachineConfig, MachineOptions, StateMachine, StateSchema, Typestate } from './types';
4
3
  /**
5
4
  * @deprecated Use `createMachine(...)` instead.
6
5
  */
7
- export declare function Machine<TContext = any, TEvent extends EventObject = AnyEventObject>(config: MachineConfig<TContext, any, TEvent>, options?: MachineOptions<TContext, TEvent>, initialContext?: TContext): StateMachine<TContext, any, TEvent>;
8
- export declare function Machine<TContext = DefaultContext, TStateSchema extends StateSchema = any, TEvent extends EventObject = AnyEventObject>(config: MachineConfig<TContext, TStateSchema, TEvent>, options?: MachineOptions<TContext, TEvent>, initialContext?: TContext): StateMachine<TContext, TStateSchema, TEvent>;
6
+ export declare function Machine<TContext = any, TEvent extends EventObject = AnyEventObject>(config: MachineConfig<TContext, any, TEvent>, options?: Partial<MachineOptions<TContext, TEvent>>, initialContext?: TContext): StateMachine<TContext, any, TEvent>;
7
+ export declare function Machine<TContext = DefaultContext, TStateSchema extends StateSchema = any, TEvent extends EventObject = AnyEventObject>(config: MachineConfig<TContext, TStateSchema, TEvent>, options?: Partial<MachineOptions<TContext, TEvent>>, initialContext?: TContext): StateMachine<TContext, TStateSchema, TEvent>;
9
8
  export declare function createMachine<TContext, TEvent extends EventObject = AnyEventObject, TTypestate extends Typestate<TContext> = {
10
9
  value: any;
11
10
  context: TContext;
12
- }, TTypesMeta extends TypegenConstraint = TypegenDisabled, TResolvedTypesMeta = ResolveTypegenMeta<TTypesMeta, TEvent, BaseActionObject>>(config: TContext extends Model<any, any, any, any> ? 'Model type no longer supported as generic type. Please use `model.createMachine(...)` instead.' : MachineConfig<TContext, any, TEvent, BaseActionObject, TTypesMeta>, options?: MaybeTypegenMachineOptions<TContext, TEvent, BaseActionObject, TResolvedTypesMeta>): StateMachine<TContext, any, TEvent, any, BaseActionObject, TResolvedTypesMeta>;
11
+ }>(config: TContext extends Model<any, any, any, any> ? 'Model type no longer supported as generic type. Please use `model.createMachine(...)` instead.' : MachineConfig<TContext, any, TEvent>, options?: Partial<MachineOptions<TContext, TEvent>>): StateMachine<TContext, any, TEvent, TTypestate>;
13
12
  //# sourceMappingURL=Machine.d.ts.map
@@ -15,10 +15,14 @@ var __read = (this && this.__read) || function (o, n) {
15
15
  }
16
16
  return ar;
17
17
  };
18
- var __spreadArray = (this && this.__spreadArray) || function (to, from) {
19
- for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
20
- to[j] = from[i];
21
- return to;
18
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
19
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
20
+ if (ar || !(i in from)) {
21
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
22
+ ar[i] = from[i];
23
+ }
24
+ }
25
+ return to.concat(ar || Array.prototype.slice.call(from));
22
26
  };
23
27
  Object.defineProperty(exports, "__esModule", { value: true });
24
28
  exports.SimulatedClock = void 0;
@@ -55,7 +59,7 @@ var SimulatedClock = /** @class */ (function () {
55
59
  };
56
60
  SimulatedClock.prototype.flushTimeouts = function () {
57
61
  var _this = this;
58
- __spreadArray([], __read(this.timeouts)).sort(function (_a, _b) {
62
+ __spreadArray([], __read(this.timeouts), false).sort(function (_a, _b) {
59
63
  var _c = __read(_a, 2), _idA = _c[0], timeoutA = _c[1];
60
64
  var _d = __read(_b, 2), _idB = _d[0], timeoutB = _d[1];
61
65
  var endA = timeoutA.start + timeoutA.timeout;
package/lib/State.d.ts CHANGED
@@ -1,21 +1,19 @@
1
1
  import { StateValue, ActivityMap, EventObject, HistoryValue, ActionObject, EventType, StateConfig, SCXML, StateSchema, TransitionDefinition, Typestate, ActorRef, StateMachine, SimpleEventsOf } from './types';
2
2
  import { StateNode } from './StateNode';
3
- import { TypegenDisabled, TypegenEnabled } from './typegenTypes';
4
- import { BaseActionObject, Prop } from './types';
5
3
  export declare function stateValuesEqual(a: StateValue | undefined, b: StateValue | undefined): boolean;
6
4
  export declare function isState<TContext, TEvent extends EventObject, TStateSchema extends StateSchema<TContext> = any, TTypestate extends Typestate<TContext> = {
7
5
  value: any;
8
6
  context: TContext;
9
- }, TResolvedTypesMeta = TypegenDisabled>(state: object | string): state is State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>;
10
- export declare function bindActionToState<TC, TE extends EventObject>(action: ActionObject<TC, TE>, state: State<TC, TE, any, any, any>): ActionObject<TC, TE>;
7
+ }>(state: object | string): state is State<TContext, TEvent, TStateSchema, TTypestate>;
8
+ export declare function bindActionToState<TC, TE extends EventObject>(action: ActionObject<TC, TE>, state: State<TC, TE, any, any>): ActionObject<TC, TE>;
11
9
  export declare class State<TContext, TEvent extends EventObject = EventObject, TStateSchema extends StateSchema<TContext> = any, TTypestate extends Typestate<TContext> = {
12
10
  value: any;
13
11
  context: TContext;
14
- }, TResolvedTypesMeta = TypegenDisabled> {
12
+ }> {
15
13
  value: StateValue;
16
14
  context: TContext;
17
15
  historyValue?: HistoryValue | undefined;
18
- history?: State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>;
16
+ history?: State<TContext, TEvent, TStateSchema, TTypestate>;
19
17
  actions: Array<ActionObject<TContext, TEvent>>;
20
18
  activities: ActivityMap;
21
19
  meta: any;
@@ -53,13 +51,13 @@ export declare class State<TContext, TEvent extends EventObject = EventObject, T
53
51
  */
54
52
  children: Record<string, ActorRef<any>>;
55
53
  tags: Set<string>;
56
- machine: StateMachine<TContext, any, TEvent, TTypestate, BaseActionObject, TResolvedTypesMeta> | undefined;
54
+ machine: StateMachine<TContext, any, TEvent, TTypestate> | undefined;
57
55
  /**
58
56
  * Creates a new State instance for the given `stateValue` and `context`.
59
57
  * @param stateValue
60
58
  * @param context
61
59
  */
62
- static from<TC, TE extends EventObject = EventObject>(stateValue: State<TC, TE, any, any, any> | StateValue, context?: TC | undefined): State<TC, TE, any, any, any>;
60
+ static from<TC, TE extends EventObject = EventObject>(stateValue: State<TC, TE, any, any> | StateValue, context?: TC | undefined): State<TC, TE, any, any>;
63
61
  /**
64
62
  * Creates a new State instance for the given `config`.
65
63
  * @param config The state config
@@ -90,24 +88,24 @@ export declare class State<TContext, TEvent extends EventObject = EventObject, T
90
88
  * @param delimiter The character(s) that separate each subpath in the string state node path.
91
89
  */
92
90
  toStrings(stateValue?: StateValue, delimiter?: string): string[];
93
- toJSON(): Omit<this, "configuration" | "transitions" | "tags" | "machine"> & {
91
+ toJSON(): Omit<this, "machine" | "tags" | "transitions" | "configuration"> & {
94
92
  tags: string[];
95
93
  };
96
94
  /**
97
95
  * Whether the current state value is a subset of the given parent state value.
98
96
  * @param parentStateValue
99
97
  */
100
- matches<TSV extends TTypestate['value']>(parentStateValue: TResolvedTypesMeta extends TypegenEnabled ? Prop<TResolvedTypesMeta, 'matchesStates'> : TSV): this is State<(TTypestate extends any ? {
98
+ matches<TSV extends TTypestate['value']>(parentStateValue: TSV): this is State<(TTypestate extends any ? {
101
99
  value: TSV;
102
100
  context: any;
103
- } extends TTypestate ? TTypestate : never : never)['context'], TEvent, TStateSchema, TTypestate, TResolvedTypesMeta> & {
101
+ } extends TTypestate ? TTypestate : never : never)['context'], TEvent, TStateSchema, TTypestate> & {
104
102
  value: TSV;
105
103
  };
106
104
  /**
107
105
  * Whether the current state configuration has a state node with the specified `tag`.
108
106
  * @param tag
109
107
  */
110
- hasTag(tag: TResolvedTypesMeta extends TypegenEnabled ? Prop<TResolvedTypesMeta, 'tags'> : string): boolean;
108
+ hasTag(tag: string): boolean;
111
109
  /**
112
110
  * Determines whether sending the `event` will cause a transition.
113
111
  * @param event The event to test
package/lib/State.js CHANGED
@@ -215,7 +215,7 @@ function () {
215
215
  return _this.toStrings(stateValue[key], delimiter).map(function (s) {
216
216
  return key + delimiter + s;
217
217
  });
218
- }))));
218
+ })), false));
219
219
  };
220
220
 
221
221
  State.prototype.toJSON = function () {
@@ -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, 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,7 +177,7 @@ 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;
@@ -198,25 +197,25 @@ declare class StateNode<TContext = any, TStateSchema extends StateSchema = any,
198
197
  * @param event The event that was sent at the current state
199
198
  * @param context The current context (extended state) of the current state
200
199
  */
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>;
200
+ transition(state: StateValue | State<TContext, TEvent, any, TTypestate> | undefined, event: Event<TEvent> | SCXML.Event<TEvent>, context?: TContext): State<TContext, TEvent, TStateSchema, TTypestate>;
202
201
  private resolveRaisedTransition;
203
202
  private resolveTransition;
204
203
  /**
205
204
  * Returns the child state node from its relative `stateKey`, or throws.
206
205
  */
207
- getStateNode(stateKey: string): StateNode<TContext, any, TEvent, TTypestate, TResolvedTypesMeta>;
206
+ getStateNode(stateKey: string): StateNode<TContext, any, TEvent, TTypestate>;
208
207
  /**
209
208
  * Returns the state node with the given `stateId`, or throws.
210
209
  *
211
210
  * @param stateId The state ID. The prefix "#" is removed.
212
211
  */
213
- getStateNodeById(stateId: string): StateNode<TContext, any, TEvent, any, TResolvedTypesMeta>;
212
+ getStateNodeById(stateId: string): StateNode<TContext, any, TEvent, any>;
214
213
  /**
215
214
  * Returns the relative state node from the given `statePath`, or throws.
216
215
  *
217
216
  * @param statePath The string or string array relative path to the state node.
218
217
  */
219
- getStateNodeByPath(statePath: string | string[]): StateNode<TContext, any, TEvent, any, any>;
218
+ getStateNodeByPath(statePath: string | string[]): StateNode<TContext, any, TEvent, any>;
220
219
  /**
221
220
  * Resolves a partial state value with its full representation in this machine.
222
221
  *
@@ -225,12 +224,12 @@ declare class StateNode<TContext = any, TStateSchema extends StateSchema = any,
225
224
  resolve(stateValue: StateValue): StateValue;
226
225
  private getResolvedPath;
227
226
  private get initialStateValue();
228
- getInitialState(stateValue: StateValue, context?: TContext): State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>;
227
+ getInitialState(stateValue: StateValue, context?: TContext): State<TContext, TEvent, TStateSchema, TTypestate>;
229
228
  /**
230
229
  * The initial State instance, which includes all actions to be executed from
231
230
  * entering the initial state.
232
231
  */
233
- get initialState(): State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>;
232
+ get initialState(): State<TContext, TEvent, TStateSchema, TTypestate>;
234
233
  /**
235
234
  * The target state value of the history state node, if it exists. This represents the
236
235
  * default state value to transition to if no history value exists yet.
@@ -244,14 +243,14 @@ declare class StateNode<TContext = any, TStateSchema extends StateSchema = any,
244
243
  * @param resolve Whether state nodes should resolve to initial child state nodes
245
244
  */
246
245
  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>>;
246
+ get initialStateNodes(): Array<StateNode<TContext, any, TEvent, any>>;
248
247
  /**
249
248
  * Retrieves state nodes from a relative path to this state node.
250
249
  *
251
250
  * @param relativePath The relative path from this state node
252
251
  * @param historyValue
253
252
  */
254
- getFromRelativePath(relativePath: string[]): Array<StateNode<TContext, any, TEvent, any, any>>;
253
+ getFromRelativePath(relativePath: string[]): Array<StateNode<TContext, any, TEvent, any>>;
255
254
  private historyValue;
256
255
  /**
257
256
  * 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, {
@@ -447,7 +448,8 @@ function () {
447
448
  return new State.State(_tslib.__assign(_tslib.__assign({}, state), {
448
449
  value: this.resolve(state.value),
449
450
  configuration: configuration,
450
- done: stateUtils.isInFinalState(configuration, this)
451
+ done: stateUtils.isInFinalState(configuration, this),
452
+ tags: stateUtils.getTagsFromConfiguration(configuration)
451
453
  }));
452
454
  };
453
455
 
@@ -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
  }
@@ -771,11 +773,11 @@ function () {
771
773
  var _c = _tslib.__read([utils.flatten(Array.from(entryStates).map(function (stateNode) {
772
774
  return _tslib.__spreadArray(_tslib.__spreadArray([], _tslib.__read(stateNode.activities.map(function (activity) {
773
775
  return actions.start(activity);
774
- }))), _tslib.__read(stateNode.onEntry));
776
+ })), false), _tslib.__read(stateNode.onEntry), false);
775
777
  })).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) {
778
+ return _tslib.__spreadArray(_tslib.__spreadArray([], _tslib.__read(stateNode.onExit), false), _tslib.__read(stateNode.activities.map(function (activity) {
777
779
  return actions.stop(activity);
778
- })));
780
+ })), false);
779
781
  }))], 2),
780
782
  entryActions = _c[0],
781
783
  exitActions = _c[1];
@@ -810,12 +812,12 @@ function () {
810
812
  }
811
813
 
812
814
  if (!environment.IS_PRODUCTION && _event.name === WILDCARD) {
813
- throw new Error("An event cannot have the wildcard type ('" + WILDCARD + "')");
815
+ throw new Error("An event cannot have the wildcard type ('".concat(WILDCARD, "')"));
814
816
  }
815
817
 
816
818
  if (this.strict) {
817
819
  if (!this.events.includes(_event.name) && !utils.isBuiltInEvent(_event.name)) {
818
- throw new Error("Machine '" + this.id + "' does not accept event '" + _event.name + "'");
820
+ throw new Error("Machine '".concat(this.id, "' does not accept event '").concat(_event.name, "'"));
819
821
  }
820
822
  }
821
823
 
@@ -829,7 +831,7 @@ function () {
829
831
  };
830
832
  var prevConfig = stateUtils.getConfiguration([], this.getStateNodes(currentState.value));
831
833
  var resolvedConfig = stateTransition.configuration.length ? stateUtils.getConfiguration(prevConfig, stateTransition.configuration) : prevConfig;
832
- stateTransition.configuration = _tslib.__spreadArray([], _tslib.__read(resolvedConfig));
834
+ stateTransition.configuration = _tslib.__spreadArray([], _tslib.__read(resolvedConfig), false);
833
835
  return this.resolveTransition(stateTransition, currentState, _event);
834
836
  };
835
837
 
@@ -843,7 +845,7 @@ function () {
843
845
  state._event = originalEvent;
844
846
  state.event = originalEvent.data;
845
847
 
846
- (_a = state.actions).unshift.apply(_a, _tslib.__spreadArray([], _tslib.__read(currentActions)));
848
+ (_a = state.actions).unshift.apply(_a, _tslib.__spreadArray([], _tslib.__read(currentActions), false));
847
849
 
848
850
  return state;
849
851
  };
@@ -980,9 +982,7 @@ function () {
980
982
  maybeNextState.changed = changed; // Preserve original history after raised events
981
983
 
982
984
  maybeNextState.history = history;
983
- maybeNextState.tags = new Set(utils.flatten(maybeNextState.configuration.map(function (sn) {
984
- return sn.tags;
985
- })));
985
+ maybeNextState.tags = stateUtils.getTagsFromConfiguration(maybeNextState.configuration);
986
986
  return maybeNextState;
987
987
  };
988
988
  /**
@@ -996,13 +996,13 @@ function () {
996
996
  }
997
997
 
998
998
  if (!this.states) {
999
- throw new Error("Unable to retrieve child state '" + stateKey + "' from '" + this.id + "'; no child states exist.");
999
+ throw new Error("Unable to retrieve child state '".concat(stateKey, "' from '").concat(this.id, "'; no child states exist."));
1000
1000
  }
1001
1001
 
1002
1002
  var result = this.states[stateKey];
1003
1003
 
1004
1004
  if (!result) {
1005
- throw new Error("Child state '" + stateKey + "' does not exist on '" + this.id + "'");
1005
+ throw new Error("Child state '".concat(stateKey, "' does not exist on '").concat(this.id, "'"));
1006
1006
  }
1007
1007
 
1008
1008
  return result;
@@ -1024,7 +1024,7 @@ function () {
1024
1024
  var stateNode = this.machine.idMap[resolvedStateId];
1025
1025
 
1026
1026
  if (!stateNode) {
1027
- throw new Error("Child state node '#" + resolvedStateId + "' does not exist on machine '" + this.id + "'");
1027
+ throw new Error("Child state node '#".concat(resolvedStateId, "' does not exist on machine '").concat(this.id, "'"));
1028
1028
  }
1029
1029
 
1030
1030
  return stateNode;
@@ -1111,7 +1111,7 @@ function () {
1111
1111
  var stateNode = this.machine.idMap[stateIdentifier.slice(STATE_IDENTIFIER.length)];
1112
1112
 
1113
1113
  if (!stateNode) {
1114
- throw new Error("Unable to find state node '" + stateIdentifier + "'");
1114
+ throw new Error("Unable to find state node '".concat(stateIdentifier, "'"));
1115
1115
  }
1116
1116
 
1117
1117
  return stateNode.path;
@@ -1138,7 +1138,7 @@ function () {
1138
1138
  });
1139
1139
  } else if (this.initial !== undefined) {
1140
1140
  if (!this.states[this.initial]) {
1141
- throw new Error("Initial state '" + this.initial + "' not found on '" + this.key + "'");
1141
+ throw new Error("Initial state '".concat(this.initial, "' not found on '").concat(this.key, "'"));
1142
1142
  }
1143
1143
 
1144
1144
  initialStateValue = stateUtils.isLeafNode(this.states[this.initial]) ? this.initial : (_a = {}, _a[this.initial] = this.states[this.initial].initialStateValue, _a);
@@ -1178,7 +1178,7 @@ function () {
1178
1178
  var initialStateValue = this.initialStateValue;
1179
1179
 
1180
1180
  if (!initialStateValue) {
1181
- throw new Error("Cannot retrieve initial state from simple state '" + this.id + "'.");
1181
+ throw new Error("Cannot retrieve initial state from simple state '".concat(this.id, "'."));
1182
1182
  }
1183
1183
 
1184
1184
  return this.getInitialState(initialStateValue);
@@ -1236,7 +1236,7 @@ function () {
1236
1236
 
1237
1237
  if (this.type === 'compound' && !this.initial) {
1238
1238
  if (!environment.IS_PRODUCTION) {
1239
- utils.warn(false, "Compound state node '" + this.id + "' has no initial state.");
1239
+ utils.warn(false, "Compound state node '".concat(this.id, "' has no initial state."));
1240
1240
  }
1241
1241
 
1242
1242
  return [this];
@@ -1267,7 +1267,7 @@ function () {
1267
1267
  childStatePath = _a.slice(1);
1268
1268
 
1269
1269
  if (!this.states) {
1270
- throw new Error("Cannot retrieve subPath '" + stateKey + "' from node with no states");
1270
+ throw new Error("Cannot retrieve subPath '".concat(stateKey, "' from node with no states"));
1271
1271
  }
1272
1272
 
1273
1273
  var childStateNode = this.getStateNode(stateKey);
@@ -1277,7 +1277,7 @@ function () {
1277
1277
  }
1278
1278
 
1279
1279
  if (!this.states[stateKey]) {
1280
- throw new Error("Child state '" + stateKey + "' does not exist on '" + this.id + "'");
1280
+ throw new Error("Child state '".concat(stateKey, "' does not exist on '").concat(this.id, "'"));
1281
1281
  }
1282
1282
 
1283
1283
  return this.states[stateKey].getFromRelativePath(childStatePath);
@@ -1376,7 +1376,7 @@ function () {
1376
1376
  try {
1377
1377
  for (var _e = (e_8 = void 0, _tslib.__values(state.events)), _f = _e.next(); !_f.done; _f = _e.next()) {
1378
1378
  var event_1 = _f.value;
1379
- events.add("" + event_1);
1379
+ events.add("".concat(event_1));
1380
1380
  }
1381
1381
  } catch (e_8_1) {
1382
1382
  e_8 = {
@@ -1455,7 +1455,7 @@ function () {
1455
1455
 
1456
1456
  return targetStateNode;
1457
1457
  } catch (err) {
1458
- throw new Error("Invalid transition definition for state node '" + _this.id + "':\n" + err.message);
1458
+ throw new Error("Invalid transition definition for state node '".concat(_this.id, "':\n").concat(err.message));
1459
1459
  }
1460
1460
  } else {
1461
1461
  return _this.getStateNodeByPath(resolvedTarget);
@@ -1483,9 +1483,9 @@ function () {
1483
1483
  toJSON: function () {
1484
1484
  return _tslib.__assign(_tslib.__assign({}, transition), {
1485
1485
  target: transition.target ? transition.target.map(function (t) {
1486
- return "#" + t.id;
1486
+ return "#".concat(t.id);
1487
1487
  }) : undefined,
1488
- source: "#" + _this.id
1488
+ source: "#".concat(_this.id)
1489
1489
  });
1490
1490
  }
1491
1491
  });
@@ -1513,7 +1513,7 @@ function () {
1513
1513
 
1514
1514
  onConfig = utils.flatten(utils.keys(strictTransitionConfigs_1).map(function (key) {
1515
1515
  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 + "\"."));
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 \"#".concat(_this.id, "\"."));
1517
1517
  }
1518
1518
 
1519
1519
  var transitionConfigArray = utils.toTransitionConfigArray(key, strictTransitionConfigs_1[key]);
@@ -1530,24 +1530,24 @@ function () {
1530
1530
  var doneConfig = this.config.onDone ? utils.toTransitionConfigArray(String(actions.done(this.id)), this.config.onDone) : [];
1531
1531
 
1532
1532
  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 + "\".");
1533
+ utils.warn(!(this.config.onDone && !this.parent), "Root nodes cannot have an \".onDone\" transition. Please check the config of \"".concat(this.id, "\"."));
1534
1534
  }
1535
1535
 
1536
1536
  var invokeConfig = utils.flatten(this.invoke.map(function (invokeDef) {
1537
1537
  var settleTransitions = [];
1538
1538
 
1539
1539
  if (invokeDef.onDone) {
1540
- settleTransitions.push.apply(settleTransitions, _tslib.__spreadArray([], _tslib.__read(utils.toTransitionConfigArray(String(actions.doneInvoke(invokeDef.id)), invokeDef.onDone))));
1540
+ settleTransitions.push.apply(settleTransitions, _tslib.__spreadArray([], _tslib.__read(utils.toTransitionConfigArray(String(actions.doneInvoke(invokeDef.id)), invokeDef.onDone)), false));
1541
1541
  }
1542
1542
 
1543
1543
  if (invokeDef.onError) {
1544
- settleTransitions.push.apply(settleTransitions, _tslib.__spreadArray([], _tslib.__read(utils.toTransitionConfigArray(String(actions.error(invokeDef.id)), invokeDef.onError))));
1544
+ settleTransitions.push.apply(settleTransitions, _tslib.__spreadArray([], _tslib.__read(utils.toTransitionConfigArray(String(actions.error(invokeDef.id)), invokeDef.onError)), false));
1545
1545
  }
1546
1546
 
1547
1547
  return settleTransitions;
1548
1548
  }));
1549
1549
  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) {
1550
+ 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
1551
  return utils.toArray(transitionConfig).map(function (transition) {
1552
1552
  return _this.formatTransition(transition);
1553
1553
  });
@@ -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 } from './types';
2
2
  import * as actionTypes from './actionTypes';
3
3
  import { State } from './State';
4
4
  import { StateNode } from './StateNode';
5
+ import { 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
@@ -133,6 +134,6 @@ export declare function forwardTo<TContext, TEvent extends EventObject>(target:
133
134
  * @param options Options to pass into the send action creator.
134
135
  */
135
136
  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];
137
+ export declare function choose<TContext, TEvent extends EventObject>(conds: Array<ChooseCondition<TContext, TEvent>>): ChooseAction<TContext, TEvent>;
138
+ 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
139
  //# 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
  }