xstate 4.22.0 → 4.23.0

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