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