xstate 4.20.1 → 4.23.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 (92) hide show
  1. package/CHANGELOG.md +134 -0
  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.js +17 -5
  6. package/es/Machine.d.ts +6 -3
  7. package/es/Machine.js +3 -6
  8. package/es/State.js +1 -3
  9. package/es/StateNode.d.ts +4 -3
  10. package/es/StateNode.js +34 -20
  11. package/es/_virtual/_tslib.js +59 -73
  12. package/es/actionTypes.js +3 -2
  13. package/es/actions.d.ts +1 -1
  14. package/es/actions.js +51 -37
  15. package/es/behaviors.d.ts +37 -0
  16. package/es/behaviors.js +65 -0
  17. package/es/constants.js +2 -1
  18. package/es/devTools.js +1 -1
  19. package/es/environment.js +2 -1
  20. package/es/index.js +3 -1
  21. package/es/interpreter.d.ts +10 -3
  22. package/es/interpreter.js +44 -22
  23. package/es/invokeUtils.js +4 -3
  24. package/es/mapState.js +1 -1
  25. package/es/match.js +1 -1
  26. package/es/model.d.ts +2 -36
  27. package/es/model.types.d.ts +37 -0
  28. package/es/registry.js +2 -1
  29. package/es/scheduler.js +2 -1
  30. package/es/schema.js +1 -1
  31. package/es/serviceScope.js +1 -3
  32. package/es/stateUtils.js +1 -9
  33. package/es/types.d.ts +26 -5
  34. package/es/types.js +1 -1
  35. package/es/utils.d.ts +3 -2
  36. package/es/utils.js +4 -40
  37. package/lib/Actor.d.ts +25 -25
  38. package/lib/Actor.js +85 -66
  39. package/lib/Machine.d.ts +17 -14
  40. package/lib/Machine.js +14 -14
  41. package/lib/SimulatedClock.d.ts +16 -16
  42. package/lib/State.d.ts +108 -108
  43. package/lib/State.js +246 -236
  44. package/lib/StateNode.d.ts +279 -278
  45. package/lib/StateNode.js +1535 -1339
  46. package/lib/_virtual/_tslib.js +81 -0
  47. package/lib/actionTypes.d.ts +19 -19
  48. package/lib/actionTypes.js +43 -23
  49. package/lib/actions.d.ts +138 -138
  50. package/lib/actions.js +465 -387
  51. package/lib/behaviors.d.ts +37 -0
  52. package/lib/behaviors.js +69 -0
  53. package/lib/constants.d.ts +5 -5
  54. package/lib/constants.js +13 -7
  55. package/lib/devTools.d.ts +15 -15
  56. package/lib/devTools.js +37 -26
  57. package/lib/each.d.ts +3 -3
  58. package/lib/environment.d.ts +1 -1
  59. package/lib/environment.js +7 -4
  60. package/lib/index.d.ts +30 -30
  61. package/lib/index.js +67 -57
  62. package/lib/interpreter.d.ts +205 -198
  63. package/lib/interpreter.js +1306 -1054
  64. package/lib/invoke.d.ts +10 -10
  65. package/lib/invokeUtils.d.ts +6 -6
  66. package/lib/invokeUtils.js +40 -37
  67. package/lib/json.d.ts +30 -30
  68. package/lib/mapState.d.ts +3 -3
  69. package/lib/mapState.js +31 -32
  70. package/lib/match.d.ts +8 -8
  71. package/lib/match.js +33 -47
  72. package/lib/model.d.ts +4 -38
  73. package/lib/model.js +5 -1
  74. package/lib/model.types.d.ts +37 -0
  75. package/lib/model.types.js +2 -0
  76. package/lib/patterns.d.ts +13 -13
  77. package/lib/registry.d.ts +8 -8
  78. package/lib/registry.js +21 -18
  79. package/lib/scheduler.d.ts +16 -16
  80. package/lib/scheduler.js +79 -70
  81. package/lib/schema.d.ts +1 -1
  82. package/lib/schema.js +6 -4
  83. package/lib/scxml.d.ts +5 -5
  84. package/lib/serviceScope.d.ts +3 -3
  85. package/lib/serviceScope.js +16 -12
  86. package/lib/stateUtils.d.ts +14 -14
  87. package/lib/stateUtils.js +231 -199
  88. package/lib/types.d.ts +928 -907
  89. package/lib/types.js +29 -29
  90. package/lib/utils.d.ts +68 -67
  91. package/lib/utils.js +530 -529
  92. package/package.json +6 -6
package/lib/StateNode.js CHANGED
@@ -1,1380 +1,1576 @@
1
- "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- var __rest = (this && this.__rest) || function (s, e) {
14
- var t = {};
15
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
16
- t[p] = s[p];
17
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
18
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
19
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
20
- t[p[i]] = s[p[i]];
21
- }
22
- return t;
23
- };
24
- var __read = (this && this.__read) || function (o, n) {
25
- var m = typeof Symbol === "function" && o[Symbol.iterator];
26
- if (!m) return o;
27
- var i = m.call(o), r, ar = [], e;
28
- try {
29
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
30
- }
31
- catch (error) { e = { error: error }; }
32
- finally {
33
- try {
34
- if (r && !r.done && (m = i["return"])) m.call(i);
35
- }
36
- finally { if (e) throw e.error; }
37
- }
38
- return ar;
39
- };
40
- var __spreadArray = (this && this.__spreadArray) || function (to, from) {
41
- for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
42
- to[j] = from[i];
43
- return to;
44
- };
45
- var __values = (this && this.__values) || function(o) {
46
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
47
- if (m) return m.call(o);
48
- if (o && typeof o.length === "number") return {
49
- next: function () {
50
- if (o && i >= o.length) o = void 0;
51
- return { value: o && o[i++], done: !o };
52
- }
53
- };
54
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
55
- };
56
- Object.defineProperty(exports, "__esModule", { value: true });
57
- exports.StateNode = void 0;
58
- var utils_1 = require("./utils");
59
- var types_1 = require("./types");
60
- var utils_2 = require("./utils");
61
- var State_1 = require("./State");
62
- var actionTypes = require("./actionTypes");
63
- var actions_1 = require("./actions");
64
- var environment_1 = require("./environment");
65
- var constants_1 = require("./constants");
66
- var stateUtils_1 = require("./stateUtils");
67
- var Actor_1 = require("./Actor");
68
- var invokeUtils_1 = require("./invokeUtils");
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var _tslib = require('./_virtual/_tslib.js');
6
+ var constants = require('./constants.js');
7
+ var environment = require('./environment.js');
8
+ var utils = require('./utils.js');
9
+ var types = require('./types.js');
10
+ var stateUtils = require('./stateUtils.js');
11
+ var actionTypes = require('./actionTypes.js');
12
+ var actions = require('./actions.js');
13
+ var State = require('./State.js');
14
+ var Actor = require('./Actor.js');
15
+ var invokeUtils = require('./invokeUtils.js');
16
+
69
17
  var NULL_EVENT = '';
70
18
  var STATE_IDENTIFIER = '#';
71
19
  var WILDCARD = '*';
72
20
  var EMPTY_OBJECT = {};
73
- var isStateId = function (str) { return str[0] === STATE_IDENTIFIER; };
74
- var createDefaultOptions = function () { return ({
21
+
22
+ var isStateId = function (str) {
23
+ return str[0] === STATE_IDENTIFIER;
24
+ };
25
+
26
+ var createDefaultOptions = function () {
27
+ return {
75
28
  actions: {},
76
29
  guards: {},
77
30
  services: {},
78
31
  activities: {},
79
32
  delays: {}
80
- }); };
33
+ };
34
+ };
35
+
81
36
  var validateArrayifiedTransitions = function (stateNode, event, transitions) {
82
- var hasNonLastUnguardedTarget = transitions
83
- .slice(0, -1)
84
- .some(function (transition) {
85
- return !('cond' in transition) &&
86
- !('in' in transition) &&
87
- (utils_1.isString(transition.target) || utils_1.isMachine(transition.target));
88
- });
89
- var eventText = event === NULL_EVENT ? 'the transient event' : "event '" + event + "'";
90
- utils_1.warn(!hasNonLastUnguardedTarget, "One or more transitions for " + eventText + " on state '" + stateNode.id + "' are unreachable. " +
91
- "Make sure that the default transition is the last one defined.");
37
+ var hasNonLastUnguardedTarget = transitions.slice(0, -1).some(function (transition) {
38
+ return !('cond' in transition) && !('in' in transition) && (utils.isString(transition.target) || utils.isMachine(transition.target));
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.");
92
42
  };
93
- var StateNode = /** @class */ (function () {
94
- function StateNode(
95
- /**
96
- * The raw config used to create the machine.
97
- */
98
- config, options,
99
- /**
100
- * The initial extended state
43
+
44
+ var StateNode =
45
+ /*#__PURE__*/
46
+
47
+ /** @class */
48
+ function () {
49
+ function StateNode(
50
+ /**
51
+ * The raw config used to create the machine.
52
+ */
53
+ config, options,
54
+ /**
55
+ * The initial extended state
56
+ */
57
+ _context // TODO: this is unsafe, but we're removing it in v5 anyway
58
+ ) {
59
+ var _this = this;
60
+
61
+ if (_context === void 0) {
62
+ _context = config.context;
63
+ }
64
+
65
+ var _a;
66
+
67
+ this.config = config;
68
+ this._context = _context;
69
+ /**
70
+ * The order this state node appears. Corresponds to the implicit SCXML document order.
101
71
  */
102
- context // TODO: this is unsafe, but we're removing it in v5 anyway
103
- ) {
104
- var _this = this;
105
- if (context === void 0) { context = undefined; }
106
- var _a;
107
- this.config = config;
108
- this.context = context;
109
- /**
110
- * The order this state node appears. Corresponds to the implicit SCXML document order.
111
- */
112
- this.order = -1;
113
- this.__xstatenode = true;
114
- this.__cache = {
115
- events: undefined,
116
- relativeValue: new Map(),
117
- initialStateValue: undefined,
118
- initialState: undefined,
119
- on: undefined,
120
- transitions: undefined,
121
- candidates: {},
122
- delayedTransitions: undefined
72
+
73
+ this.order = -1;
74
+ this.__xstatenode = true;
75
+ this.__cache = {
76
+ events: undefined,
77
+ relativeValue: new Map(),
78
+ initialStateValue: undefined,
79
+ initialState: undefined,
80
+ on: undefined,
81
+ transitions: undefined,
82
+ candidates: {},
83
+ delayedTransitions: undefined
84
+ };
85
+ this.idMap = {};
86
+ this.tags = [];
87
+ this.options = Object.assign(createDefaultOptions(), options);
88
+ this.parent = this.options._parent;
89
+ this.key = this.config.key || this.options._key || this.config.id || '(machine)';
90
+ this.machine = this.parent ? this.parent.machine : this;
91
+ this.path = this.parent ? this.parent.path.concat(this.key) : [];
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);
94
+ this.version = this.parent ? this.parent.version : this.config.version;
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
+ this.schema = this.parent ? this.machine.schema : (_a = this.config.schema) !== null && _a !== void 0 ? _a : {};
97
+
98
+ if (!environment.IS_PRODUCTION) {
99
+ 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
+ }
101
+
102
+ this.initial = this.config.initial;
103
+ this.states = this.config.states ? utils.mapValues(this.config.states, function (stateConfig, key) {
104
+ var _a;
105
+
106
+ var stateNode = new StateNode(stateConfig, {
107
+ _parent: _this,
108
+ _key: key
109
+ });
110
+ Object.assign(_this.idMap, _tslib.__assign((_a = {}, _a[stateNode.id] = stateNode, _a), stateNode.idMap));
111
+ return stateNode;
112
+ }) : EMPTY_OBJECT; // Document order
113
+
114
+ var order = 0;
115
+
116
+ function dfs(stateNode) {
117
+ var e_1, _a;
118
+
119
+ stateNode.order = order++;
120
+
121
+ try {
122
+ for (var _b = _tslib.__values(stateUtils.getChildren(stateNode)), _c = _b.next(); !_c.done; _c = _b.next()) {
123
+ var child = _c.value;
124
+ dfs(child);
125
+ }
126
+ } catch (e_1_1) {
127
+ e_1 = {
128
+ error: e_1_1
123
129
  };
124
- this.idMap = {};
125
- this.tags = [];
126
- this.options = Object.assign(createDefaultOptions(), options);
127
- this.parent = this.options._parent;
128
- this.key =
129
- this.config.key || this.options._key || this.config.id || '(machine)';
130
- this.machine = this.parent ? this.parent.machine : this;
131
- this.path = this.parent ? this.parent.path.concat(this.key) : [];
132
- this.delimiter =
133
- this.config.delimiter ||
134
- (this.parent ? this.parent.delimiter : constants_1.STATE_DELIMITER);
135
- this.id =
136
- this.config.id || __spreadArray([this.machine.key], __read(this.path)).join(this.delimiter);
137
- this.version = this.parent
138
- ? this.parent.version
139
- : this.config.version;
140
- this.type =
141
- this.config.type ||
142
- (this.config.parallel
143
- ? 'parallel'
144
- : this.config.states && utils_1.keys(this.config.states).length
145
- ? 'compound'
146
- : this.config.history
147
- ? 'history'
148
- : 'atomic');
149
- this.schema = this.parent
150
- ? this.machine.schema
151
- : (_a = this.config.schema) !== null && _a !== void 0 ? _a : {};
152
- if (!environment_1.IS_PRODUCTION) {
153
- utils_1.warn(!('parallel' in this.config), "The \"parallel\" property is deprecated and will be removed in version 4.1. " + (this.config.parallel
154
- ? "Replace with `type: 'parallel'`"
155
- : "Use `type: '" + this.type + "'`") + " in the config for state node '" + this.id + "' instead.");
156
- }
157
- this.initial = this.config.initial;
158
- this.states = (this.config.states
159
- ? utils_1.mapValues(this.config.states, function (stateConfig, key) {
160
- var _a;
161
- var stateNode = new StateNode(stateConfig, {
162
- _parent: _this,
163
- _key: key
164
- });
165
- Object.assign(_this.idMap, __assign((_a = {}, _a[stateNode.id] = stateNode, _a), stateNode.idMap));
166
- return stateNode;
167
- })
168
- : EMPTY_OBJECT);
169
- // Document order
170
- var order = 0;
171
- function dfs(stateNode) {
172
- var e_1, _a;
173
- stateNode.order = order++;
174
- try {
175
- for (var _b = __values(stateUtils_1.getChildren(stateNode)), _c = _b.next(); !_c.done; _c = _b.next()) {
176
- var child = _c.value;
177
- dfs(child);
178
- }
179
- }
180
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
181
- finally {
182
- try {
183
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
184
- }
185
- finally { if (e_1) throw e_1.error; }
186
- }
130
+ } finally {
131
+ try {
132
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
133
+ } finally {
134
+ if (e_1) throw e_1.error;
187
135
  }
188
- dfs(this);
189
- // History config
190
- this.history =
191
- this.config.history === true ? 'shallow' : this.config.history || false;
192
- this._transient =
193
- !!this.config.always ||
194
- (!this.config.on
195
- ? false
196
- : Array.isArray(this.config.on)
197
- ? this.config.on.some(function (_a) {
198
- var event = _a.event;
199
- return event === NULL_EVENT;
200
- })
201
- : NULL_EVENT in this.config.on);
202
- this.strict = !!this.config.strict;
203
- // TODO: deprecate (entry)
204
- this.onEntry = utils_1.toArray(this.config.entry || this.config.onEntry).map(function (action) { return actions_1.toActionObject(action); });
205
- // TODO: deprecate (exit)
206
- this.onExit = utils_1.toArray(this.config.exit || this.config.onExit).map(function (action) { return actions_1.toActionObject(action); });
207
- this.meta = this.config.meta;
208
- this.doneData =
209
- this.type === 'final'
210
- ? this.config.data
211
- : undefined;
212
- this.invoke = utils_1.toArray(this.config.invoke).map(function (invokeConfig, i) {
213
- var _a, _b;
214
- if (utils_1.isMachine(invokeConfig)) {
215
- _this.machine.options.services = __assign((_a = {}, _a[invokeConfig.id] = invokeConfig, _a), _this.machine.options.services);
216
- return invokeUtils_1.toInvokeDefinition({
217
- src: invokeConfig.id,
218
- id: invokeConfig.id
219
- });
220
- }
221
- else if (utils_1.isString(invokeConfig.src)) {
222
- return invokeUtils_1.toInvokeDefinition(__assign(__assign({}, invokeConfig), { id: invokeConfig.id || invokeConfig.src, src: invokeConfig.src }));
223
- }
224
- else if (utils_1.isMachine(invokeConfig.src) || utils_1.isFunction(invokeConfig.src)) {
225
- var invokeSrc = _this.id + ":invocation[" + i + "]"; // TODO: util function
226
- _this.machine.options.services = __assign((_b = {}, _b[invokeSrc] = invokeConfig.src, _b), _this.machine.options.services);
227
- return invokeUtils_1.toInvokeDefinition(__assign(__assign({ id: invokeSrc }, invokeConfig), { src: invokeSrc }));
228
- }
229
- else {
230
- var invokeSource = invokeConfig.src;
231
- return invokeUtils_1.toInvokeDefinition(__assign(__assign({ id: invokeSource.type }, invokeConfig), { src: invokeSource }));
232
- }
233
- });
234
- this.activities = utils_1.toArray(this.config.activities)
235
- .concat(this.invoke)
236
- .map(function (activity) { return actions_1.toActivityDefinition(activity); });
237
- this.transition = this.transition.bind(this);
238
- this.tags = utils_1.toArray(this.config.tags);
239
- // TODO: this is the real fix for initialization once
240
- // state node getters are deprecated
241
- // if (!this.parent) {
242
- // this._init();
243
- // }
136
+ }
244
137
  }
245
- StateNode.prototype._init = function () {
246
- if (this.__cache.transitions) {
247
- return;
248
- }
249
- stateUtils_1.getAllStateNodes(this).forEach(function (stateNode) { return stateNode.on; });
250
- };
251
- /**
252
- * Clones this state machine with custom options and context.
253
- *
254
- * @param options Options (actions, guards, activities, services) to recursively merge with the existing options.
255
- * @param context Custom context (will override predefined context)
256
- */
257
- StateNode.prototype.withConfig = function (options, context) {
258
- if (context === void 0) { context = this.context; }
259
- var _a = this.options, actions = _a.actions, activities = _a.activities, guards = _a.guards, services = _a.services, delays = _a.delays;
260
- return new StateNode(this.config, {
261
- actions: __assign(__assign({}, actions), options.actions),
262
- activities: __assign(__assign({}, activities), options.activities),
263
- guards: __assign(__assign({}, guards), options.guards),
264
- services: __assign(__assign({}, services), options.services),
265
- delays: __assign(__assign({}, delays), options.delays)
266
- }, context);
267
- };
268
- /**
269
- * Clones this state machine with custom context.
270
- *
271
- * @param context Custom context (will override predefined context, not recursive)
272
- */
273
- StateNode.prototype.withContext = function (context) {
274
- return new StateNode(this.config, this.options, context);
275
- };
276
- Object.defineProperty(StateNode.prototype, "definition", {
277
- /**
278
- * The well-structured state node definition.
279
- */
280
- get: function () {
281
- return {
282
- id: this.id,
283
- key: this.key,
284
- version: this.version,
285
- context: this.context,
286
- type: this.type,
287
- initial: this.initial,
288
- history: this.history,
289
- states: utils_1.mapValues(this.states, function (state) { return state.definition; }),
290
- on: this.on,
291
- transitions: this.transitions,
292
- entry: this.onEntry,
293
- exit: this.onExit,
294
- activities: this.activities || [],
295
- meta: this.meta,
296
- order: this.order || -1,
297
- data: this.doneData,
298
- invoke: this.invoke
299
- };
300
- },
301
- enumerable: false,
302
- configurable: true
138
+
139
+ dfs(this); // History config
140
+
141
+ this.history = this.config.history === true ? 'shallow' : this.config.history || false;
142
+ this._transient = !!this.config.always || (!this.config.on ? false : Array.isArray(this.config.on) ? this.config.on.some(function (_a) {
143
+ var event = _a.event;
144
+ return event === NULL_EVENT;
145
+ }) : NULL_EVENT in this.config.on);
146
+ this.strict = !!this.config.strict; // TODO: deprecate (entry)
147
+
148
+ this.onEntry = utils.toArray(this.config.entry || this.config.onEntry).map(function (action) {
149
+ return actions.toActionObject(action);
150
+ }); // TODO: deprecate (exit)
151
+
152
+ this.onExit = utils.toArray(this.config.exit || this.config.onExit).map(function (action) {
153
+ return actions.toActionObject(action);
303
154
  });
304
- StateNode.prototype.toJSON = function () {
305
- return this.definition;
306
- };
307
- Object.defineProperty(StateNode.prototype, "on", {
308
- /**
309
- * The mapping of events to transitions.
310
- */
311
- get: function () {
312
- if (this.__cache.on) {
313
- return this.__cache.on;
314
- }
315
- var transitions = this.transitions;
316
- return (this.__cache.on = transitions.reduce(function (map, transition) {
317
- map[transition.eventType] = map[transition.eventType] || [];
318
- map[transition.eventType].push(transition);
319
- return map;
320
- }, {}));
321
- },
322
- enumerable: false,
323
- configurable: true
155
+ this.meta = this.config.meta;
156
+ this.doneData = this.type === 'final' ? this.config.data : undefined;
157
+ this.invoke = utils.toArray(this.config.invoke).map(function (invokeConfig, i) {
158
+ var _a, _b;
159
+
160
+ if (utils.isMachine(invokeConfig)) {
161
+ _this.machine.options.services = _tslib.__assign((_a = {}, _a[invokeConfig.id] = invokeConfig, _a), _this.machine.options.services);
162
+ return invokeUtils.toInvokeDefinition({
163
+ src: invokeConfig.id,
164
+ id: invokeConfig.id
165
+ });
166
+ } else if (utils.isString(invokeConfig.src)) {
167
+ return invokeUtils.toInvokeDefinition(_tslib.__assign(_tslib.__assign({}, invokeConfig), {
168
+ id: invokeConfig.id || invokeConfig.src,
169
+ src: invokeConfig.src
170
+ }));
171
+ } else if (utils.isMachine(invokeConfig.src) || utils.isFunction(invokeConfig.src)) {
172
+ var invokeSrc = _this.id + ":invocation[" + i + "]"; // TODO: util function
173
+
174
+ _this.machine.options.services = _tslib.__assign((_b = {}, _b[invokeSrc] = invokeConfig.src, _b), _this.machine.options.services);
175
+ return invokeUtils.toInvokeDefinition(_tslib.__assign(_tslib.__assign({
176
+ id: invokeSrc
177
+ }, invokeConfig), {
178
+ src: invokeSrc
179
+ }));
180
+ } else {
181
+ var invokeSource = invokeConfig.src;
182
+ return invokeUtils.toInvokeDefinition(_tslib.__assign(_tslib.__assign({
183
+ id: invokeSource.type
184
+ }, invokeConfig), {
185
+ src: invokeSource
186
+ }));
187
+ }
324
188
  });
325
- Object.defineProperty(StateNode.prototype, "after", {
326
- get: function () {
327
- return (this.__cache.delayedTransitions ||
328
- ((this.__cache.delayedTransitions = this.getDelayedTransitions()),
329
- this.__cache.delayedTransitions));
330
- },
331
- enumerable: false,
332
- configurable: true
189
+ this.activities = utils.toArray(this.config.activities).concat(this.invoke).map(function (activity) {
190
+ return actions.toActivityDefinition(activity);
333
191
  });
334
- Object.defineProperty(StateNode.prototype, "transitions", {
335
- /**
336
- * All the transitions that can be taken from this state node.
337
- */
338
- get: function () {
339
- return (this.__cache.transitions ||
340
- ((this.__cache.transitions = this.formatTransitions()),
341
- this.__cache.transitions));
342
- },
343
- enumerable: false,
344
- configurable: true
192
+ this.transition = this.transition.bind(this);
193
+ this.tags = utils.toArray(this.config.tags); // TODO: this is the real fix for initialization once
194
+ // state node getters are deprecated
195
+ // if (!this.parent) {
196
+ // this._init();
197
+ // }
198
+ }
199
+
200
+ StateNode.prototype._init = function () {
201
+ if (this.__cache.transitions) {
202
+ return;
203
+ }
204
+
205
+ stateUtils.getAllStateNodes(this).forEach(function (stateNode) {
206
+ return stateNode.on;
345
207
  });
346
- StateNode.prototype.getCandidates = function (eventName) {
347
- if (this.__cache.candidates[eventName]) {
348
- return this.__cache.candidates[eventName];
349
- }
350
- var transient = eventName === NULL_EVENT;
351
- var candidates = this.transitions.filter(function (transition) {
352
- var sameEventType = transition.eventType === eventName;
353
- // null events should only match against eventless transitions
354
- return transient
355
- ? sameEventType
356
- : sameEventType || transition.eventType === WILDCARD;
357
- });
358
- this.__cache.candidates[eventName] = candidates;
359
- return candidates;
360
- };
361
- /**
362
- * All delayed transitions from the config.
363
- */
364
- StateNode.prototype.getDelayedTransitions = function () {
365
- var _this = this;
366
- var afterConfig = this.config.after;
367
- if (!afterConfig) {
368
- return [];
369
- }
370
- var mutateEntryExit = function (delay, i) {
371
- var delayRef = utils_1.isFunction(delay) ? _this.id + ":delay[" + i + "]" : delay;
372
- var eventType = actions_1.after(delayRef, _this.id);
373
- _this.onEntry.push(actions_1.send(eventType, { delay: delay }));
374
- _this.onExit.push(actions_1.cancel(eventType));
375
- return eventType;
376
- };
377
- var delayedTransitions = utils_1.isArray(afterConfig)
378
- ? afterConfig.map(function (transition, i) {
379
- var eventType = mutateEntryExit(transition.delay, i);
380
- return __assign(__assign({}, transition), { event: eventType });
381
- })
382
- : utils_1.flatten(utils_1.keys(afterConfig).map(function (delay, i) {
383
- var configTransition = afterConfig[delay];
384
- var resolvedTransition = utils_1.isString(configTransition)
385
- ? { target: configTransition }
386
- : configTransition;
387
- var resolvedDelay = !isNaN(+delay) ? +delay : delay;
388
- var eventType = mutateEntryExit(resolvedDelay, i);
389
- return utils_1.toArray(resolvedTransition).map(function (transition) { return (__assign(__assign({}, transition), { event: eventType, delay: resolvedDelay })); });
390
- }));
391
- return delayedTransitions.map(function (delayedTransition) {
392
- var delay = delayedTransition.delay;
393
- return __assign(__assign({}, _this.formatTransition(delayedTransition)), { delay: delay });
394
- });
395
- };
396
- /**
397
- * Returns the state nodes represented by the current state value.
398
- *
399
- * @param state The state value or State instance
208
+ };
209
+ /**
210
+ * Clones this state machine with custom options and context.
211
+ *
212
+ * @param options Options (actions, guards, activities, services) to recursively merge with the existing options.
213
+ * @param context Custom context (will override predefined context)
214
+ */
215
+
216
+
217
+ StateNode.prototype.withConfig = function (options, context) {
218
+ var _a = this.options,
219
+ actions = _a.actions,
220
+ activities = _a.activities,
221
+ guards = _a.guards,
222
+ services = _a.services,
223
+ delays = _a.delays;
224
+ return new StateNode(this.config, {
225
+ actions: _tslib.__assign(_tslib.__assign({}, actions), options.actions),
226
+ activities: _tslib.__assign(_tslib.__assign({}, activities), options.activities),
227
+ guards: _tslib.__assign(_tslib.__assign({}, guards), options.guards),
228
+ services: _tslib.__assign(_tslib.__assign({}, services), options.services),
229
+ delays: _tslib.__assign(_tslib.__assign({}, delays), options.delays)
230
+ }, context !== null && context !== void 0 ? context : this.context);
231
+ };
232
+ /**
233
+ * Clones this state machine with custom context.
234
+ *
235
+ * @param context Custom context (will override predefined context, not recursive)
236
+ */
237
+
238
+
239
+ StateNode.prototype.withContext = function (context) {
240
+ return new StateNode(this.config, this.options, context);
241
+ };
242
+
243
+ Object.defineProperty(StateNode.prototype, "context", {
244
+ get: function () {
245
+ return utils.isFunction(this._context) ? this._context() : this._context;
246
+ },
247
+ enumerable: false,
248
+ configurable: true
249
+ });
250
+ Object.defineProperty(StateNode.prototype, "definition", {
251
+ /**
252
+ * The well-structured state node definition.
400
253
  */
401
- StateNode.prototype.getStateNodes = function (state) {
402
- var _a;
403
- var _this = this;
404
- if (!state) {
405
- return [];
406
- }
407
- var stateValue = state instanceof State_1.State
408
- ? state.value
409
- : utils_1.toStateValue(state, this.delimiter);
410
- if (utils_1.isString(stateValue)) {
411
- var initialStateValue = this.getStateNode(stateValue).initial;
412
- return initialStateValue !== undefined
413
- ? this.getStateNodes((_a = {}, _a[stateValue] = initialStateValue, _a))
414
- : [this, this.states[stateValue]];
415
- }
416
- var subStateKeys = utils_1.keys(stateValue);
417
- var subStateNodes = subStateKeys.map(function (subStateKey) { return _this.getStateNode(subStateKey); });
418
- subStateNodes.push(this);
419
- return subStateNodes.concat(subStateKeys.reduce(function (allSubStateNodes, subStateKey) {
420
- var subStateNode = _this.getStateNode(subStateKey).getStateNodes(stateValue[subStateKey]);
421
- return allSubStateNodes.concat(subStateNode);
422
- }, []));
423
- };
424
- /**
425
- * Returns `true` if this state node explicitly handles the given event.
426
- *
427
- * @param event The event in question
254
+ get: function () {
255
+ return {
256
+ id: this.id,
257
+ key: this.key,
258
+ version: this.version,
259
+ context: this.context,
260
+ type: this.type,
261
+ initial: this.initial,
262
+ history: this.history,
263
+ states: utils.mapValues(this.states, function (state) {
264
+ return state.definition;
265
+ }),
266
+ on: this.on,
267
+ transitions: this.transitions,
268
+ entry: this.onEntry,
269
+ exit: this.onExit,
270
+ activities: this.activities || [],
271
+ meta: this.meta,
272
+ order: this.order || -1,
273
+ data: this.doneData,
274
+ invoke: this.invoke
275
+ };
276
+ },
277
+ enumerable: false,
278
+ configurable: true
279
+ });
280
+
281
+ StateNode.prototype.toJSON = function () {
282
+ return this.definition;
283
+ };
284
+
285
+ Object.defineProperty(StateNode.prototype, "on", {
286
+ /**
287
+ * The mapping of events to transitions.
428
288
  */
429
- StateNode.prototype.handles = function (event) {
430
- var eventType = utils_1.getEventType(event);
431
- return this.events.includes(eventType);
432
- };
433
- /**
434
- * Resolves the given `state` to a new `State` instance relative to this machine.
435
- *
436
- * This ensures that `.events` and `.nextEvents` represent the correct values.
437
- *
438
- * @param state The state to resolve
289
+ get: function () {
290
+ if (this.__cache.on) {
291
+ return this.__cache.on;
292
+ }
293
+
294
+ var transitions = this.transitions;
295
+ return this.__cache.on = transitions.reduce(function (map, transition) {
296
+ map[transition.eventType] = map[transition.eventType] || [];
297
+ map[transition.eventType].push(transition);
298
+ return map;
299
+ }, {});
300
+ },
301
+ enumerable: false,
302
+ configurable: true
303
+ });
304
+ Object.defineProperty(StateNode.prototype, "after", {
305
+ get: function () {
306
+ return this.__cache.delayedTransitions || (this.__cache.delayedTransitions = this.getDelayedTransitions(), this.__cache.delayedTransitions);
307
+ },
308
+ enumerable: false,
309
+ configurable: true
310
+ });
311
+ Object.defineProperty(StateNode.prototype, "transitions", {
312
+ /**
313
+ * All the transitions that can be taken from this state node.
439
314
  */
440
- StateNode.prototype.resolveState = function (state) {
441
- var configuration = Array.from(stateUtils_1.getConfiguration([], this.getStateNodes(state.value)));
442
- return new State_1.State(__assign(__assign({}, state), { value: this.resolve(state.value), configuration: configuration, done: stateUtils_1.isInFinalState(configuration, this) }));
443
- };
444
- StateNode.prototype.transitionLeafNode = function (stateValue, state, _event) {
445
- var stateNode = this.getStateNode(stateValue);
446
- var next = stateNode.next(state, _event);
447
- if (!next || !next.transitions.length) {
448
- return this.next(state, _event);
449
- }
450
- return next;
451
- };
452
- StateNode.prototype.transitionCompoundNode = function (stateValue, state, _event) {
453
- var subStateKeys = utils_1.keys(stateValue);
454
- var stateNode = this.getStateNode(subStateKeys[0]);
455
- var next = stateNode._transition(stateValue[subStateKeys[0]], state, _event);
456
- if (!next || !next.transitions.length) {
457
- return this.next(state, _event);
458
- }
459
- return next;
460
- };
461
- StateNode.prototype.transitionParallelNode = function (stateValue, state, _event) {
462
- var e_2, _a;
463
- var transitionMap = {};
464
- try {
465
- for (var _b = __values(utils_1.keys(stateValue)), _c = _b.next(); !_c.done; _c = _b.next()) {
466
- var subStateKey = _c.value;
467
- var subStateValue = stateValue[subStateKey];
468
- if (!subStateValue) {
469
- continue;
470
- }
471
- var subStateNode = this.getStateNode(subStateKey);
472
- var next = subStateNode._transition(subStateValue, state, _event);
473
- if (next) {
474
- transitionMap[subStateKey] = next;
475
- }
476
- }
477
- }
478
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
479
- finally {
480
- try {
481
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
482
- }
483
- finally { if (e_2) throw e_2.error; }
484
- }
485
- var stateTransitions = utils_1.keys(transitionMap).map(function (key) { return transitionMap[key]; });
486
- var enabledTransitions = utils_1.flatten(stateTransitions.map(function (st) { return st.transitions; }));
487
- var willTransition = stateTransitions.some(function (st) { return st.transitions.length > 0; });
488
- if (!willTransition) {
489
- return this.next(state, _event);
490
- }
491
- var entryNodes = utils_1.flatten(stateTransitions.map(function (t) { return t.entrySet; }));
492
- var configuration = utils_1.flatten(utils_1.keys(transitionMap).map(function (key) { return transitionMap[key].configuration; }));
493
- return {
494
- transitions: enabledTransitions,
495
- entrySet: entryNodes,
496
- exitSet: utils_1.flatten(stateTransitions.map(function (t) { return t.exitSet; })),
497
- configuration: configuration,
498
- source: state,
499
- actions: utils_1.flatten(utils_1.keys(transitionMap).map(function (key) {
500
- return transitionMap[key].actions;
501
- }))
502
- };
503
- };
504
- StateNode.prototype._transition = function (stateValue, state, _event) {
505
- // leaf node
506
- if (utils_1.isString(stateValue)) {
507
- return this.transitionLeafNode(stateValue, state, _event);
508
- }
509
- // hierarchical node
510
- if (utils_1.keys(stateValue).length === 1) {
511
- return this.transitionCompoundNode(stateValue, state, _event);
512
- }
513
- // orthogonal node
514
- return this.transitionParallelNode(stateValue, state, _event);
515
- };
516
- StateNode.prototype.next = function (state, _event) {
517
- var e_3, _a;
518
- var _this = this;
519
- var eventName = _event.name;
520
- var actions = [];
521
- var nextStateNodes = [];
522
- var selectedTransition;
523
- try {
524
- for (var _b = __values(this.getCandidates(eventName)), _c = _b.next(); !_c.done; _c = _b.next()) {
525
- var candidate = _c.value;
526
- var cond = candidate.cond, stateIn = candidate.in;
527
- var resolvedContext = state.context;
528
- var isInState = stateIn
529
- ? utils_1.isString(stateIn) && isStateId(stateIn)
530
- ? // Check if in state by ID
531
- state.matches(utils_1.toStateValue(this.getStateNodeById(stateIn).path, this.delimiter))
532
- : // Check if in state by relative grandparent
533
- utils_2.matchesState(utils_1.toStateValue(stateIn, this.delimiter), utils_1.path(this.path.slice(0, -2))(state.value))
534
- : true;
535
- var guardPassed = false;
536
- try {
537
- guardPassed =
538
- !cond ||
539
- utils_1.evaluateGuard(this.machine, cond, resolvedContext, _event, state);
540
- }
541
- catch (err) {
542
- throw new Error("Unable to evaluate guard '" + (cond.name || cond.type) + "' in transition for event '" + eventName + "' in state node '" + this.id + "':\n" + err.message);
543
- }
544
- if (guardPassed && isInState) {
545
- if (candidate.target !== undefined) {
546
- nextStateNodes = candidate.target;
547
- }
548
- actions.push.apply(actions, __spreadArray([], __read(candidate.actions)));
549
- selectedTransition = candidate;
550
- break;
551
- }
552
- }
553
- }
554
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
555
- finally {
556
- try {
557
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
558
- }
559
- finally { if (e_3) throw e_3.error; }
560
- }
561
- if (!selectedTransition) {
562
- return undefined;
563
- }
564
- if (!nextStateNodes.length) {
565
- return {
566
- transitions: [selectedTransition],
567
- entrySet: [],
568
- exitSet: [],
569
- configuration: state.value ? [this] : [],
570
- source: state,
571
- actions: actions
572
- };
573
- }
574
- var allNextStateNodes = utils_1.flatten(nextStateNodes.map(function (stateNode) {
575
- return _this.getRelativeStateNodes(stateNode, state.historyValue);
576
- }));
577
- var isInternal = !!selectedTransition.internal;
578
- var reentryNodes = isInternal
579
- ? []
580
- : utils_1.flatten(allNextStateNodes.map(function (n) { return _this.nodesFromChild(n); }));
581
- return {
582
- transitions: [selectedTransition],
583
- entrySet: reentryNodes,
584
- exitSet: isInternal ? [] : [this],
585
- configuration: allNextStateNodes,
586
- source: state,
587
- actions: actions
588
- };
589
- };
590
- StateNode.prototype.nodesFromChild = function (childStateNode) {
591
- if (childStateNode.escapes(this)) {
592
- return [];
593
- }
594
- var nodes = [];
595
- var marker = childStateNode;
596
- while (marker && marker !== this) {
597
- nodes.push(marker);
598
- marker = marker.parent;
599
- }
600
- nodes.push(this); // inclusive
601
- return nodes;
315
+ get: function () {
316
+ return this.__cache.transitions || (this.__cache.transitions = this.formatTransitions(), this.__cache.transitions);
317
+ },
318
+ enumerable: false,
319
+ configurable: true
320
+ });
321
+
322
+ StateNode.prototype.getCandidates = function (eventName) {
323
+ if (this.__cache.candidates[eventName]) {
324
+ return this.__cache.candidates[eventName];
325
+ }
326
+
327
+ var transient = eventName === NULL_EVENT;
328
+ var candidates = this.transitions.filter(function (transition) {
329
+ var sameEventType = transition.eventType === eventName; // null events should only match against eventless transitions
330
+
331
+ return transient ? sameEventType : sameEventType || transition.eventType === WILDCARD;
332
+ });
333
+ this.__cache.candidates[eventName] = candidates;
334
+ return candidates;
335
+ };
336
+ /**
337
+ * All delayed transitions from the config.
338
+ */
339
+
340
+
341
+ StateNode.prototype.getDelayedTransitions = function () {
342
+ var _this = this;
343
+
344
+ var afterConfig = this.config.after;
345
+
346
+ if (!afterConfig) {
347
+ return [];
348
+ }
349
+
350
+ var mutateEntryExit = function (delay, i) {
351
+ var delayRef = utils.isFunction(delay) ? _this.id + ":delay[" + i + "]" : delay;
352
+ var eventType = actions.after(delayRef, _this.id);
353
+
354
+ _this.onEntry.push(actions.send(eventType, {
355
+ delay: delay
356
+ }));
357
+
358
+ _this.onExit.push(actions.cancel(eventType));
359
+
360
+ return eventType;
602
361
  };
603
- /**
604
- * Whether the given state node "escapes" this state node. If the `stateNode` is equal to or the parent of
605
- * this state node, it does not escape.
606
- */
607
- StateNode.prototype.escapes = function (stateNode) {
608
- if (this === stateNode) {
609
- return false;
610
- }
611
- var parent = this.parent;
612
- while (parent) {
613
- if (parent === stateNode) {
614
- return false;
615
- }
616
- parent = parent.parent;
617
- }
618
- return true;
362
+
363
+ var delayedTransitions = utils.isArray(afterConfig) ? afterConfig.map(function (transition, i) {
364
+ var eventType = mutateEntryExit(transition.delay, i);
365
+ return _tslib.__assign(_tslib.__assign({}, transition), {
366
+ event: eventType
367
+ });
368
+ }) : utils.flatten(utils.keys(afterConfig).map(function (delay, i) {
369
+ var configTransition = afterConfig[delay];
370
+ var resolvedTransition = utils.isString(configTransition) ? {
371
+ target: configTransition
372
+ } : configTransition;
373
+ var resolvedDelay = !isNaN(+delay) ? +delay : delay;
374
+ var eventType = mutateEntryExit(resolvedDelay, i);
375
+ return utils.toArray(resolvedTransition).map(function (transition) {
376
+ return _tslib.__assign(_tslib.__assign({}, transition), {
377
+ event: eventType,
378
+ delay: resolvedDelay
379
+ });
380
+ });
381
+ }));
382
+ return delayedTransitions.map(function (delayedTransition) {
383
+ var delay = delayedTransition.delay;
384
+ return _tslib.__assign(_tslib.__assign({}, _this.formatTransition(delayedTransition)), {
385
+ delay: delay
386
+ });
387
+ });
388
+ };
389
+ /**
390
+ * Returns the state nodes represented by the current state value.
391
+ *
392
+ * @param state The state value or State instance
393
+ */
394
+
395
+
396
+ StateNode.prototype.getStateNodes = function (state) {
397
+ var _a;
398
+
399
+ var _this = this;
400
+
401
+ if (!state) {
402
+ return [];
403
+ }
404
+
405
+ var stateValue = state instanceof State.State ? state.value : utils.toStateValue(state, this.delimiter);
406
+
407
+ if (utils.isString(stateValue)) {
408
+ var initialStateValue = this.getStateNode(stateValue).initial;
409
+ return initialStateValue !== undefined ? this.getStateNodes((_a = {}, _a[stateValue] = initialStateValue, _a)) : [this, this.states[stateValue]];
410
+ }
411
+
412
+ var subStateKeys = utils.keys(stateValue);
413
+ var subStateNodes = subStateKeys.map(function (subStateKey) {
414
+ return _this.getStateNode(subStateKey);
415
+ });
416
+ subStateNodes.push(this);
417
+ return subStateNodes.concat(subStateKeys.reduce(function (allSubStateNodes, subStateKey) {
418
+ var subStateNode = _this.getStateNode(subStateKey).getStateNodes(stateValue[subStateKey]);
419
+
420
+ return allSubStateNodes.concat(subStateNode);
421
+ }, []));
422
+ };
423
+ /**
424
+ * Returns `true` if this state node explicitly handles the given event.
425
+ *
426
+ * @param event The event in question
427
+ */
428
+
429
+
430
+ StateNode.prototype.handles = function (event) {
431
+ var eventType = utils.getEventType(event);
432
+ return this.events.includes(eventType);
433
+ };
434
+ /**
435
+ * Resolves the given `state` to a new `State` instance relative to this machine.
436
+ *
437
+ * This ensures that `.events` and `.nextEvents` represent the correct values.
438
+ *
439
+ * @param state The state to resolve
440
+ */
441
+
442
+
443
+ StateNode.prototype.resolveState = function (state) {
444
+ var configuration = Array.from(stateUtils.getConfiguration([], this.getStateNodes(state.value)));
445
+ return new State.State(_tslib.__assign(_tslib.__assign({}, state), {
446
+ value: this.resolve(state.value),
447
+ configuration: configuration,
448
+ done: stateUtils.isInFinalState(configuration, this)
449
+ }));
450
+ };
451
+
452
+ StateNode.prototype.transitionLeafNode = function (stateValue, state, _event) {
453
+ var stateNode = this.getStateNode(stateValue);
454
+ var next = stateNode.next(state, _event);
455
+
456
+ if (!next || !next.transitions.length) {
457
+ return this.next(state, _event);
458
+ }
459
+
460
+ return next;
461
+ };
462
+
463
+ StateNode.prototype.transitionCompoundNode = function (stateValue, state, _event) {
464
+ var subStateKeys = utils.keys(stateValue);
465
+ var stateNode = this.getStateNode(subStateKeys[0]);
466
+
467
+ var next = stateNode._transition(stateValue[subStateKeys[0]], state, _event);
468
+
469
+ if (!next || !next.transitions.length) {
470
+ return this.next(state, _event);
471
+ }
472
+
473
+ return next;
474
+ };
475
+
476
+ StateNode.prototype.transitionParallelNode = function (stateValue, state, _event) {
477
+ var e_2, _a;
478
+
479
+ var transitionMap = {};
480
+
481
+ try {
482
+ for (var _b = _tslib.__values(utils.keys(stateValue)), _c = _b.next(); !_c.done; _c = _b.next()) {
483
+ var subStateKey = _c.value;
484
+ var subStateValue = stateValue[subStateKey];
485
+
486
+ if (!subStateValue) {
487
+ continue;
488
+ }
489
+
490
+ var subStateNode = this.getStateNode(subStateKey);
491
+
492
+ var next = subStateNode._transition(subStateValue, state, _event);
493
+
494
+ if (next) {
495
+ transitionMap[subStateKey] = next;
496
+ }
497
+ }
498
+ } catch (e_2_1) {
499
+ e_2 = {
500
+ error: e_2_1
501
+ };
502
+ } finally {
503
+ try {
504
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
505
+ } finally {
506
+ if (e_2) throw e_2.error;
507
+ }
508
+ }
509
+
510
+ var stateTransitions = utils.keys(transitionMap).map(function (key) {
511
+ return transitionMap[key];
512
+ });
513
+ var enabledTransitions = utils.flatten(stateTransitions.map(function (st) {
514
+ return st.transitions;
515
+ }));
516
+ var willTransition = stateTransitions.some(function (st) {
517
+ return st.transitions.length > 0;
518
+ });
519
+
520
+ if (!willTransition) {
521
+ return this.next(state, _event);
522
+ }
523
+
524
+ var entryNodes = utils.flatten(stateTransitions.map(function (t) {
525
+ return t.entrySet;
526
+ }));
527
+ var configuration = utils.flatten(utils.keys(transitionMap).map(function (key) {
528
+ return transitionMap[key].configuration;
529
+ }));
530
+ return {
531
+ transitions: enabledTransitions,
532
+ entrySet: entryNodes,
533
+ exitSet: utils.flatten(stateTransitions.map(function (t) {
534
+ return t.exitSet;
535
+ })),
536
+ configuration: configuration,
537
+ source: state,
538
+ actions: utils.flatten(utils.keys(transitionMap).map(function (key) {
539
+ return transitionMap[key].actions;
540
+ }))
619
541
  };
620
- StateNode.prototype.getActions = function (transition, currentContext, _event, prevState) {
621
- var e_4, _a, e_5, _b;
622
- var prevConfig = stateUtils_1.getConfiguration([], prevState ? this.getStateNodes(prevState.value) : [this]);
623
- var resolvedConfig = transition.configuration.length
624
- ? stateUtils_1.getConfiguration(prevConfig, transition.configuration)
625
- : prevConfig;
626
- try {
627
- for (var resolvedConfig_1 = __values(resolvedConfig), resolvedConfig_1_1 = resolvedConfig_1.next(); !resolvedConfig_1_1.done; resolvedConfig_1_1 = resolvedConfig_1.next()) {
628
- var sn = resolvedConfig_1_1.value;
629
- if (!stateUtils_1.has(prevConfig, sn)) {
630
- transition.entrySet.push(sn);
631
- }
632
- }
633
- }
634
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
635
- finally {
636
- try {
637
- if (resolvedConfig_1_1 && !resolvedConfig_1_1.done && (_a = resolvedConfig_1.return)) _a.call(resolvedConfig_1);
638
- }
639
- finally { if (e_4) throw e_4.error; }
640
- }
542
+ };
543
+
544
+ StateNode.prototype._transition = function (stateValue, state, _event) {
545
+ // leaf node
546
+ if (utils.isString(stateValue)) {
547
+ return this.transitionLeafNode(stateValue, state, _event);
548
+ } // hierarchical node
549
+
550
+
551
+ if (utils.keys(stateValue).length === 1) {
552
+ return this.transitionCompoundNode(stateValue, state, _event);
553
+ } // orthogonal node
554
+
555
+
556
+ return this.transitionParallelNode(stateValue, state, _event);
557
+ };
558
+
559
+ StateNode.prototype.next = function (state, _event) {
560
+ var e_3, _a;
561
+
562
+ var _this = this;
563
+
564
+ var eventName = _event.name;
565
+ var actions = [];
566
+ var nextStateNodes = [];
567
+ var selectedTransition;
568
+
569
+ try {
570
+ for (var _b = _tslib.__values(this.getCandidates(eventName)), _c = _b.next(); !_c.done; _c = _b.next()) {
571
+ var candidate = _c.value;
572
+ var cond = candidate.cond,
573
+ stateIn = candidate.in;
574
+ var resolvedContext = state.context;
575
+ var isInState = stateIn ? utils.isString(stateIn) && isStateId(stateIn) ? // Check if in state by ID
576
+ state.matches(utils.toStateValue(this.getStateNodeById(stateIn).path, this.delimiter)) : // Check if in state by relative grandparent
577
+ utils.matchesState(utils.toStateValue(stateIn, this.delimiter), utils.path(this.path.slice(0, -2))(state.value)) : true;
578
+ var guardPassed = false;
579
+
641
580
  try {
642
- for (var prevConfig_1 = __values(prevConfig), prevConfig_1_1 = prevConfig_1.next(); !prevConfig_1_1.done; prevConfig_1_1 = prevConfig_1.next()) {
643
- var sn = prevConfig_1_1.value;
644
- if (!stateUtils_1.has(resolvedConfig, sn) || stateUtils_1.has(transition.exitSet, sn.parent)) {
645
- transition.exitSet.push(sn);
646
- }
647
- }
648
- }
649
- catch (e_5_1) { e_5 = { error: e_5_1 }; }
650
- finally {
651
- try {
652
- if (prevConfig_1_1 && !prevConfig_1_1.done && (_b = prevConfig_1.return)) _b.call(prevConfig_1);
653
- }
654
- finally { if (e_5) throw e_5.error; }
655
- }
656
- if (!transition.source) {
657
- transition.exitSet = [];
658
- // Ensure that root StateNode (machine) is entered
659
- transition.entrySet.push(this);
660
- }
661
- var doneEvents = utils_1.flatten(transition.entrySet.map(function (sn) {
662
- var events = [];
663
- if (sn.type !== 'final') {
664
- return events;
665
- }
666
- var parent = sn.parent;
667
- if (!parent.parent) {
668
- return events;
669
- }
670
- events.push(actions_1.done(sn.id, sn.doneData), // TODO: deprecate - final states should not emit done events for their own state.
671
- actions_1.done(parent.id, sn.doneData
672
- ? utils_1.mapContext(sn.doneData, currentContext, _event)
673
- : undefined));
674
- var grandparent = parent.parent;
675
- if (grandparent.type === 'parallel') {
676
- if (stateUtils_1.getChildren(grandparent).every(function (parentNode) {
677
- return stateUtils_1.isInFinalState(transition.configuration, parentNode);
678
- })) {
679
- events.push(actions_1.done(grandparent.id));
680
- }
681
- }
682
- return events;
683
- }));
684
- transition.exitSet.sort(function (a, b) { return b.order - a.order; });
685
- transition.entrySet.sort(function (a, b) { return a.order - b.order; });
686
- var entryStates = new Set(transition.entrySet);
687
- var exitStates = new Set(transition.exitSet);
688
- var _c = __read([
689
- utils_1.flatten(Array.from(entryStates).map(function (stateNode) {
690
- return __spreadArray(__spreadArray([], __read(stateNode.activities.map(function (activity) { return actions_1.start(activity); }))), __read(stateNode.onEntry));
691
- })).concat(doneEvents.map(actions_1.raise)),
692
- utils_1.flatten(Array.from(exitStates).map(function (stateNode) { return __spreadArray(__spreadArray([], __read(stateNode.onExit)), __read(stateNode.activities.map(function (activity) { return actions_1.stop(activity); }))); }))
693
- ], 2), entryActions = _c[0], exitActions = _c[1];
694
- var actions = actions_1.toActionObjects(exitActions.concat(transition.actions).concat(entryActions), this.machine.options.actions);
695
- return actions;
696
- };
697
- /**
698
- * Determines the next state given the current `state` and sent `event`.
699
- *
700
- * @param state The current State instance or state value
701
- * @param event The event that was sent at the current state
702
- * @param context The current context (extended state) of the current state
703
- */
704
- StateNode.prototype.transition = function (state, event, context) {
705
- if (state === void 0) { state = this
706
- .initialState; }
707
- var _event = utils_1.toSCXMLEvent(event);
708
- var currentState;
709
- if (state instanceof State_1.State) {
710
- currentState =
711
- context === undefined
712
- ? state
713
- : this.resolveState(State_1.State.from(state, context));
714
- }
715
- else {
716
- var resolvedStateValue = utils_1.isString(state)
717
- ? this.resolve(utils_1.pathToStateValue(this.getResolvedPath(state)))
718
- : this.resolve(state);
719
- var resolvedContext = context ? context : this.machine.context;
720
- currentState = this.resolveState(State_1.State.from(resolvedStateValue, resolvedContext));
721
- }
722
- if (!environment_1.IS_PRODUCTION && _event.name === WILDCARD) {
723
- throw new Error("An event cannot have the wildcard type ('" + WILDCARD + "')");
724
- }
725
- if (this.strict) {
726
- if (!this.events.includes(_event.name) && !utils_1.isBuiltInEvent(_event.name)) {
727
- throw new Error("Machine '" + this.id + "' does not accept event '" + _event.name + "'");
728
- }
729
- }
730
- var stateTransition = this._transition(currentState.value, currentState, _event) || {
731
- transitions: [],
732
- configuration: [],
733
- entrySet: [],
734
- exitSet: [],
735
- source: currentState,
736
- actions: []
737
- };
738
- var prevConfig = stateUtils_1.getConfiguration([], this.getStateNodes(currentState.value));
739
- var resolvedConfig = stateTransition.configuration.length
740
- ? stateUtils_1.getConfiguration(prevConfig, stateTransition.configuration)
741
- : prevConfig;
742
- stateTransition.configuration = __spreadArray([], __read(resolvedConfig));
743
- return this.resolveTransition(stateTransition, currentState, _event);
581
+ guardPassed = !cond || utils.evaluateGuard(this.machine, cond, resolvedContext, _event, state);
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);
584
+ }
585
+
586
+ if (guardPassed && isInState) {
587
+ if (candidate.target !== undefined) {
588
+ nextStateNodes = candidate.target;
589
+ }
590
+
591
+ actions.push.apply(actions, _tslib.__spreadArray([], _tslib.__read(candidate.actions)));
592
+ selectedTransition = candidate;
593
+ break;
594
+ }
595
+ }
596
+ } catch (e_3_1) {
597
+ e_3 = {
598
+ error: e_3_1
599
+ };
600
+ } finally {
601
+ try {
602
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
603
+ } finally {
604
+ if (e_3) throw e_3.error;
605
+ }
606
+ }
607
+
608
+ if (!selectedTransition) {
609
+ return undefined;
610
+ }
611
+
612
+ if (!nextStateNodes.length) {
613
+ return {
614
+ transitions: [selectedTransition],
615
+ entrySet: [],
616
+ exitSet: [],
617
+ configuration: state.value ? [this] : [],
618
+ source: state,
619
+ actions: actions
620
+ };
621
+ }
622
+
623
+ var allNextStateNodes = utils.flatten(nextStateNodes.map(function (stateNode) {
624
+ return _this.getRelativeStateNodes(stateNode, state.historyValue);
625
+ }));
626
+ var isInternal = !!selectedTransition.internal;
627
+ var reentryNodes = isInternal ? [] : utils.flatten(allNextStateNodes.map(function (n) {
628
+ return _this.nodesFromChild(n);
629
+ }));
630
+ return {
631
+ transitions: [selectedTransition],
632
+ entrySet: reentryNodes,
633
+ exitSet: isInternal ? [] : [this],
634
+ configuration: allNextStateNodes,
635
+ source: state,
636
+ actions: actions
744
637
  };
745
- StateNode.prototype.resolveRaisedTransition = function (state, _event, originalEvent) {
746
- var _a;
747
- var currentActions = state.actions;
748
- state = this.transition(state, _event);
749
- // Save original event to state
750
- // TODO: this should be the raised event! Delete in V5 (breaking)
751
- state._event = originalEvent;
752
- state.event = originalEvent.data;
753
- (_a = state.actions).unshift.apply(_a, __spreadArray([], __read(currentActions)));
754
- return state;
638
+ };
639
+
640
+ StateNode.prototype.nodesFromChild = function (childStateNode) {
641
+ if (childStateNode.escapes(this)) {
642
+ return [];
643
+ }
644
+
645
+ var nodes = [];
646
+ var marker = childStateNode;
647
+
648
+ while (marker && marker !== this) {
649
+ nodes.push(marker);
650
+ marker = marker.parent;
651
+ }
652
+
653
+ nodes.push(this); // inclusive
654
+
655
+ return nodes;
656
+ };
657
+ /**
658
+ * Whether the given state node "escapes" this state node. If the `stateNode` is equal to or the parent of
659
+ * this state node, it does not escape.
660
+ */
661
+
662
+
663
+ StateNode.prototype.escapes = function (stateNode) {
664
+ if (this === stateNode) {
665
+ return false;
666
+ }
667
+
668
+ var parent = this.parent;
669
+
670
+ while (parent) {
671
+ if (parent === stateNode) {
672
+ return false;
673
+ }
674
+
675
+ parent = parent.parent;
676
+ }
677
+
678
+ return true;
679
+ };
680
+
681
+ StateNode.prototype.getActions = function (transition, currentContext, _event, prevState) {
682
+ var e_4, _a, e_5, _b;
683
+
684
+ var prevConfig = stateUtils.getConfiguration([], prevState ? this.getStateNodes(prevState.value) : [this]);
685
+ var resolvedConfig = transition.configuration.length ? stateUtils.getConfiguration(prevConfig, transition.configuration) : prevConfig;
686
+
687
+ try {
688
+ for (var resolvedConfig_1 = _tslib.__values(resolvedConfig), resolvedConfig_1_1 = resolvedConfig_1.next(); !resolvedConfig_1_1.done; resolvedConfig_1_1 = resolvedConfig_1.next()) {
689
+ var sn = resolvedConfig_1_1.value;
690
+
691
+ if (!stateUtils.has(prevConfig, sn)) {
692
+ transition.entrySet.push(sn);
693
+ }
694
+ }
695
+ } catch (e_4_1) {
696
+ e_4 = {
697
+ error: e_4_1
698
+ };
699
+ } finally {
700
+ try {
701
+ if (resolvedConfig_1_1 && !resolvedConfig_1_1.done && (_a = resolvedConfig_1.return)) _a.call(resolvedConfig_1);
702
+ } finally {
703
+ if (e_4) throw e_4.error;
704
+ }
705
+ }
706
+
707
+ try {
708
+ for (var prevConfig_1 = _tslib.__values(prevConfig), prevConfig_1_1 = prevConfig_1.next(); !prevConfig_1_1.done; prevConfig_1_1 = prevConfig_1.next()) {
709
+ var sn = prevConfig_1_1.value;
710
+
711
+ if (!stateUtils.has(resolvedConfig, sn) || stateUtils.has(transition.exitSet, sn.parent)) {
712
+ transition.exitSet.push(sn);
713
+ }
714
+ }
715
+ } catch (e_5_1) {
716
+ e_5 = {
717
+ error: e_5_1
718
+ };
719
+ } finally {
720
+ try {
721
+ if (prevConfig_1_1 && !prevConfig_1_1.done && (_b = prevConfig_1.return)) _b.call(prevConfig_1);
722
+ } finally {
723
+ if (e_5) throw e_5.error;
724
+ }
725
+ }
726
+
727
+ if (!transition.source) {
728
+ transition.exitSet = []; // Ensure that root StateNode (machine) is entered
729
+
730
+ transition.entrySet.push(this);
731
+ }
732
+
733
+ var doneEvents = utils.flatten(transition.entrySet.map(function (sn) {
734
+ var events = [];
735
+
736
+ if (sn.type !== 'final') {
737
+ return events;
738
+ }
739
+
740
+ var parent = sn.parent;
741
+
742
+ if (!parent.parent) {
743
+ return events;
744
+ }
745
+
746
+ events.push(actions.done(sn.id, sn.doneData), // TODO: deprecate - final states should not emit done events for their own state.
747
+ actions.done(parent.id, sn.doneData ? utils.mapContext(sn.doneData, currentContext, _event) : undefined));
748
+ var grandparent = parent.parent;
749
+
750
+ if (grandparent.type === 'parallel') {
751
+ if (stateUtils.getChildren(grandparent).every(function (parentNode) {
752
+ return stateUtils.isInFinalState(transition.configuration, parentNode);
753
+ })) {
754
+ events.push(actions.done(grandparent.id));
755
+ }
756
+ }
757
+
758
+ return events;
759
+ }));
760
+ transition.exitSet.sort(function (a, b) {
761
+ return b.order - a.order;
762
+ });
763
+ transition.entrySet.sort(function (a, b) {
764
+ return a.order - b.order;
765
+ });
766
+ var entryStates = new Set(transition.entrySet);
767
+ var exitStates = new Set(transition.exitSet);
768
+
769
+ var _c = _tslib.__read([utils.flatten(Array.from(entryStates).map(function (stateNode) {
770
+ return _tslib.__spreadArray(_tslib.__spreadArray([], _tslib.__read(stateNode.activities.map(function (activity) {
771
+ return actions.start(activity);
772
+ }))), _tslib.__read(stateNode.onEntry));
773
+ })).concat(doneEvents.map(actions.raise)), utils.flatten(Array.from(exitStates).map(function (stateNode) {
774
+ return _tslib.__spreadArray(_tslib.__spreadArray([], _tslib.__read(stateNode.onExit)), _tslib.__read(stateNode.activities.map(function (activity) {
775
+ return actions.stop(activity);
776
+ })));
777
+ }))], 2),
778
+ entryActions = _c[0],
779
+ exitActions = _c[1];
780
+
781
+ var actions$1 = actions.toActionObjects(exitActions.concat(transition.actions).concat(entryActions), this.machine.options.actions);
782
+ return actions$1;
783
+ };
784
+ /**
785
+ * Determines the next state given the current `state` and sent `event`.
786
+ *
787
+ * @param state The current State instance or state value
788
+ * @param event The event that was sent at the current state
789
+ * @param context The current context (extended state) of the current state
790
+ */
791
+
792
+
793
+ StateNode.prototype.transition = function (state, event, context) {
794
+ if (state === void 0) {
795
+ state = this.initialState;
796
+ }
797
+
798
+ var _event = utils.toSCXMLEvent(event);
799
+
800
+ var currentState;
801
+
802
+ if (state instanceof State.State) {
803
+ currentState = context === undefined ? state : this.resolveState(State.State.from(state, context));
804
+ } else {
805
+ var resolvedStateValue = utils.isString(state) ? this.resolve(utils.pathToStateValue(this.getResolvedPath(state))) : this.resolve(state);
806
+ var resolvedContext = context !== null && context !== void 0 ? context : this.machine.context;
807
+ currentState = this.resolveState(State.State.from(resolvedStateValue, resolvedContext));
808
+ }
809
+
810
+ if (!environment.IS_PRODUCTION && _event.name === WILDCARD) {
811
+ throw new Error("An event cannot have the wildcard type ('" + WILDCARD + "')");
812
+ }
813
+
814
+ if (this.strict) {
815
+ if (!this.events.includes(_event.name) && !utils.isBuiltInEvent(_event.name)) {
816
+ throw new Error("Machine '" + this.id + "' does not accept event '" + _event.name + "'");
817
+ }
818
+ }
819
+
820
+ var stateTransition = this._transition(currentState.value, currentState, _event) || {
821
+ transitions: [],
822
+ configuration: [],
823
+ entrySet: [],
824
+ exitSet: [],
825
+ source: currentState,
826
+ actions: []
755
827
  };
756
- StateNode.prototype.resolveTransition = function (stateTransition, currentState, _event, context) {
757
- var e_6, _a;
758
- var _this = this;
759
- if (_event === void 0) { _event = actions_1.initEvent; }
760
- if (context === void 0) { context = this.machine.context; }
761
- var configuration = stateTransition.configuration;
762
- // Transition will "apply" if:
763
- // - this is the initial state (there is no current state)
764
- // - OR there are transitions
765
- var willTransition = !currentState || stateTransition.transitions.length > 0;
766
- var resolvedStateValue = willTransition
767
- ? stateUtils_1.getValue(this.machine, configuration)
768
- : undefined;
769
- var historyValue = currentState
770
- ? currentState.historyValue
771
- ? currentState.historyValue
772
- : stateTransition.source
773
- ? this.machine.historyValue(currentState.value)
774
- : undefined
775
- : undefined;
776
- var currentContext = currentState ? currentState.context : context;
777
- var actions = this.getActions(stateTransition, currentContext, _event, currentState);
778
- var activities = currentState ? __assign({}, currentState.activities) : {};
779
- try {
780
- for (var actions_2 = __values(actions), actions_2_1 = actions_2.next(); !actions_2_1.done; actions_2_1 = actions_2.next()) {
781
- var action = actions_2_1.value;
782
- if (action.type === actionTypes.start) {
783
- activities[action.activity.id || action.activity.type] = action;
784
- }
785
- else if (action.type === actionTypes.stop) {
786
- activities[action.activity.id || action.activity.type] = false;
787
- }
788
- }
789
- }
790
- catch (e_6_1) { e_6 = { error: e_6_1 }; }
791
- finally {
792
- try {
793
- if (actions_2_1 && !actions_2_1.done && (_a = actions_2.return)) _a.call(actions_2);
794
- }
795
- finally { if (e_6) throw e_6.error; }
796
- }
797
- var _b = __read(actions_1.resolveActions(this, currentState, currentContext, _event, actions), 2), resolvedActions = _b[0], updatedContext = _b[1];
798
- var _c = __read(utils_1.partition(resolvedActions, function (action) {
799
- return action.type === actionTypes.raise ||
800
- (action.type === actionTypes.send &&
801
- action.to ===
802
- types_1.SpecialTargets.Internal);
803
- }), 2), raisedEvents = _c[0], nonRaisedActions = _c[1];
804
- var invokeActions = resolvedActions.filter(function (action) {
805
- var _a;
806
- return (action.type === actionTypes.start &&
807
- ((_a = action.activity) === null || _a === void 0 ? void 0 : _a.type) ===
808
- actionTypes.invoke);
828
+ var prevConfig = stateUtils.getConfiguration([], this.getStateNodes(currentState.value));
829
+ var resolvedConfig = stateTransition.configuration.length ? stateUtils.getConfiguration(prevConfig, stateTransition.configuration) : prevConfig;
830
+ stateTransition.configuration = _tslib.__spreadArray([], _tslib.__read(resolvedConfig));
831
+ return this.resolveTransition(stateTransition, currentState, _event);
832
+ };
833
+
834
+ StateNode.prototype.resolveRaisedTransition = function (state, _event, originalEvent) {
835
+ var _a;
836
+
837
+ var currentActions = state.actions;
838
+ state = this.transition(state, _event); // Save original event to state
839
+ // TODO: this should be the raised event! Delete in V5 (breaking)
840
+
841
+ state._event = originalEvent;
842
+ state.event = originalEvent.data;
843
+
844
+ (_a = state.actions).unshift.apply(_a, _tslib.__spreadArray([], _tslib.__read(currentActions)));
845
+
846
+ return state;
847
+ };
848
+
849
+ StateNode.prototype.resolveTransition = function (stateTransition, currentState, _event, context) {
850
+ var e_6, _a;
851
+
852
+ var _this = this;
853
+
854
+ if (_event === void 0) {
855
+ _event = actions.initEvent;
856
+ }
857
+
858
+ if (context === void 0) {
859
+ context = this.machine.context;
860
+ }
861
+
862
+ var configuration = stateTransition.configuration; // Transition will "apply" if:
863
+ // - this is the initial state (there is no current state)
864
+ // - OR there are transitions
865
+
866
+ var willTransition = !currentState || stateTransition.transitions.length > 0;
867
+ var resolvedStateValue = willTransition ? stateUtils.getValue(this.machine, configuration) : undefined;
868
+ var historyValue = currentState ? currentState.historyValue ? currentState.historyValue : stateTransition.source ? this.machine.historyValue(currentState.value) : undefined : undefined;
869
+ var currentContext = currentState ? currentState.context : context;
870
+ var actions$1 = this.getActions(stateTransition, currentContext, _event, currentState);
871
+ var activities = currentState ? _tslib.__assign({}, currentState.activities) : {};
872
+
873
+ try {
874
+ for (var actions_1 = _tslib.__values(actions$1), actions_1_1 = actions_1.next(); !actions_1_1.done; actions_1_1 = actions_1.next()) {
875
+ var action = actions_1_1.value;
876
+
877
+ if (action.type === actionTypes.start) {
878
+ activities[action.activity.id || action.activity.type] = action;
879
+ } else if (action.type === actionTypes.stop) {
880
+ activities[action.activity.id || action.activity.type] = false;
881
+ }
882
+ }
883
+ } catch (e_6_1) {
884
+ e_6 = {
885
+ error: e_6_1
886
+ };
887
+ } finally {
888
+ try {
889
+ if (actions_1_1 && !actions_1_1.done && (_a = actions_1.return)) _a.call(actions_1);
890
+ } finally {
891
+ if (e_6) throw e_6.error;
892
+ }
893
+ }
894
+
895
+ var _b = _tslib.__read(actions.resolveActions(this, currentState, currentContext, _event, actions$1, this.machine.config.preserveActionOrder), 2),
896
+ resolvedActions = _b[0],
897
+ updatedContext = _b[1];
898
+
899
+ var _c = _tslib.__read(utils.partition(resolvedActions, function (action) {
900
+ return action.type === actionTypes.raise || action.type === actionTypes.send && action.to === types.SpecialTargets.Internal;
901
+ }), 2),
902
+ raisedEvents = _c[0],
903
+ nonRaisedActions = _c[1];
904
+
905
+ var invokeActions = resolvedActions.filter(function (action) {
906
+ var _a;
907
+
908
+ return action.type === actionTypes.start && ((_a = action.activity) === null || _a === void 0 ? void 0 : _a.type) === actionTypes.invoke;
909
+ });
910
+ var children = invokeActions.reduce(function (acc, action) {
911
+ acc[action.activity.id] = Actor.createInvocableActor(action.activity, _this.machine, updatedContext, _event);
912
+ return acc;
913
+ }, currentState ? _tslib.__assign({}, currentState.children) : {});
914
+ var resolvedConfiguration = resolvedStateValue ? stateTransition.configuration : currentState ? currentState.configuration : [];
915
+ var isDone = stateUtils.isInFinalState(resolvedConfiguration, this);
916
+ var nextState = new State.State({
917
+ value: resolvedStateValue || currentState.value,
918
+ context: updatedContext,
919
+ _event: _event,
920
+ // Persist _sessionid between states
921
+ _sessionid: currentState ? currentState._sessionid : null,
922
+ historyValue: resolvedStateValue ? historyValue ? utils.updateHistoryValue(historyValue, resolvedStateValue) : undefined : currentState ? currentState.historyValue : undefined,
923
+ history: !resolvedStateValue || stateTransition.source ? currentState : undefined,
924
+ actions: resolvedStateValue ? nonRaisedActions : [],
925
+ activities: resolvedStateValue ? activities : currentState ? currentState.activities : {},
926
+ events: [],
927
+ configuration: resolvedConfiguration,
928
+ transitions: stateTransition.transitions,
929
+ children: children,
930
+ done: isDone,
931
+ tags: currentState === null || currentState === void 0 ? void 0 : currentState.tags
932
+ });
933
+ var didUpdateContext = currentContext !== updatedContext;
934
+ nextState.changed = _event.name === actionTypes.update || didUpdateContext; // Dispose of penultimate histories to prevent memory leaks
935
+
936
+ var history = nextState.history;
937
+
938
+ if (history) {
939
+ delete history.history;
940
+ } // There are transient transitions if the machine is not in a final state
941
+ // and if some of the state nodes have transient ("always") transitions.
942
+
943
+
944
+ var isTransient = !isDone && (this._transient || configuration.some(function (stateNode) {
945
+ return stateNode._transient;
946
+ })); // If there are no enabled transitions, check if there are transient transitions.
947
+ // If there are transient transitions, continue checking for more transitions
948
+ // because an transient transition should be triggered even if there are no
949
+ // enabled transitions.
950
+ //
951
+ // If we're already working on an transient transition (by checking
952
+ // if the event is a NULL_EVENT), then stop to prevent an infinite loop.
953
+ //
954
+ // Otherwise, if there are no enabled nor transient transitions, we are done.
955
+
956
+ if (!willTransition && (!isTransient || _event.name === NULL_EVENT)) {
957
+ return nextState;
958
+ }
959
+
960
+ var maybeNextState = nextState;
961
+
962
+ if (!isDone) {
963
+ if (isTransient) {
964
+ maybeNextState = this.resolveRaisedTransition(maybeNextState, {
965
+ type: actionTypes.nullEvent
966
+ }, _event);
967
+ }
968
+
969
+ while (raisedEvents.length) {
970
+ var raisedEvent = raisedEvents.shift();
971
+ maybeNextState = this.resolveRaisedTransition(maybeNextState, raisedEvent._event, _event);
972
+ }
973
+ } // Detect if state changed
974
+
975
+
976
+ var changed = maybeNextState.changed || (history ? !!maybeNextState.actions.length || didUpdateContext || typeof history.value !== typeof maybeNextState.value || !State.stateValuesEqual(maybeNextState.value, history.value) : undefined);
977
+ maybeNextState.changed = changed; // Preserve original history after raised events
978
+
979
+ maybeNextState.history = history;
980
+ maybeNextState.tags = new Set(utils.flatten(maybeNextState.configuration.map(function (sn) {
981
+ return sn.tags;
982
+ })));
983
+ return maybeNextState;
984
+ };
985
+ /**
986
+ * Returns the child state node from its relative `stateKey`, or throws.
987
+ */
988
+
989
+
990
+ StateNode.prototype.getStateNode = function (stateKey) {
991
+ if (isStateId(stateKey)) {
992
+ return this.machine.getStateNodeById(stateKey);
993
+ }
994
+
995
+ if (!this.states) {
996
+ throw new Error("Unable to retrieve child state '" + stateKey + "' from '" + this.id + "'; no child states exist.");
997
+ }
998
+
999
+ var result = this.states[stateKey];
1000
+
1001
+ if (!result) {
1002
+ throw new Error("Child state '" + stateKey + "' does not exist on '" + this.id + "'");
1003
+ }
1004
+
1005
+ return result;
1006
+ };
1007
+ /**
1008
+ * Returns the state node with the given `stateId`, or throws.
1009
+ *
1010
+ * @param stateId The state ID. The prefix "#" is removed.
1011
+ */
1012
+
1013
+
1014
+ StateNode.prototype.getStateNodeById = function (stateId) {
1015
+ var resolvedStateId = isStateId(stateId) ? stateId.slice(STATE_IDENTIFIER.length) : stateId;
1016
+
1017
+ if (resolvedStateId === this.id) {
1018
+ return this;
1019
+ }
1020
+
1021
+ var stateNode = this.machine.idMap[resolvedStateId];
1022
+
1023
+ if (!stateNode) {
1024
+ throw new Error("Child state node '#" + resolvedStateId + "' does not exist on machine '" + this.id + "'");
1025
+ }
1026
+
1027
+ return stateNode;
1028
+ };
1029
+ /**
1030
+ * Returns the relative state node from the given `statePath`, or throws.
1031
+ *
1032
+ * @param statePath The string or string array relative path to the state node.
1033
+ */
1034
+
1035
+
1036
+ StateNode.prototype.getStateNodeByPath = function (statePath) {
1037
+ if (typeof statePath === 'string' && isStateId(statePath)) {
1038
+ try {
1039
+ return this.getStateNodeById(statePath.slice(1));
1040
+ } catch (e) {// try individual paths
1041
+ // throw e;
1042
+ }
1043
+ }
1044
+
1045
+ var arrayStatePath = utils.toStatePath(statePath, this.delimiter).slice();
1046
+ var currentStateNode = this;
1047
+
1048
+ while (arrayStatePath.length) {
1049
+ var key = arrayStatePath.shift();
1050
+
1051
+ if (!key.length) {
1052
+ break;
1053
+ }
1054
+
1055
+ currentStateNode = currentStateNode.getStateNode(key);
1056
+ }
1057
+
1058
+ return currentStateNode;
1059
+ };
1060
+ /**
1061
+ * Resolves a partial state value with its full representation in this machine.
1062
+ *
1063
+ * @param stateValue The partial state value to resolve.
1064
+ */
1065
+
1066
+
1067
+ StateNode.prototype.resolve = function (stateValue) {
1068
+ var _a;
1069
+
1070
+ var _this = this;
1071
+
1072
+ if (!stateValue) {
1073
+ return this.initialStateValue || EMPTY_OBJECT; // TODO: type-specific properties
1074
+ }
1075
+
1076
+ switch (this.type) {
1077
+ case 'parallel':
1078
+ return utils.mapValues(this.initialStateValue, function (subStateValue, subStateKey) {
1079
+ return subStateValue ? _this.getStateNode(subStateKey).resolve(stateValue[subStateKey] || subStateValue) : EMPTY_OBJECT;
809
1080
  });
810
- var children = invokeActions.reduce(function (acc, action) {
811
- acc[action.activity.id] = Actor_1.createInvocableActor(action.activity, _this.machine, updatedContext, _event);
812
- return acc;
813
- }, currentState
814
- ? __assign({}, currentState.children) : {});
815
- var resolvedConfiguration = resolvedStateValue
816
- ? stateTransition.configuration
817
- : currentState
818
- ? currentState.configuration
819
- : [];
820
- var isDone = stateUtils_1.isInFinalState(resolvedConfiguration, this);
821
- var nextState = new State_1.State({
822
- value: resolvedStateValue || currentState.value,
823
- context: updatedContext,
824
- _event: _event,
825
- // Persist _sessionid between states
826
- _sessionid: currentState ? currentState._sessionid : null,
827
- historyValue: resolvedStateValue
828
- ? historyValue
829
- ? utils_1.updateHistoryValue(historyValue, resolvedStateValue)
830
- : undefined
831
- : currentState
832
- ? currentState.historyValue
833
- : undefined,
834
- history: !resolvedStateValue || stateTransition.source
835
- ? currentState
836
- : undefined,
837
- actions: resolvedStateValue ? nonRaisedActions : [],
838
- activities: resolvedStateValue
839
- ? activities
840
- : currentState
841
- ? currentState.activities
842
- : {},
843
- events: [],
844
- configuration: resolvedConfiguration,
845
- transitions: stateTransition.transitions,
846
- children: children,
847
- done: isDone,
848
- tags: currentState === null || currentState === void 0 ? void 0 : currentState.tags
1081
+
1082
+ case 'compound':
1083
+ if (utils.isString(stateValue)) {
1084
+ var subStateNode = this.getStateNode(stateValue);
1085
+
1086
+ if (subStateNode.type === 'parallel' || subStateNode.type === 'compound') {
1087
+ return _a = {}, _a[stateValue] = subStateNode.initialStateValue, _a;
1088
+ }
1089
+
1090
+ return stateValue;
1091
+ }
1092
+
1093
+ if (!utils.keys(stateValue).length) {
1094
+ return this.initialStateValue || {};
1095
+ }
1096
+
1097
+ return utils.mapValues(stateValue, function (subStateValue, subStateKey) {
1098
+ return subStateValue ? _this.getStateNode(subStateKey).resolve(subStateValue) : EMPTY_OBJECT;
849
1099
  });
850
- var didUpdateContext = currentContext !== updatedContext;
851
- nextState.changed = _event.name === actionTypes.update || didUpdateContext;
852
- // Dispose of penultimate histories to prevent memory leaks
853
- var history = nextState.history;
854
- if (history) {
855
- delete history.history;
856
- }
857
- if (!resolvedStateValue) {
858
- return nextState;
859
- }
860
- var maybeNextState = nextState;
861
- if (!isDone) {
862
- var isTransient = this._transient ||
863
- configuration.some(function (stateNode) {
864
- return stateNode._transient;
865
- });
866
- if (isTransient) {
867
- maybeNextState = this.resolveRaisedTransition(maybeNextState, {
868
- type: actionTypes.nullEvent
869
- }, _event);
870
- }
871
- while (raisedEvents.length) {
872
- var raisedEvent = raisedEvents.shift();
873
- maybeNextState = this.resolveRaisedTransition(maybeNextState, raisedEvent._event, _event);
874
- }
875
- }
876
- // Detect if state changed
877
- var changed = maybeNextState.changed ||
878
- (history
879
- ? !!maybeNextState.actions.length ||
880
- didUpdateContext ||
881
- typeof history.value !== typeof maybeNextState.value ||
882
- !State_1.stateValuesEqual(maybeNextState.value, history.value)
883
- : undefined);
884
- maybeNextState.changed = changed;
885
- // Preserve original history after raised events
886
- maybeNextState.history = history;
887
- maybeNextState.tags = new Set(utils_1.flatten(maybeNextState.configuration.map(function (sn) { return sn.tags; })));
888
- return maybeNextState;
889
- };
890
- /**
891
- * Returns the child state node from its relative `stateKey`, or throws.
892
- */
893
- StateNode.prototype.getStateNode = function (stateKey) {
894
- if (isStateId(stateKey)) {
895
- return this.machine.getStateNodeById(stateKey);
896
- }
897
- if (!this.states) {
898
- throw new Error("Unable to retrieve child state '" + stateKey + "' from '" + this.id + "'; no child states exist.");
899
- }
900
- var result = this.states[stateKey];
901
- if (!result) {
902
- throw new Error("Child state '" + stateKey + "' does not exist on '" + this.id + "'");
903
- }
904
- return result;
905
- };
906
- /**
907
- * Returns the state node with the given `stateId`, or throws.
908
- *
909
- * @param stateId The state ID. The prefix "#" is removed.
910
- */
911
- StateNode.prototype.getStateNodeById = function (stateId) {
912
- var resolvedStateId = isStateId(stateId)
913
- ? stateId.slice(STATE_IDENTIFIER.length)
914
- : stateId;
915
- if (resolvedStateId === this.id) {
916
- return this;
917
- }
918
- var stateNode = this.machine.idMap[resolvedStateId];
919
- if (!stateNode) {
920
- throw new Error("Child state node '#" + resolvedStateId + "' does not exist on machine '" + this.id + "'");
921
- }
922
- return stateNode;
923
- };
924
- /**
925
- * Returns the relative state node from the given `statePath`, or throws.
926
- *
927
- * @param statePath The string or string array relative path to the state node.
1100
+
1101
+ default:
1102
+ return stateValue || EMPTY_OBJECT;
1103
+ }
1104
+ };
1105
+
1106
+ StateNode.prototype.getResolvedPath = function (stateIdentifier) {
1107
+ if (isStateId(stateIdentifier)) {
1108
+ var stateNode = this.machine.idMap[stateIdentifier.slice(STATE_IDENTIFIER.length)];
1109
+
1110
+ if (!stateNode) {
1111
+ throw new Error("Unable to find state node '" + stateIdentifier + "'");
1112
+ }
1113
+
1114
+ return stateNode.path;
1115
+ }
1116
+
1117
+ return utils.toStatePath(stateIdentifier, this.delimiter);
1118
+ };
1119
+
1120
+ Object.defineProperty(StateNode.prototype, "initialStateValue", {
1121
+ get: function () {
1122
+ var _a;
1123
+
1124
+ if (this.__cache.initialStateValue) {
1125
+ return this.__cache.initialStateValue;
1126
+ }
1127
+
1128
+ var initialStateValue;
1129
+
1130
+ if (this.type === 'parallel') {
1131
+ initialStateValue = utils.mapFilterValues(this.states, function (state) {
1132
+ return state.initialStateValue || EMPTY_OBJECT;
1133
+ }, function (stateNode) {
1134
+ return !(stateNode.type === 'history');
1135
+ });
1136
+ } else if (this.initial !== undefined) {
1137
+ if (!this.states[this.initial]) {
1138
+ throw new Error("Initial state '" + this.initial + "' not found on '" + this.key + "'");
1139
+ }
1140
+
1141
+ initialStateValue = stateUtils.isLeafNode(this.states[this.initial]) ? this.initial : (_a = {}, _a[this.initial] = this.states[this.initial].initialStateValue, _a);
1142
+ } else {
1143
+ // The finite state value of a machine without child states is just an empty object
1144
+ initialStateValue = {};
1145
+ }
1146
+
1147
+ this.__cache.initialStateValue = initialStateValue;
1148
+ return this.__cache.initialStateValue;
1149
+ },
1150
+ enumerable: false,
1151
+ configurable: true
1152
+ });
1153
+
1154
+ StateNode.prototype.getInitialState = function (stateValue, context) {
1155
+ var configuration = this.getStateNodes(stateValue);
1156
+ return this.resolveTransition({
1157
+ configuration: configuration,
1158
+ entrySet: configuration,
1159
+ exitSet: [],
1160
+ transitions: [],
1161
+ source: undefined,
1162
+ actions: []
1163
+ }, undefined, undefined, context);
1164
+ };
1165
+
1166
+ Object.defineProperty(StateNode.prototype, "initialState", {
1167
+ /**
1168
+ * The initial State instance, which includes all actions to be executed from
1169
+ * entering the initial state.
928
1170
  */
929
- StateNode.prototype.getStateNodeByPath = function (statePath) {
930
- if (typeof statePath === 'string' && isStateId(statePath)) {
931
- try {
932
- return this.getStateNodeById(statePath.slice(1));
933
- }
934
- catch (e) {
935
- // try individual paths
936
- // throw e;
937
- }
938
- }
939
- var arrayStatePath = utils_1.toStatePath(statePath, this.delimiter).slice();
940
- var currentStateNode = this;
941
- while (arrayStatePath.length) {
942
- var key = arrayStatePath.shift();
943
- if (!key.length) {
944
- break;
945
- }
946
- currentStateNode = currentStateNode.getStateNode(key);
947
- }
948
- return currentStateNode;
949
- };
950
- /**
951
- * Resolves a partial state value with its full representation in this machine.
952
- *
953
- * @param stateValue The partial state value to resolve.
1171
+ get: function () {
1172
+ this._init(); // TODO: this should be in the constructor (see note in constructor)
1173
+
1174
+
1175
+ var initialStateValue = this.initialStateValue;
1176
+
1177
+ if (!initialStateValue) {
1178
+ throw new Error("Cannot retrieve initial state from simple state '" + this.id + "'.");
1179
+ }
1180
+
1181
+ return this.getInitialState(initialStateValue);
1182
+ },
1183
+ enumerable: false,
1184
+ configurable: true
1185
+ });
1186
+ Object.defineProperty(StateNode.prototype, "target", {
1187
+ /**
1188
+ * The target state value of the history state node, if it exists. This represents the
1189
+ * default state value to transition to if no history value exists yet.
954
1190
  */
955
- StateNode.prototype.resolve = function (stateValue) {
956
- var _a;
957
- var _this = this;
958
- if (!stateValue) {
959
- return this.initialStateValue || EMPTY_OBJECT; // TODO: type-specific properties
960
- }
961
- switch (this.type) {
962
- case 'parallel':
963
- return utils_1.mapValues(this.initialStateValue, function (subStateValue, subStateKey) {
964
- return subStateValue
965
- ? _this.getStateNode(subStateKey).resolve(stateValue[subStateKey] || subStateValue)
966
- : EMPTY_OBJECT;
967
- });
968
- case 'compound':
969
- if (utils_1.isString(stateValue)) {
970
- var subStateNode = this.getStateNode(stateValue);
971
- if (subStateNode.type === 'parallel' ||
972
- subStateNode.type === 'compound') {
973
- return _a = {}, _a[stateValue] = subStateNode.initialStateValue, _a;
974
- }
975
- return stateValue;
976
- }
977
- if (!utils_1.keys(stateValue).length) {
978
- return this.initialStateValue || {};
979
- }
980
- return utils_1.mapValues(stateValue, function (subStateValue, subStateKey) {
981
- return subStateValue
982
- ? _this.getStateNode(subStateKey).resolve(subStateValue)
983
- : EMPTY_OBJECT;
984
- });
985
- default:
986
- return stateValue || EMPTY_OBJECT;
987
- }
988
- };
989
- StateNode.prototype.getResolvedPath = function (stateIdentifier) {
990
- if (isStateId(stateIdentifier)) {
991
- var stateNode = this.machine.idMap[stateIdentifier.slice(STATE_IDENTIFIER.length)];
992
- if (!stateNode) {
993
- throw new Error("Unable to find state node '" + stateIdentifier + "'");
994
- }
995
- return stateNode.path;
996
- }
997
- return utils_1.toStatePath(stateIdentifier, this.delimiter);
998
- };
999
- Object.defineProperty(StateNode.prototype, "initialStateValue", {
1000
- get: function () {
1001
- var _a;
1002
- if (this.__cache.initialStateValue) {
1003
- return this.__cache.initialStateValue;
1004
- }
1005
- var initialStateValue;
1006
- if (this.type === 'parallel') {
1007
- initialStateValue = utils_1.mapFilterValues(this.states, function (state) { return state.initialStateValue || EMPTY_OBJECT; }, function (stateNode) { return !(stateNode.type === 'history'); });
1008
- }
1009
- else if (this.initial !== undefined) {
1010
- if (!this.states[this.initial]) {
1011
- throw new Error("Initial state '" + this.initial + "' not found on '" + this.key + "'");
1012
- }
1013
- initialStateValue = (stateUtils_1.isLeafNode(this.states[this.initial])
1014
- ? this.initial
1015
- : (_a = {},
1016
- _a[this.initial] = this.states[this.initial].initialStateValue,
1017
- _a));
1018
- }
1019
- else {
1020
- // The finite state value of a machine without child states is just an empty object
1021
- initialStateValue = {};
1022
- }
1023
- this.__cache.initialStateValue = initialStateValue;
1024
- return this.__cache.initialStateValue;
1025
- },
1026
- enumerable: false,
1027
- configurable: true
1028
- });
1029
- StateNode.prototype.getInitialState = function (stateValue, context) {
1030
- var configuration = this.getStateNodes(stateValue);
1031
- return this.resolveTransition({
1032
- configuration: configuration,
1033
- entrySet: configuration,
1034
- exitSet: [],
1035
- transitions: [],
1036
- source: undefined,
1037
- actions: []
1038
- }, undefined, undefined, context);
1191
+ get: function () {
1192
+ var target;
1193
+
1194
+ if (this.type === 'history') {
1195
+ var historyConfig = this.config;
1196
+
1197
+ if (utils.isString(historyConfig.target)) {
1198
+ target = isStateId(historyConfig.target) ? utils.pathToStateValue(this.machine.getStateNodeById(historyConfig.target).path.slice(this.path.length - 1)) : historyConfig.target;
1199
+ } else {
1200
+ target = historyConfig.target;
1201
+ }
1202
+ }
1203
+
1204
+ return target;
1205
+ },
1206
+ enumerable: false,
1207
+ configurable: true
1208
+ });
1209
+ /**
1210
+ * Returns the leaf nodes from a state path relative to this state node.
1211
+ *
1212
+ * @param relativeStateId The relative state path to retrieve the state nodes
1213
+ * @param history The previous state to retrieve history
1214
+ * @param resolve Whether state nodes should resolve to initial child state nodes
1215
+ */
1216
+
1217
+ StateNode.prototype.getRelativeStateNodes = function (relativeStateId, historyValue, resolve) {
1218
+ if (resolve === void 0) {
1219
+ resolve = true;
1220
+ }
1221
+
1222
+ return resolve ? relativeStateId.type === 'history' ? relativeStateId.resolveHistory(historyValue) : relativeStateId.initialStateNodes : [relativeStateId];
1223
+ };
1224
+
1225
+ Object.defineProperty(StateNode.prototype, "initialStateNodes", {
1226
+ get: function () {
1227
+ var _this = this;
1228
+
1229
+ if (stateUtils.isLeafNode(this)) {
1230
+ return [this];
1231
+ } // Case when state node is compound but no initial state is defined
1232
+
1233
+
1234
+ if (this.type === 'compound' && !this.initial) {
1235
+ if (!environment.IS_PRODUCTION) {
1236
+ utils.warn(false, "Compound state node '" + this.id + "' has no initial state.");
1237
+ }
1238
+
1239
+ return [this];
1240
+ }
1241
+
1242
+ var initialStateNodePaths = utils.toStatePaths(this.initialStateValue);
1243
+ return utils.flatten(initialStateNodePaths.map(function (initialPath) {
1244
+ return _this.getFromRelativePath(initialPath);
1245
+ }));
1246
+ },
1247
+ enumerable: false,
1248
+ configurable: true
1249
+ });
1250
+ /**
1251
+ * Retrieves state nodes from a relative path to this state node.
1252
+ *
1253
+ * @param relativePath The relative path from this state node
1254
+ * @param historyValue
1255
+ */
1256
+
1257
+ StateNode.prototype.getFromRelativePath = function (relativePath) {
1258
+ if (!relativePath.length) {
1259
+ return [this];
1260
+ }
1261
+
1262
+ var _a = _tslib.__read(relativePath),
1263
+ stateKey = _a[0],
1264
+ childStatePath = _a.slice(1);
1265
+
1266
+ if (!this.states) {
1267
+ throw new Error("Cannot retrieve subPath '" + stateKey + "' from node with no states");
1268
+ }
1269
+
1270
+ var childStateNode = this.getStateNode(stateKey);
1271
+
1272
+ if (childStateNode.type === 'history') {
1273
+ return childStateNode.resolveHistory();
1274
+ }
1275
+
1276
+ if (!this.states[stateKey]) {
1277
+ throw new Error("Child state '" + stateKey + "' does not exist on '" + this.id + "'");
1278
+ }
1279
+
1280
+ return this.states[stateKey].getFromRelativePath(childStatePath);
1281
+ };
1282
+
1283
+ StateNode.prototype.historyValue = function (relativeStateValue) {
1284
+ if (!utils.keys(this.states).length) {
1285
+ return undefined;
1286
+ }
1287
+
1288
+ return {
1289
+ current: relativeStateValue || this.initialStateValue,
1290
+ states: utils.mapFilterValues(this.states, function (stateNode, key) {
1291
+ if (!relativeStateValue) {
1292
+ return stateNode.historyValue();
1293
+ }
1294
+
1295
+ var subStateValue = utils.isString(relativeStateValue) ? undefined : relativeStateValue[key];
1296
+ return stateNode.historyValue(subStateValue || stateNode.initialStateValue);
1297
+ }, function (stateNode) {
1298
+ return !stateNode.history;
1299
+ })
1039
1300
  };
1040
- Object.defineProperty(StateNode.prototype, "initialState", {
1041
- /**
1042
- * The initial State instance, which includes all actions to be executed from
1043
- * entering the initial state.
1044
- */
1045
- get: function () {
1046
- this._init(); // TODO: this should be in the constructor (see note in constructor)
1047
- var initialStateValue = this.initialStateValue;
1048
- if (!initialStateValue) {
1049
- throw new Error("Cannot retrieve initial state from simple state '" + this.id + "'.");
1050
- }
1051
- return this.getInitialState(initialStateValue);
1052
- },
1053
- enumerable: false,
1054
- configurable: true
1055
- });
1056
- Object.defineProperty(StateNode.prototype, "target", {
1057
- /**
1058
- * The target state value of the history state node, if it exists. This represents the
1059
- * default state value to transition to if no history value exists yet.
1060
- */
1061
- get: function () {
1062
- var target;
1063
- if (this.type === 'history') {
1064
- var historyConfig = this.config;
1065
- if (utils_1.isString(historyConfig.target)) {
1066
- target = isStateId(historyConfig.target)
1067
- ? utils_1.pathToStateValue(this.machine
1068
- .getStateNodeById(historyConfig.target)
1069
- .path.slice(this.path.length - 1))
1070
- : historyConfig.target;
1071
- }
1072
- else {
1073
- target = historyConfig.target;
1074
- }
1075
- }
1076
- return target;
1077
- },
1078
- enumerable: false,
1079
- configurable: true
1080
- });
1081
- /**
1082
- * Returns the leaf nodes from a state path relative to this state node.
1083
- *
1084
- * @param relativeStateId The relative state path to retrieve the state nodes
1085
- * @param history The previous state to retrieve history
1086
- * @param resolve Whether state nodes should resolve to initial child state nodes
1301
+ };
1302
+ /**
1303
+ * Resolves to the historical value(s) of the parent state node,
1304
+ * represented by state nodes.
1305
+ *
1306
+ * @param historyValue
1307
+ */
1308
+
1309
+
1310
+ StateNode.prototype.resolveHistory = function (historyValue) {
1311
+ var _this = this;
1312
+
1313
+ if (this.type !== 'history') {
1314
+ return [this];
1315
+ }
1316
+
1317
+ var parent = this.parent;
1318
+
1319
+ if (!historyValue) {
1320
+ var historyTarget = this.target;
1321
+ return historyTarget ? utils.flatten(utils.toStatePaths(historyTarget).map(function (relativeChildPath) {
1322
+ return parent.getFromRelativePath(relativeChildPath);
1323
+ })) : parent.initialStateNodes;
1324
+ }
1325
+
1326
+ var subHistoryValue = utils.nestedPath(parent.path, 'states')(historyValue).current;
1327
+
1328
+ if (utils.isString(subHistoryValue)) {
1329
+ return [parent.getStateNode(subHistoryValue)];
1330
+ }
1331
+
1332
+ return utils.flatten(utils.toStatePaths(subHistoryValue).map(function (subStatePath) {
1333
+ return _this.history === 'deep' ? parent.getFromRelativePath(subStatePath) : [parent.states[subStatePath[0]]];
1334
+ }));
1335
+ };
1336
+
1337
+ Object.defineProperty(StateNode.prototype, "stateIds", {
1338
+ /**
1339
+ * All the state node IDs of this state node and its descendant state nodes.
1087
1340
  */
1088
- StateNode.prototype.getRelativeStateNodes = function (relativeStateId, historyValue, resolve) {
1089
- if (resolve === void 0) { resolve = true; }
1090
- return resolve
1091
- ? relativeStateId.type === 'history'
1092
- ? relativeStateId.resolveHistory(historyValue)
1093
- : relativeStateId.initialStateNodes
1094
- : [relativeStateId];
1095
- };
1096
- Object.defineProperty(StateNode.prototype, "initialStateNodes", {
1097
- get: function () {
1098
- var _this = this;
1099
- if (stateUtils_1.isLeafNode(this)) {
1100
- return [this];
1101
- }
1102
- // Case when state node is compound but no initial state is defined
1103
- if (this.type === 'compound' && !this.initial) {
1104
- if (!environment_1.IS_PRODUCTION) {
1105
- utils_1.warn(false, "Compound state node '" + this.id + "' has no initial state.");
1106
- }
1107
- return [this];
1108
- }
1109
- var initialStateNodePaths = utils_1.toStatePaths(this.initialStateValue);
1110
- return utils_1.flatten(initialStateNodePaths.map(function (initialPath) {
1111
- return _this.getFromRelativePath(initialPath);
1112
- }));
1113
- },
1114
- enumerable: false,
1115
- configurable: true
1116
- });
1117
- /**
1118
- * Retrieves state nodes from a relative path to this state node.
1119
- *
1120
- * @param relativePath The relative path from this state node
1121
- * @param historyValue
1341
+ get: function () {
1342
+ var _this = this;
1343
+
1344
+ var childStateIds = utils.flatten(utils.keys(this.states).map(function (stateKey) {
1345
+ return _this.states[stateKey].stateIds;
1346
+ }));
1347
+ return [this.id].concat(childStateIds);
1348
+ },
1349
+ enumerable: false,
1350
+ configurable: true
1351
+ });
1352
+ Object.defineProperty(StateNode.prototype, "events", {
1353
+ /**
1354
+ * All the event types accepted by this state node and its descendants.
1122
1355
  */
1123
- StateNode.prototype.getFromRelativePath = function (relativePath) {
1124
- if (!relativePath.length) {
1125
- return [this];
1126
- }
1127
- var _a = __read(relativePath), stateKey = _a[0], childStatePath = _a.slice(1);
1128
- if (!this.states) {
1129
- throw new Error("Cannot retrieve subPath '" + stateKey + "' from node with no states");
1130
- }
1131
- var childStateNode = this.getStateNode(stateKey);
1132
- if (childStateNode.type === 'history') {
1133
- return childStateNode.resolveHistory();
1134
- }
1135
- if (!this.states[stateKey]) {
1136
- throw new Error("Child state '" + stateKey + "' does not exist on '" + this.id + "'");
1137
- }
1138
- return this.states[stateKey].getFromRelativePath(childStatePath);
1139
- };
1140
- StateNode.prototype.historyValue = function (relativeStateValue) {
1141
- if (!utils_1.keys(this.states).length) {
1142
- return undefined;
1143
- }
1144
- return {
1145
- current: relativeStateValue || this.initialStateValue,
1146
- states: utils_1.mapFilterValues(this.states, function (stateNode, key) {
1147
- if (!relativeStateValue) {
1148
- return stateNode.historyValue();
1356
+ get: function () {
1357
+ var e_7, _a, e_8, _b;
1358
+
1359
+ if (this.__cache.events) {
1360
+ return this.__cache.events;
1361
+ }
1362
+
1363
+ var states = this.states;
1364
+ var events = new Set(this.ownEvents);
1365
+
1366
+ if (states) {
1367
+ try {
1368
+ for (var _c = _tslib.__values(utils.keys(states)), _d = _c.next(); !_d.done; _d = _c.next()) {
1369
+ var stateId = _d.value;
1370
+ var state = states[stateId];
1371
+
1372
+ if (state.states) {
1373
+ try {
1374
+ for (var _e = (e_8 = void 0, _tslib.__values(state.events)), _f = _e.next(); !_f.done; _f = _e.next()) {
1375
+ var event_1 = _f.value;
1376
+ events.add("" + event_1);
1149
1377
  }
1150
- var subStateValue = utils_1.isString(relativeStateValue)
1151
- ? undefined
1152
- : relativeStateValue[key];
1153
- return stateNode.historyValue(subStateValue || stateNode.initialStateValue);
1154
- }, function (stateNode) { return !stateNode.history; })
1155
- };
1156
- };
1157
- /**
1158
- * Resolves to the historical value(s) of the parent state node,
1159
- * represented by state nodes.
1160
- *
1161
- * @param historyValue
1162
- */
1163
- StateNode.prototype.resolveHistory = function (historyValue) {
1164
- var _this = this;
1165
- if (this.type !== 'history') {
1166
- return [this];
1167
- }
1168
- var parent = this.parent;
1169
- if (!historyValue) {
1170
- var historyTarget = this.target;
1171
- return historyTarget
1172
- ? utils_1.flatten(utils_1.toStatePaths(historyTarget).map(function (relativeChildPath) {
1173
- return parent.getFromRelativePath(relativeChildPath);
1174
- }))
1175
- : parent.initialStateNodes;
1176
- }
1177
- var subHistoryValue = utils_1.nestedPath(parent.path, 'states')(historyValue).current;
1178
- if (utils_1.isString(subHistoryValue)) {
1179
- return [parent.getStateNode(subHistoryValue)];
1180
- }
1181
- return utils_1.flatten(utils_1.toStatePaths(subHistoryValue).map(function (subStatePath) {
1182
- return _this.history === 'deep'
1183
- ? parent.getFromRelativePath(subStatePath)
1184
- : [parent.states[subStatePath[0]]];
1185
- }));
1186
- };
1187
- Object.defineProperty(StateNode.prototype, "stateIds", {
1188
- /**
1189
- * All the state node IDs of this state node and its descendant state nodes.
1190
- */
1191
- get: function () {
1192
- var _this = this;
1193
- var childStateIds = utils_1.flatten(utils_1.keys(this.states).map(function (stateKey) {
1194
- return _this.states[stateKey].stateIds;
1195
- }));
1196
- return [this.id].concat(childStateIds);
1197
- },
1198
- enumerable: false,
1199
- configurable: true
1200
- });
1201
- Object.defineProperty(StateNode.prototype, "events", {
1202
- /**
1203
- * All the event types accepted by this state node and its descendants.
1204
- */
1205
- get: function () {
1206
- var e_7, _a, e_8, _b;
1207
- if (this.__cache.events) {
1208
- return this.__cache.events;
1209
- }
1210
- var states = this.states;
1211
- var events = new Set(this.ownEvents);
1212
- if (states) {
1378
+ } catch (e_8_1) {
1379
+ e_8 = {
1380
+ error: e_8_1
1381
+ };
1382
+ } finally {
1213
1383
  try {
1214
- for (var _c = __values(utils_1.keys(states)), _d = _c.next(); !_d.done; _d = _c.next()) {
1215
- var stateId = _d.value;
1216
- var state = states[stateId];
1217
- if (state.states) {
1218
- try {
1219
- for (var _e = (e_8 = void 0, __values(state.events)), _f = _e.next(); !_f.done; _f = _e.next()) {
1220
- var event_1 = _f.value;
1221
- events.add("" + event_1);
1222
- }
1223
- }
1224
- catch (e_8_1) { e_8 = { error: e_8_1 }; }
1225
- finally {
1226
- try {
1227
- if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
1228
- }
1229
- finally { if (e_8) throw e_8.error; }
1230
- }
1231
- }
1232
- }
1233
- }
1234
- catch (e_7_1) { e_7 = { error: e_7_1 }; }
1235
- finally {
1236
- try {
1237
- if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
1238
- }
1239
- finally { if (e_7) throw e_7.error; }
1384
+ if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
1385
+ } finally {
1386
+ if (e_8) throw e_8.error;
1240
1387
  }
1388
+ }
1241
1389
  }
1242
- return (this.__cache.events = Array.from(events));
1243
- },
1244
- enumerable: false,
1245
- configurable: true
1246
- });
1247
- Object.defineProperty(StateNode.prototype, "ownEvents", {
1248
- /**
1249
- * All the events that have transitions directly from this state node.
1250
- *
1251
- * Excludes any inert events.
1252
- */
1253
- get: function () {
1254
- var events = new Set(this.transitions
1255
- .filter(function (transition) {
1256
- return !(!transition.target &&
1257
- !transition.actions.length &&
1258
- transition.internal);
1259
- })
1260
- .map(function (transition) { return transition.eventType; }));
1261
- return Array.from(events);
1262
- },
1263
- enumerable: false,
1264
- configurable: true
1390
+ }
1391
+ } catch (e_7_1) {
1392
+ e_7 = {
1393
+ error: e_7_1
1394
+ };
1395
+ } finally {
1396
+ try {
1397
+ if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
1398
+ } finally {
1399
+ if (e_7) throw e_7.error;
1400
+ }
1401
+ }
1402
+ }
1403
+
1404
+ return this.__cache.events = Array.from(events);
1405
+ },
1406
+ enumerable: false,
1407
+ configurable: true
1408
+ });
1409
+ Object.defineProperty(StateNode.prototype, "ownEvents", {
1410
+ /**
1411
+ * All the events that have transitions directly from this state node.
1412
+ *
1413
+ * Excludes any inert events.
1414
+ */
1415
+ get: function () {
1416
+ var events = new Set(this.transitions.filter(function (transition) {
1417
+ return !(!transition.target && !transition.actions.length && transition.internal);
1418
+ }).map(function (transition) {
1419
+ return transition.eventType;
1420
+ }));
1421
+ return Array.from(events);
1422
+ },
1423
+ enumerable: false,
1424
+ configurable: true
1425
+ });
1426
+
1427
+ StateNode.prototype.resolveTarget = function (_target) {
1428
+ var _this = this;
1429
+
1430
+ if (_target === undefined) {
1431
+ // an undefined target signals that the state node should not transition from that state when receiving that event
1432
+ return undefined;
1433
+ }
1434
+
1435
+ return _target.map(function (target) {
1436
+ if (!utils.isString(target)) {
1437
+ return target;
1438
+ }
1439
+
1440
+ var isInternalTarget = target[0] === _this.delimiter; // If internal target is defined on machine,
1441
+ // do not include machine key on target
1442
+
1443
+ if (isInternalTarget && !_this.parent) {
1444
+ return _this.getStateNodeByPath(target.slice(1));
1445
+ }
1446
+
1447
+ var resolvedTarget = isInternalTarget ? _this.key + target : target;
1448
+
1449
+ if (_this.parent) {
1450
+ try {
1451
+ var targetStateNode = _this.parent.getStateNodeByPath(resolvedTarget);
1452
+
1453
+ return targetStateNode;
1454
+ } catch (err) {
1455
+ throw new Error("Invalid transition definition for state node '" + _this.id + "':\n" + err.message);
1456
+ }
1457
+ } else {
1458
+ return _this.getStateNodeByPath(resolvedTarget);
1459
+ }
1265
1460
  });
1266
- StateNode.prototype.resolveTarget = function (_target) {
1267
- var _this = this;
1268
- if (_target === undefined) {
1269
- // an undefined target signals that the state node should not transition from that state when receiving that event
1270
- return undefined;
1271
- }
1272
- return _target.map(function (target) {
1273
- if (!utils_1.isString(target)) {
1274
- return target;
1275
- }
1276
- var isInternalTarget = target[0] === _this.delimiter;
1277
- // If internal target is defined on machine,
1278
- // do not include machine key on target
1279
- if (isInternalTarget && !_this.parent) {
1280
- return _this.getStateNodeByPath(target.slice(1));
1281
- }
1282
- var resolvedTarget = isInternalTarget ? _this.key + target : target;
1283
- if (_this.parent) {
1284
- try {
1285
- var targetStateNode = _this.parent.getStateNodeByPath(resolvedTarget);
1286
- return targetStateNode;
1287
- }
1288
- catch (err) {
1289
- throw new Error("Invalid transition definition for state node '" + _this.id + "':\n" + err.message);
1290
- }
1291
- }
1292
- else {
1293
- return _this.getStateNodeByPath(resolvedTarget);
1294
- }
1461
+ };
1462
+
1463
+ StateNode.prototype.formatTransition = function (transitionConfig) {
1464
+ var _this = this;
1465
+
1466
+ var normalizedTarget = utils.normalizeTarget(transitionConfig.target);
1467
+ var internal = 'internal' in transitionConfig ? transitionConfig.internal : normalizedTarget ? normalizedTarget.some(function (_target) {
1468
+ return utils.isString(_target) && _target[0] === _this.delimiter;
1469
+ }) : true;
1470
+ var guards = this.machine.options.guards;
1471
+ var target = this.resolveTarget(normalizedTarget);
1472
+
1473
+ var transition = _tslib.__assign(_tslib.__assign({}, transitionConfig), {
1474
+ actions: actions.toActionObjects(utils.toArray(transitionConfig.actions)),
1475
+ cond: utils.toGuard(transitionConfig.cond, guards),
1476
+ target: target,
1477
+ source: this,
1478
+ internal: internal,
1479
+ eventType: transitionConfig.event,
1480
+ toJSON: function () {
1481
+ return _tslib.__assign(_tslib.__assign({}, transition), {
1482
+ target: transition.target ? transition.target.map(function (t) {
1483
+ return "#" + t.id;
1484
+ }) : undefined,
1485
+ source: "#" + _this.id
1295
1486
  });
1296
- };
1297
- StateNode.prototype.formatTransition = function (transitionConfig) {
1298
- var _this = this;
1299
- var normalizedTarget = utils_1.normalizeTarget(transitionConfig.target);
1300
- var internal = 'internal' in transitionConfig
1301
- ? transitionConfig.internal
1302
- : normalizedTarget
1303
- ? normalizedTarget.some(function (_target) { return utils_1.isString(_target) && _target[0] === _this.delimiter; })
1304
- : true;
1305
- var guards = this.machine.options.guards;
1306
- var target = this.resolveTarget(normalizedTarget);
1307
- var transition = __assign(__assign({}, transitionConfig), { actions: actions_1.toActionObjects(utils_1.toArray(transitionConfig.actions)), cond: utils_1.toGuard(transitionConfig.cond, guards), target: target, source: this, internal: internal, eventType: transitionConfig.event, toJSON: function () { return (__assign(__assign({}, transition), { target: transition.target
1308
- ? transition.target.map(function (t) { return "#" + t.id; })
1309
- : undefined, source: "#" + _this.id })); } });
1310
- return transition;
1311
- };
1312
- StateNode.prototype.formatTransitions = function () {
1313
- var e_9, _a;
1314
- var _this = this;
1315
- var onConfig;
1316
- if (!this.config.on) {
1317
- onConfig = [];
1318
- }
1319
- else if (Array.isArray(this.config.on)) {
1320
- onConfig = this.config.on;
1321
- }
1322
- else {
1323
- var _b = this.config.on, _c = WILDCARD, _d = _b[_c], wildcardConfigs = _d === void 0 ? [] : _d, strictTransitionConfigs_1 = __rest(_b, [typeof _c === "symbol" ? _c : _c + ""]);
1324
- onConfig = utils_1.flatten(utils_1.keys(strictTransitionConfigs_1)
1325
- .map(function (key) {
1326
- if (!environment_1.IS_PRODUCTION && key === NULL_EVENT) {
1327
- utils_1.warn(false, "Empty string transition configs (e.g., `{ on: { '': ... }}`) for transient transitions are deprecated. Specify the transition in the `{ always: ... }` property instead. " +
1328
- ("Please check the `on` configuration for \"#" + _this.id + "\"."));
1329
- }
1330
- var transitionConfigArray = utils_1.toTransitionConfigArray(key, strictTransitionConfigs_1[key]);
1331
- if (!environment_1.IS_PRODUCTION) {
1332
- validateArrayifiedTransitions(_this, key, transitionConfigArray);
1333
- }
1334
- return transitionConfigArray;
1335
- })
1336
- .concat(utils_1.toTransitionConfigArray(WILDCARD, wildcardConfigs)));
1337
- }
1338
- var eventlessConfig = this.config.always
1339
- ? utils_1.toTransitionConfigArray('', this.config.always)
1340
- : [];
1341
- var doneConfig = this.config.onDone
1342
- ? utils_1.toTransitionConfigArray(String(actions_1.done(this.id)), this.config.onDone)
1343
- : [];
1344
- if (!environment_1.IS_PRODUCTION) {
1345
- utils_1.warn(!(this.config.onDone && !this.parent), "Root nodes cannot have an \".onDone\" transition. Please check the config of \"" + this.id + "\".");
1346
- }
1347
- var invokeConfig = utils_1.flatten(this.invoke.map(function (invokeDef) {
1348
- var settleTransitions = [];
1349
- if (invokeDef.onDone) {
1350
- settleTransitions.push.apply(settleTransitions, __spreadArray([], __read(utils_1.toTransitionConfigArray(String(actions_1.doneInvoke(invokeDef.id)), invokeDef.onDone))));
1351
- }
1352
- if (invokeDef.onError) {
1353
- settleTransitions.push.apply(settleTransitions, __spreadArray([], __read(utils_1.toTransitionConfigArray(String(actions_1.error(invokeDef.id)), invokeDef.onError))));
1354
- }
1355
- return settleTransitions;
1356
- }));
1357
- var delayedTransitions = this.after;
1358
- var formattedTransitions = utils_1.flatten(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], __read(doneConfig)), __read(invokeConfig)), __read(onConfig)), __read(eventlessConfig)).map(function (transitionConfig) {
1359
- return utils_1.toArray(transitionConfig).map(function (transition) {
1360
- return _this.formatTransition(transition);
1361
- });
1362
- }));
1363
- try {
1364
- for (var delayedTransitions_1 = __values(delayedTransitions), delayedTransitions_1_1 = delayedTransitions_1.next(); !delayedTransitions_1_1.done; delayedTransitions_1_1 = delayedTransitions_1.next()) {
1365
- var delayedTransition = delayedTransitions_1_1.value;
1366
- formattedTransitions.push(delayedTransition);
1367
- }
1368
- }
1369
- catch (e_9_1) { e_9 = { error: e_9_1 }; }
1370
- finally {
1371
- try {
1372
- if (delayedTransitions_1_1 && !delayedTransitions_1_1.done && (_a = delayedTransitions_1.return)) _a.call(delayedTransitions_1);
1373
- }
1374
- finally { if (e_9) throw e_9.error; }
1375
- }
1376
- return formattedTransitions;
1377
- };
1378
- return StateNode;
1379
- }());
1487
+ }
1488
+ });
1489
+
1490
+ return transition;
1491
+ };
1492
+
1493
+ StateNode.prototype.formatTransitions = function () {
1494
+ var e_9, _a;
1495
+
1496
+ var _this = this;
1497
+
1498
+ var onConfig;
1499
+
1500
+ if (!this.config.on) {
1501
+ onConfig = [];
1502
+ } else if (Array.isArray(this.config.on)) {
1503
+ onConfig = this.config.on;
1504
+ } else {
1505
+ var _b = this.config.on,
1506
+ _c = WILDCARD,
1507
+ _d = _b[_c],
1508
+ wildcardConfigs = _d === void 0 ? [] : _d,
1509
+ strictTransitionConfigs_1 = _tslib.__rest(_b, [typeof _c === "symbol" ? _c : _c + ""]);
1510
+
1511
+ onConfig = utils.flatten(utils.keys(strictTransitionConfigs_1).map(function (key) {
1512
+ if (!environment.IS_PRODUCTION && key === NULL_EVENT) {
1513
+ 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 + "\"."));
1514
+ }
1515
+
1516
+ var transitionConfigArray = utils.toTransitionConfigArray(key, strictTransitionConfigs_1[key]);
1517
+
1518
+ if (!environment.IS_PRODUCTION) {
1519
+ validateArrayifiedTransitions(_this, key, transitionConfigArray);
1520
+ }
1521
+
1522
+ return transitionConfigArray;
1523
+ }).concat(utils.toTransitionConfigArray(WILDCARD, wildcardConfigs)));
1524
+ }
1525
+
1526
+ var eventlessConfig = this.config.always ? utils.toTransitionConfigArray('', this.config.always) : [];
1527
+ var doneConfig = this.config.onDone ? utils.toTransitionConfigArray(String(actions.done(this.id)), this.config.onDone) : [];
1528
+
1529
+ if (!environment.IS_PRODUCTION) {
1530
+ utils.warn(!(this.config.onDone && !this.parent), "Root nodes cannot have an \".onDone\" transition. Please check the config of \"" + this.id + "\".");
1531
+ }
1532
+
1533
+ var invokeConfig = utils.flatten(this.invoke.map(function (invokeDef) {
1534
+ var settleTransitions = [];
1535
+
1536
+ if (invokeDef.onDone) {
1537
+ settleTransitions.push.apply(settleTransitions, _tslib.__spreadArray([], _tslib.__read(utils.toTransitionConfigArray(String(actions.doneInvoke(invokeDef.id)), invokeDef.onDone))));
1538
+ }
1539
+
1540
+ if (invokeDef.onError) {
1541
+ settleTransitions.push.apply(settleTransitions, _tslib.__spreadArray([], _tslib.__read(utils.toTransitionConfigArray(String(actions.error(invokeDef.id)), invokeDef.onError))));
1542
+ }
1543
+
1544
+ return settleTransitions;
1545
+ }));
1546
+ var delayedTransitions = this.after;
1547
+ 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) {
1548
+ return utils.toArray(transitionConfig).map(function (transition) {
1549
+ return _this.formatTransition(transition);
1550
+ });
1551
+ }));
1552
+
1553
+ try {
1554
+ for (var delayedTransitions_1 = _tslib.__values(delayedTransitions), delayedTransitions_1_1 = delayedTransitions_1.next(); !delayedTransitions_1_1.done; delayedTransitions_1_1 = delayedTransitions_1.next()) {
1555
+ var delayedTransition = delayedTransitions_1_1.value;
1556
+ formattedTransitions.push(delayedTransition);
1557
+ }
1558
+ } catch (e_9_1) {
1559
+ e_9 = {
1560
+ error: e_9_1
1561
+ };
1562
+ } finally {
1563
+ try {
1564
+ if (delayedTransitions_1_1 && !delayedTransitions_1_1.done && (_a = delayedTransitions_1.return)) _a.call(delayedTransitions_1);
1565
+ } finally {
1566
+ if (e_9) throw e_9.error;
1567
+ }
1568
+ }
1569
+
1570
+ return formattedTransitions;
1571
+ };
1572
+
1573
+ return StateNode;
1574
+ }();
1575
+
1380
1576
  exports.StateNode = StateNode;