xstate 4.32.1 → 5.0.0-alpha.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.
- package/CHANGELOG.md +483 -0
- package/actions/ExecutableAction.ts +58 -0
- package/actions/dist/xstate-actions.cjs.d.ts +1 -0
- package/actions/dist/xstate-actions.cjs.dev.js +32 -0
- package/actions/dist/xstate-actions.cjs.js +7 -0
- package/actions/dist/xstate-actions.cjs.prod.js +32 -0
- package/actions/dist/xstate-actions.esm.js +2 -0
- package/actions/dynamicAction.ts +34 -0
- package/actions/package.json +4 -0
- package/actors/dist/xstate-actors.cjs.d.ts +1 -0
- package/actors/dist/xstate-actors.cjs.dev.js +21 -0
- package/actors/dist/xstate-actors.cjs.js +7 -0
- package/actors/dist/xstate-actors.cjs.prod.js +21 -0
- package/actors/dist/xstate-actors.esm.js +2 -0
- package/actors/package.json +4 -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/package.json +4 -0
- package/dist/Machine-9ce74c11.cjs.dev.js +755 -0
- package/dist/Machine-dca041dc.cjs.prod.js +749 -0
- package/dist/Machine-fb2f47f5.esm.js +751 -0
- package/dist/actions-6b86876d.cjs.dev.js +4815 -0
- package/dist/actions-70094c93.cjs.prod.js +4765 -0
- package/dist/actions-ff512f16.esm.js +4757 -0
- package/dist/declarations/actions/ExecutableAction.d.ts +23 -0
- package/dist/declarations/actions/dynamicAction.d.ts +3 -0
- package/dist/declarations/src/Machine.d.ts +4 -0
- package/dist/declarations/src/Mailbox.d.ts +12 -0
- package/dist/declarations/src/ObservableActorRef.d.ts +25 -0
- package/{lib → dist/declarations/src}/SimulatedClock.d.ts +0 -1
- package/dist/declarations/src/State.d.ts +104 -0
- package/dist/declarations/src/StateMachine.d.ts +112 -0
- package/dist/declarations/src/StateNode.d.ts +127 -0
- package/{es → dist/declarations/src}/actionTypes.d.ts +0 -3
- 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 +55 -0
- package/dist/declarations/src/actions/stop.d.ts +8 -0
- package/dist/declarations/src/actions.d.ts +44 -0
- package/dist/declarations/src/actors.d.ts +38 -0
- package/dist/declarations/src/constants.d.ts +5 -0
- package/{lib/devTools.d.ts → dist/declarations/src/dev/index.d.ts} +2 -2
- package/{es → dist/declarations/src}/environment.d.ts +0 -1
- package/dist/declarations/src/guards.d.ts +9 -0
- package/dist/declarations/src/index.d.ts +47 -0
- package/dist/declarations/src/interpreter.d.ts +147 -0
- package/{es → dist/declarations/src}/mapState.d.ts +0 -1
- package/dist/declarations/src/match.d.ts +5 -0
- package/dist/declarations/src/memo.d.ts +1 -0
- package/dist/declarations/src/model.d.ts +5 -0
- package/{lib → dist/declarations/src}/model.types.d.ts +6 -9
- package/dist/declarations/src/registry.d.ts +8 -0
- package/{es → dist/declarations/src}/schema.d.ts +0 -1
- package/dist/declarations/src/spawn.d.ts +2 -0
- package/dist/declarations/src/stateUtils.d.ts +85 -0
- package/{lib → dist/declarations/src}/typegenTypes.d.ts +16 -17
- package/dist/declarations/src/types.d.ts +1026 -0
- package/dist/declarations/src/utils.d.ts +56 -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 +217 -0
- package/dist/xstate.cjs.js +7 -0
- package/dist/xstate.cjs.prod.js +217 -0
- package/dist/xstate.esm.js +172 -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/package.json +4 -0
- package/invoke/package.json +4 -0
- package/model/dist/xstate-model.cjs.d.ts +1 -0
- package/model/dist/xstate-model.cjs.dev.js +41 -0
- package/model/dist/xstate-model.cjs.js +7 -0
- package/model/dist/xstate-model.cjs.prod.js +41 -0
- package/model/dist/xstate-model.esm.js +37 -0
- package/model/package.json +4 -0
- package/package.json +21 -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 -14
- package/es/SimulatedClock.d.ts +0 -17
- 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 -287
- package/es/StateNode.js +0 -1566
- package/es/_virtual/_tslib.js +0 -78
- package/es/actionTypes.js +0 -22
- package/es/actions.d.ts +0 -154
- package/es/actions.js +0 -520
- 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 -23
- package/es/interpreter.d.ts +0 -209
- package/es/interpreter.js +0 -1402
- 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 -5
- 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 -17
- package/es/stateUtils.js +0 -259
- package/es/typegenTypes.d.ts +0 -133
- package/es/types.d.ts +0 -1031
- package/es/types.js +0 -33
- package/es/utils.d.ts +0 -72
- package/es/utils.js +0 -626
- package/es/waitFor.d.ts +0 -32
- package/es/waitFor.js +0 -71
- 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 -19
- 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 -287
- package/lib/StateNode.js +0 -1570
- 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 -154
- package/lib/actions.js +0 -552
- 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 -60
- package/lib/interpreter.d.ts +0 -209
- package/lib/interpreter.js +0 -1408
- 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 -5
- package/lib/model.js +0 -54
- 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 -17
- package/lib/stateUtils.js +0 -273
- package/lib/typegenTypes.js +0 -2
- package/lib/types.d.ts +0 -1031
- package/lib/types.js +0 -35
- package/lib/utils.d.ts +0 -72
- package/lib/utils.js +0 -673
- package/lib/waitFor.d.ts +0 -32
- package/lib/waitFor.js +0 -75
package/lib/State.js
DELETED
|
@@ -1,282 +0,0 @@
|
|
|
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 utils = require('./utils.js');
|
|
8
|
-
var stateUtils = require('./stateUtils.js');
|
|
9
|
-
var actions = require('./actions.js');
|
|
10
|
-
var environment = require('./environment.js');
|
|
11
|
-
|
|
12
|
-
function stateValuesEqual(a, b) {
|
|
13
|
-
if (a === b) {
|
|
14
|
-
return true;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
if (a === undefined || b === undefined) {
|
|
18
|
-
return false;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
if (utils.isString(a) || utils.isString(b)) {
|
|
22
|
-
return a === b;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
var aKeys = Object.keys(a);
|
|
26
|
-
var bKeys = Object.keys(b);
|
|
27
|
-
return aKeys.length === bKeys.length && aKeys.every(function (key) {
|
|
28
|
-
return stateValuesEqual(a[key], b[key]);
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
function isStateConfig(state) {
|
|
32
|
-
if (typeof state !== 'object' || state === null) {
|
|
33
|
-
return false;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
return 'value' in state && '_event' in state;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* @deprecated Use `isStateConfig(object)` or `state instanceof State` instead.
|
|
40
|
-
*/
|
|
41
|
-
|
|
42
|
-
var isState = isStateConfig;
|
|
43
|
-
function bindActionToState(action, state) {
|
|
44
|
-
var exec = action.exec;
|
|
45
|
-
|
|
46
|
-
var boundAction = _tslib.__assign(_tslib.__assign({}, action), {
|
|
47
|
-
exec: exec !== undefined ? function () {
|
|
48
|
-
return exec(state.context, state.event, {
|
|
49
|
-
action: action,
|
|
50
|
-
state: state,
|
|
51
|
-
_event: state._event
|
|
52
|
-
});
|
|
53
|
-
} : undefined
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
return boundAction;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
var State =
|
|
60
|
-
/*#__PURE__*/
|
|
61
|
-
|
|
62
|
-
/** @class */
|
|
63
|
-
function () {
|
|
64
|
-
/**
|
|
65
|
-
* Creates a new State instance.
|
|
66
|
-
* @param value The state value
|
|
67
|
-
* @param context The extended state
|
|
68
|
-
* @param historyValue The tree representing historical values of the state nodes
|
|
69
|
-
* @param history The previous state
|
|
70
|
-
* @param actions An array of action objects to execute as side-effects
|
|
71
|
-
* @param activities A mapping of activities and whether they are started (`true`) or stopped (`false`).
|
|
72
|
-
* @param meta
|
|
73
|
-
* @param events Internal event queue. Should be empty with run-to-completion semantics.
|
|
74
|
-
* @param configuration
|
|
75
|
-
*/
|
|
76
|
-
function State(config) {
|
|
77
|
-
var _this = this;
|
|
78
|
-
|
|
79
|
-
var _a;
|
|
80
|
-
|
|
81
|
-
this.actions = [];
|
|
82
|
-
this.activities = constants.EMPTY_ACTIVITY_MAP;
|
|
83
|
-
this.meta = {};
|
|
84
|
-
this.events = [];
|
|
85
|
-
this.value = config.value;
|
|
86
|
-
this.context = config.context;
|
|
87
|
-
this._event = config._event;
|
|
88
|
-
this._sessionid = config._sessionid;
|
|
89
|
-
this.event = this._event.data;
|
|
90
|
-
this.historyValue = config.historyValue;
|
|
91
|
-
this.history = config.history;
|
|
92
|
-
this.actions = config.actions || [];
|
|
93
|
-
this.activities = config.activities || constants.EMPTY_ACTIVITY_MAP;
|
|
94
|
-
this.meta = stateUtils.getMeta(config.configuration);
|
|
95
|
-
this.events = config.events || [];
|
|
96
|
-
this.matches = this.matches.bind(this);
|
|
97
|
-
this.toStrings = this.toStrings.bind(this);
|
|
98
|
-
this.configuration = config.configuration;
|
|
99
|
-
this.transitions = config.transitions;
|
|
100
|
-
this.children = config.children;
|
|
101
|
-
this.done = !!config.done;
|
|
102
|
-
this.tags = (_a = Array.isArray(config.tags) ? new Set(config.tags) : config.tags) !== null && _a !== void 0 ? _a : new Set();
|
|
103
|
-
this.machine = config.machine;
|
|
104
|
-
Object.defineProperty(this, 'nextEvents', {
|
|
105
|
-
get: function () {
|
|
106
|
-
return stateUtils.nextEvents(_this.configuration);
|
|
107
|
-
}
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Creates a new State instance for the given `stateValue` and `context`.
|
|
112
|
-
* @param stateValue
|
|
113
|
-
* @param context
|
|
114
|
-
*/
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
State.from = function (stateValue, context) {
|
|
118
|
-
if (stateValue instanceof State) {
|
|
119
|
-
if (stateValue.context !== context) {
|
|
120
|
-
return new State({
|
|
121
|
-
value: stateValue.value,
|
|
122
|
-
context: context,
|
|
123
|
-
_event: stateValue._event,
|
|
124
|
-
_sessionid: null,
|
|
125
|
-
historyValue: stateValue.historyValue,
|
|
126
|
-
history: stateValue.history,
|
|
127
|
-
actions: [],
|
|
128
|
-
activities: stateValue.activities,
|
|
129
|
-
meta: {},
|
|
130
|
-
events: [],
|
|
131
|
-
configuration: [],
|
|
132
|
-
transitions: [],
|
|
133
|
-
children: {}
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
return stateValue;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
var _event = actions.initEvent;
|
|
141
|
-
return new State({
|
|
142
|
-
value: stateValue,
|
|
143
|
-
context: context,
|
|
144
|
-
_event: _event,
|
|
145
|
-
_sessionid: null,
|
|
146
|
-
historyValue: undefined,
|
|
147
|
-
history: undefined,
|
|
148
|
-
actions: [],
|
|
149
|
-
activities: undefined,
|
|
150
|
-
meta: undefined,
|
|
151
|
-
events: [],
|
|
152
|
-
configuration: [],
|
|
153
|
-
transitions: [],
|
|
154
|
-
children: {}
|
|
155
|
-
});
|
|
156
|
-
};
|
|
157
|
-
/**
|
|
158
|
-
* Creates a new State instance for the given `config`.
|
|
159
|
-
* @param config The state config
|
|
160
|
-
*/
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
State.create = function (config) {
|
|
164
|
-
return new State(config);
|
|
165
|
-
};
|
|
166
|
-
/**
|
|
167
|
-
* Creates a new `State` instance for the given `stateValue` and `context` with no actions (side-effects).
|
|
168
|
-
* @param stateValue
|
|
169
|
-
* @param context
|
|
170
|
-
*/
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
State.inert = function (stateValue, context) {
|
|
174
|
-
if (stateValue instanceof State) {
|
|
175
|
-
if (!stateValue.actions.length) {
|
|
176
|
-
return stateValue;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
var _event = actions.initEvent;
|
|
180
|
-
return new State({
|
|
181
|
-
value: stateValue.value,
|
|
182
|
-
context: context,
|
|
183
|
-
_event: _event,
|
|
184
|
-
_sessionid: null,
|
|
185
|
-
historyValue: stateValue.historyValue,
|
|
186
|
-
history: stateValue.history,
|
|
187
|
-
activities: stateValue.activities,
|
|
188
|
-
configuration: stateValue.configuration,
|
|
189
|
-
transitions: [],
|
|
190
|
-
children: {}
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
return State.from(stateValue, context);
|
|
195
|
-
};
|
|
196
|
-
/**
|
|
197
|
-
* Returns an array of all the string leaf state node paths.
|
|
198
|
-
* @param stateValue
|
|
199
|
-
* @param delimiter The character(s) that separate each subpath in the string state node path.
|
|
200
|
-
*/
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
State.prototype.toStrings = function (stateValue, delimiter) {
|
|
204
|
-
var _this = this;
|
|
205
|
-
|
|
206
|
-
if (stateValue === void 0) {
|
|
207
|
-
stateValue = this.value;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
if (delimiter === void 0) {
|
|
211
|
-
delimiter = '.';
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
if (utils.isString(stateValue)) {
|
|
215
|
-
return [stateValue];
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
var valueKeys = Object.keys(stateValue);
|
|
219
|
-
return valueKeys.concat.apply(valueKeys, _tslib.__spreadArray([], _tslib.__read(valueKeys.map(function (key) {
|
|
220
|
-
return _this.toStrings(stateValue[key], delimiter).map(function (s) {
|
|
221
|
-
return key + delimiter + s;
|
|
222
|
-
});
|
|
223
|
-
})), false));
|
|
224
|
-
};
|
|
225
|
-
|
|
226
|
-
State.prototype.toJSON = function () {
|
|
227
|
-
var _a = this;
|
|
228
|
-
_a.configuration;
|
|
229
|
-
_a.transitions;
|
|
230
|
-
var tags = _a.tags;
|
|
231
|
-
_a.machine;
|
|
232
|
-
var jsonValues = _tslib.__rest(_a, ["configuration", "transitions", "tags", "machine"]);
|
|
233
|
-
|
|
234
|
-
return _tslib.__assign(_tslib.__assign({}, jsonValues), {
|
|
235
|
-
tags: Array.from(tags)
|
|
236
|
-
});
|
|
237
|
-
};
|
|
238
|
-
|
|
239
|
-
State.prototype.matches = function (parentStateValue) {
|
|
240
|
-
return utils.matchesState(parentStateValue, this.value);
|
|
241
|
-
};
|
|
242
|
-
/**
|
|
243
|
-
* Whether the current state configuration has a state node with the specified `tag`.
|
|
244
|
-
* @param tag
|
|
245
|
-
*/
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
State.prototype.hasTag = function (tag) {
|
|
249
|
-
return this.tags.has(tag);
|
|
250
|
-
};
|
|
251
|
-
/**
|
|
252
|
-
* Determines whether sending the `event` will cause a non-forbidden transition
|
|
253
|
-
* to be selected, even if the transitions have no actions nor
|
|
254
|
-
* change the state value.
|
|
255
|
-
*
|
|
256
|
-
* @param event The event to test
|
|
257
|
-
* @returns Whether the event will cause a transition
|
|
258
|
-
*/
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
State.prototype.can = function (event) {
|
|
262
|
-
var _a;
|
|
263
|
-
|
|
264
|
-
if (environment.IS_PRODUCTION) {
|
|
265
|
-
utils.warn(!!this.machine, "state.can(...) used outside of a machine-created State object; this will always return false.");
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
var transitionData = (_a = this.machine) === null || _a === void 0 ? void 0 : _a.getTransitionData(this, event);
|
|
269
|
-
return !!(transitionData === null || transitionData === void 0 ? void 0 : transitionData.transitions.length) && // Check that at least one transition is not forbidden
|
|
270
|
-
transitionData.transitions.some(function (t) {
|
|
271
|
-
return t.target !== undefined || t.actions.length;
|
|
272
|
-
});
|
|
273
|
-
};
|
|
274
|
-
|
|
275
|
-
return State;
|
|
276
|
-
}();
|
|
277
|
-
|
|
278
|
-
exports.State = State;
|
|
279
|
-
exports.bindActionToState = bindActionToState;
|
|
280
|
-
exports.isState = isState;
|
|
281
|
-
exports.isStateConfig = isStateConfig;
|
|
282
|
-
exports.stateValuesEqual = stateValuesEqual;
|
package/lib/StateNode.d.ts
DELETED
|
@@ -1,287 +0,0 @@
|
|
|
1
|
-
import { Event, StateValue, StateTransition, MachineOptions, EventObject, HistoryValue, StateNodeDefinition, TransitionDefinition, DelayedTransitionDefinition, ActivityDefinition, StateNodeConfig, StateSchema, StateNodesConfig, InvokeDefinition, ActionObject, Mapper, PropertyMapper, SCXML, Typestate, TransitionDefinitionMap, MachineSchema, InternalMachineOptions, ServiceMap, StateConfig } from './types';
|
|
2
|
-
import { State } from './State';
|
|
3
|
-
import { TypegenDisabled } from './typegenTypes';
|
|
4
|
-
declare class StateNode<TContext = any, TStateSchema extends StateSchema = any, TEvent extends EventObject = EventObject, TTypestate extends Typestate<TContext> = {
|
|
5
|
-
value: any;
|
|
6
|
-
context: TContext;
|
|
7
|
-
}, TServiceMap extends ServiceMap = ServiceMap, TResolvedTypesMeta = TypegenDisabled> {
|
|
8
|
-
/**
|
|
9
|
-
* The raw config used to create the machine.
|
|
10
|
-
*/
|
|
11
|
-
config: StateNodeConfig<TContext, TStateSchema, TEvent>;
|
|
12
|
-
/**
|
|
13
|
-
* The initial extended state
|
|
14
|
-
*/
|
|
15
|
-
private _context;
|
|
16
|
-
/**
|
|
17
|
-
* The relative key of the state node, which represents its location in the overall state value.
|
|
18
|
-
*/
|
|
19
|
-
key: string;
|
|
20
|
-
/**
|
|
21
|
-
* The unique ID of the state node.
|
|
22
|
-
*/
|
|
23
|
-
id: string;
|
|
24
|
-
/**
|
|
25
|
-
* The machine's own version.
|
|
26
|
-
*/
|
|
27
|
-
version?: string;
|
|
28
|
-
/**
|
|
29
|
-
* The type of this state node:
|
|
30
|
-
*
|
|
31
|
-
* - `'atomic'` - no child state nodes
|
|
32
|
-
* - `'compound'` - nested child state nodes (XOR)
|
|
33
|
-
* - `'parallel'` - orthogonal nested child state nodes (AND)
|
|
34
|
-
* - `'history'` - history state node
|
|
35
|
-
* - `'final'` - final state node
|
|
36
|
-
*/
|
|
37
|
-
type: 'atomic' | 'compound' | 'parallel' | 'final' | 'history';
|
|
38
|
-
/**
|
|
39
|
-
* The string path from the root machine node to this node.
|
|
40
|
-
*/
|
|
41
|
-
path: string[];
|
|
42
|
-
/**
|
|
43
|
-
* The initial state node key.
|
|
44
|
-
*/
|
|
45
|
-
initial?: keyof TStateSchema['states'];
|
|
46
|
-
/**
|
|
47
|
-
* (DEPRECATED) Whether the state node is a parallel state node.
|
|
48
|
-
*
|
|
49
|
-
* Use `type: 'parallel'` instead.
|
|
50
|
-
*/
|
|
51
|
-
parallel?: boolean;
|
|
52
|
-
/**
|
|
53
|
-
* Whether the state node is "transient". A state node is considered transient if it has
|
|
54
|
-
* an immediate transition from a "null event" (empty string), taken upon entering the state node.
|
|
55
|
-
*/
|
|
56
|
-
private _transient;
|
|
57
|
-
/**
|
|
58
|
-
* The child state nodes.
|
|
59
|
-
*/
|
|
60
|
-
states: StateNodesConfig<TContext, TStateSchema, TEvent>;
|
|
61
|
-
/**
|
|
62
|
-
* The type of history on this state node. Can be:
|
|
63
|
-
*
|
|
64
|
-
* - `'shallow'` - recalls only top-level historical state value
|
|
65
|
-
* - `'deep'` - recalls historical state value at all levels
|
|
66
|
-
*/
|
|
67
|
-
history: false | 'shallow' | 'deep';
|
|
68
|
-
/**
|
|
69
|
-
* The action(s) to be executed upon entering the state node.
|
|
70
|
-
*/
|
|
71
|
-
onEntry: Array<ActionObject<TContext, TEvent>>;
|
|
72
|
-
/**
|
|
73
|
-
* The action(s) to be executed upon exiting the state node.
|
|
74
|
-
*/
|
|
75
|
-
onExit: Array<ActionObject<TContext, TEvent>>;
|
|
76
|
-
/**
|
|
77
|
-
* The activities to be started upon entering the state node,
|
|
78
|
-
* and stopped upon exiting the state node.
|
|
79
|
-
*/
|
|
80
|
-
activities: Array<ActivityDefinition<TContext, TEvent>>;
|
|
81
|
-
strict: boolean;
|
|
82
|
-
/**
|
|
83
|
-
* The parent state node.
|
|
84
|
-
*/
|
|
85
|
-
parent?: StateNode<TContext, any, TEvent, any, any, any>;
|
|
86
|
-
/**
|
|
87
|
-
* The root machine node.
|
|
88
|
-
*/
|
|
89
|
-
machine: StateNode<TContext, any, TEvent, TTypestate>;
|
|
90
|
-
/**
|
|
91
|
-
* The meta data associated with this state node, which will be returned in State instances.
|
|
92
|
-
*/
|
|
93
|
-
meta?: TStateSchema extends {
|
|
94
|
-
meta: infer D;
|
|
95
|
-
} ? D : any;
|
|
96
|
-
/**
|
|
97
|
-
* The data sent with the "done.state._id_" event if this is a final state node.
|
|
98
|
-
*/
|
|
99
|
-
doneData?: Mapper<TContext, TEvent, any> | PropertyMapper<TContext, TEvent, any>;
|
|
100
|
-
/**
|
|
101
|
-
* The string delimiter for serializing the path to a string. The default is "."
|
|
102
|
-
*/
|
|
103
|
-
delimiter: string;
|
|
104
|
-
/**
|
|
105
|
-
* The order this state node appears. Corresponds to the implicit SCXML document order.
|
|
106
|
-
*/
|
|
107
|
-
order: number;
|
|
108
|
-
/**
|
|
109
|
-
* The services invoked by this state node.
|
|
110
|
-
*/
|
|
111
|
-
invoke: Array<InvokeDefinition<TContext, TEvent>>;
|
|
112
|
-
options: MachineOptions<TContext, TEvent>;
|
|
113
|
-
schema: MachineSchema<TContext, TEvent>;
|
|
114
|
-
__xstatenode: true;
|
|
115
|
-
description?: string;
|
|
116
|
-
private __cache;
|
|
117
|
-
private idMap;
|
|
118
|
-
tags: string[];
|
|
119
|
-
constructor(
|
|
120
|
-
/**
|
|
121
|
-
* The raw config used to create the machine.
|
|
122
|
-
*/
|
|
123
|
-
config: StateNodeConfig<TContext, TStateSchema, TEvent>, options?: MachineOptions<TContext, TEvent>,
|
|
124
|
-
/**
|
|
125
|
-
* The initial extended state
|
|
126
|
-
*/
|
|
127
|
-
_context?: Readonly<TContext> | (() => Readonly<TContext>), // TODO: this is unsafe, but we're removing it in v5 anyway
|
|
128
|
-
_stateInfo?: {
|
|
129
|
-
parent: StateNode<any, any, any, any, any, any>;
|
|
130
|
-
key: string;
|
|
131
|
-
});
|
|
132
|
-
private _init;
|
|
133
|
-
/**
|
|
134
|
-
* Clones this state machine with custom options and context.
|
|
135
|
-
*
|
|
136
|
-
* @param options Options (actions, guards, activities, services) to recursively merge with the existing options.
|
|
137
|
-
* @param context Custom context (will override predefined context)
|
|
138
|
-
*/
|
|
139
|
-
withConfig(options: InternalMachineOptions<TContext, TEvent, TResolvedTypesMeta, true>, context?: TContext | (() => TContext)): StateNode<TContext, TStateSchema, TEvent, TTypestate, TServiceMap, TResolvedTypesMeta>;
|
|
140
|
-
/**
|
|
141
|
-
* Clones this state machine with custom context.
|
|
142
|
-
*
|
|
143
|
-
* @param context Custom context (will override predefined context, not recursive)
|
|
144
|
-
*/
|
|
145
|
-
withContext(context: TContext | (() => TContext)): StateNode<TContext, TStateSchema, TEvent, TTypestate>;
|
|
146
|
-
get context(): TContext;
|
|
147
|
-
/**
|
|
148
|
-
* The well-structured state node definition.
|
|
149
|
-
*/
|
|
150
|
-
get definition(): StateNodeDefinition<TContext, TStateSchema, TEvent>;
|
|
151
|
-
toJSON(): StateNodeDefinition<TContext, TStateSchema, TEvent>;
|
|
152
|
-
/**
|
|
153
|
-
* The mapping of events to transitions.
|
|
154
|
-
*/
|
|
155
|
-
get on(): TransitionDefinitionMap<TContext, TEvent>;
|
|
156
|
-
get after(): Array<DelayedTransitionDefinition<TContext, TEvent>>;
|
|
157
|
-
/**
|
|
158
|
-
* All the transitions that can be taken from this state node.
|
|
159
|
-
*/
|
|
160
|
-
get transitions(): Array<TransitionDefinition<TContext, TEvent>>;
|
|
161
|
-
private getCandidates;
|
|
162
|
-
/**
|
|
163
|
-
* All delayed transitions from the config.
|
|
164
|
-
*/
|
|
165
|
-
private getDelayedTransitions;
|
|
166
|
-
/**
|
|
167
|
-
* Returns the state nodes represented by the current state value.
|
|
168
|
-
*
|
|
169
|
-
* @param state The state value or State instance
|
|
170
|
-
*/
|
|
171
|
-
getStateNodes(state: StateValue | State<TContext, TEvent, any, TTypestate, TResolvedTypesMeta>): Array<StateNode<TContext, any, TEvent, TTypestate, TServiceMap, TResolvedTypesMeta>>;
|
|
172
|
-
/**
|
|
173
|
-
* Returns `true` if this state node explicitly handles the given event.
|
|
174
|
-
*
|
|
175
|
-
* @param event The event in question
|
|
176
|
-
*/
|
|
177
|
-
handles(event: Event<TEvent>): boolean;
|
|
178
|
-
/**
|
|
179
|
-
* Resolves the given `state` to a new `State` instance relative to this machine.
|
|
180
|
-
*
|
|
181
|
-
* This ensures that `.events` and `.nextEvents` represent the correct values.
|
|
182
|
-
*
|
|
183
|
-
* @param state The state to resolve
|
|
184
|
-
*/
|
|
185
|
-
resolveState(state: State<TContext, TEvent, any, any> | StateConfig<TContext, TEvent>): State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>;
|
|
186
|
-
private transitionLeafNode;
|
|
187
|
-
private transitionCompoundNode;
|
|
188
|
-
private transitionParallelNode;
|
|
189
|
-
private _transition;
|
|
190
|
-
getTransitionData(state: State<TContext, TEvent, any, any, any>, event: Event<TEvent> | SCXML.Event<TEvent>): StateTransition<TContext, TEvent> | undefined;
|
|
191
|
-
private next;
|
|
192
|
-
private nodesFromChild;
|
|
193
|
-
/**
|
|
194
|
-
* Whether the given state node "escapes" this state node. If the `stateNode` is equal to or the parent of
|
|
195
|
-
* this state node, it does not escape.
|
|
196
|
-
*/
|
|
197
|
-
private escapes;
|
|
198
|
-
private getActions;
|
|
199
|
-
/**
|
|
200
|
-
* Determines the next state given the current `state` and sent `event`.
|
|
201
|
-
*
|
|
202
|
-
* @param state The current State instance or state value
|
|
203
|
-
* @param event The event that was sent at the current state
|
|
204
|
-
* @param context The current context (extended state) of the current state
|
|
205
|
-
*/
|
|
206
|
-
transition(state: StateValue | State<TContext, TEvent, any, TTypestate, TResolvedTypesMeta> | undefined, event: Event<TEvent> | SCXML.Event<TEvent>, context?: TContext): State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>;
|
|
207
|
-
private resolveRaisedTransition;
|
|
208
|
-
private resolveTransition;
|
|
209
|
-
/**
|
|
210
|
-
* Returns the child state node from its relative `stateKey`, or throws.
|
|
211
|
-
*/
|
|
212
|
-
getStateNode(stateKey: string): StateNode<TContext, any, TEvent, TTypestate, TServiceMap, TResolvedTypesMeta>;
|
|
213
|
-
/**
|
|
214
|
-
* Returns the state node with the given `stateId`, or throws.
|
|
215
|
-
*
|
|
216
|
-
* @param stateId The state ID. The prefix "#" is removed.
|
|
217
|
-
*/
|
|
218
|
-
getStateNodeById(stateId: string): StateNode<TContext, any, TEvent, any, TServiceMap, TResolvedTypesMeta>;
|
|
219
|
-
/**
|
|
220
|
-
* Returns the relative state node from the given `statePath`, or throws.
|
|
221
|
-
*
|
|
222
|
-
* @param statePath The string or string array relative path to the state node.
|
|
223
|
-
*/
|
|
224
|
-
getStateNodeByPath(statePath: string | string[]): StateNode<TContext, any, TEvent, any, any, any>;
|
|
225
|
-
/**
|
|
226
|
-
* Resolves a partial state value with its full representation in this machine.
|
|
227
|
-
*
|
|
228
|
-
* @param stateValue The partial state value to resolve.
|
|
229
|
-
*/
|
|
230
|
-
resolve(stateValue: StateValue): StateValue;
|
|
231
|
-
private getResolvedPath;
|
|
232
|
-
private get initialStateValue();
|
|
233
|
-
getInitialState(stateValue: StateValue, context?: TContext): State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>;
|
|
234
|
-
/**
|
|
235
|
-
* The initial State instance, which includes all actions to be executed from
|
|
236
|
-
* entering the initial state.
|
|
237
|
-
*/
|
|
238
|
-
get initialState(): State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>;
|
|
239
|
-
/**
|
|
240
|
-
* The target state value of the history state node, if it exists. This represents the
|
|
241
|
-
* default state value to transition to if no history value exists yet.
|
|
242
|
-
*/
|
|
243
|
-
get target(): StateValue | undefined;
|
|
244
|
-
/**
|
|
245
|
-
* Returns the leaf nodes from a state path relative to this state node.
|
|
246
|
-
*
|
|
247
|
-
* @param relativeStateId The relative state path to retrieve the state nodes
|
|
248
|
-
* @param history The previous state to retrieve history
|
|
249
|
-
* @param resolve Whether state nodes should resolve to initial child state nodes
|
|
250
|
-
*/
|
|
251
|
-
getRelativeStateNodes(relativeStateId: StateNode<TContext, any, TEvent>, historyValue?: HistoryValue, resolve?: boolean): Array<StateNode<TContext, any, TEvent>>;
|
|
252
|
-
get initialStateNodes(): Array<StateNode<TContext, any, TEvent, any, any, any>>;
|
|
253
|
-
/**
|
|
254
|
-
* Retrieves state nodes from a relative path to this state node.
|
|
255
|
-
*
|
|
256
|
-
* @param relativePath The relative path from this state node
|
|
257
|
-
* @param historyValue
|
|
258
|
-
*/
|
|
259
|
-
getFromRelativePath(relativePath: string[]): Array<StateNode<TContext, any, TEvent, any, any, any>>;
|
|
260
|
-
private historyValue;
|
|
261
|
-
/**
|
|
262
|
-
* Resolves to the historical value(s) of the parent state node,
|
|
263
|
-
* represented by state nodes.
|
|
264
|
-
*
|
|
265
|
-
* @param historyValue
|
|
266
|
-
*/
|
|
267
|
-
private resolveHistory;
|
|
268
|
-
/**
|
|
269
|
-
* All the state node IDs of this state node and its descendant state nodes.
|
|
270
|
-
*/
|
|
271
|
-
get stateIds(): string[];
|
|
272
|
-
/**
|
|
273
|
-
* All the event types accepted by this state node and its descendants.
|
|
274
|
-
*/
|
|
275
|
-
get events(): Array<TEvent['type']>;
|
|
276
|
-
/**
|
|
277
|
-
* All the events that have transitions directly from this state node.
|
|
278
|
-
*
|
|
279
|
-
* Excludes any inert events.
|
|
280
|
-
*/
|
|
281
|
-
get ownEvents(): Array<TEvent['type']>;
|
|
282
|
-
private resolveTarget;
|
|
283
|
-
private formatTransition;
|
|
284
|
-
private formatTransitions;
|
|
285
|
-
}
|
|
286
|
-
export { StateNode };
|
|
287
|
-
//# sourceMappingURL=StateNode.d.ts.map
|