xstate 5.0.0-beta.9 → 5.0.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 +10 -8
- package/actions/dist/xstate-actions.cjs.js +19 -5
- package/actions/dist/xstate-actions.cjs.mjs +3 -15
- package/actions/dist/xstate-actions.development.cjs.js +21 -0
- package/actions/dist/xstate-actions.development.cjs.mjs +13 -0
- package/actions/dist/xstate-actions.development.esm.js +3 -0
- package/actions/dist/xstate-actions.esm.js +3 -2
- package/actions/dist/xstate-actions.umd.min.js +1 -1
- package/actions/dist/xstate-actions.umd.min.js.map +1 -1
- package/actors/dist/xstate-actors.cjs.js +621 -4
- package/actors/dist/xstate-actors.cjs.mjs +1 -8
- package/actors/dist/xstate-actors.development.cjs.js +624 -0
- package/actors/dist/xstate-actors.development.cjs.mjs +8 -0
- package/actors/dist/xstate-actors.development.esm.js +615 -0
- package/actors/dist/xstate-actors.esm.js +615 -2
- package/actors/dist/xstate-actors.umd.min.js +1 -1
- package/actors/dist/xstate-actors.umd.min.js.map +1 -1
- package/dev/dist/xstate-dev.cjs.js +45 -4
- package/{dist/index-0f3fdf0c.cjs.prod.js → dev/dist/xstate-dev.development.cjs.js} +6 -7
- package/dev/dist/xstate-dev.development.cjs.mjs +5 -0
- package/{dist/index-50bd0aff.esm.js → dev/dist/xstate-dev.development.esm.js} +6 -8
- package/dev/dist/xstate-dev.esm.js +42 -1
- package/dev/dist/xstate-dev.umd.min.js +1 -1
- package/dev/dist/xstate-dev.umd.min.js.map +1 -1
- package/dist/declarations/src/SimulatedClock.d.ts +1 -1
- package/dist/declarations/src/State.d.ts +47 -73
- package/dist/declarations/src/StateMachine.d.ts +29 -57
- package/dist/declarations/src/StateNode.d.ts +36 -33
- package/dist/declarations/src/actions/assign.d.ts +11 -2
- package/dist/declarations/src/actions/cancel.d.ts +7 -3
- package/dist/declarations/src/actions/enqueueActions.d.ts +32 -0
- package/dist/declarations/src/actions/log.d.ts +7 -3
- package/dist/declarations/src/actions/raise.d.ts +7 -2
- package/dist/declarations/src/actions/send.d.ts +14 -36
- package/dist/declarations/src/actions/spawnChild.d.ts +29 -0
- package/dist/declarations/src/actions/stopChild.d.ts +18 -0
- package/dist/declarations/src/actions.d.ts +8 -48
- package/dist/declarations/src/actors/callback.d.ts +91 -8
- package/dist/declarations/src/actors/index.d.ts +6 -28
- package/dist/declarations/src/actors/observable.d.ts +101 -18
- package/dist/declarations/src/actors/promise.d.ts +80 -10
- package/dist/declarations/src/actors/transition.d.ts +64 -9
- package/dist/declarations/src/constants.d.ts +3 -0
- package/dist/declarations/src/createMachine.d.ts +20 -0
- package/dist/declarations/src/dev/index.d.ts +6 -6
- package/dist/declarations/src/guards.d.ts +41 -8
- package/dist/declarations/src/index.d.ts +18 -23
- package/dist/declarations/src/interpreter.d.ts +149 -41
- package/dist/declarations/src/setup.d.ts +51 -0
- package/dist/declarations/src/spawn.d.ts +23 -2
- package/dist/declarations/src/stateUtils.d.ts +30 -45
- package/dist/declarations/src/system.d.ts +26 -2
- package/dist/declarations/src/typegenTypes.d.ts +34 -22
- package/dist/declarations/src/types.d.ts +527 -669
- package/dist/declarations/src/utils.d.ts +15 -52
- package/dist/declarations/src/waitFor.d.ts +2 -2
- package/dist/log-22e678c5.esm.js +364 -0
- package/dist/log-5e226275.cjs.js +372 -0
- package/dist/log-641cd926.development.cjs.js +394 -0
- package/dist/log-f196f85f.development.esm.js +386 -0
- package/dist/raise-34e25c2c.cjs.js +2368 -0
- package/dist/raise-62704519.development.cjs.js +2422 -0
- package/dist/raise-89c581c4.development.esm.js +2371 -0
- package/dist/raise-8bc422d1.esm.js +2317 -0
- package/dist/xstate.cjs.js +728 -4
- package/dist/xstate.cjs.mjs +9 -9
- package/dist/xstate.development.cjs.js +737 -0
- package/dist/xstate.development.cjs.mjs +39 -0
- package/dist/xstate.development.esm.js +699 -0
- package/dist/xstate.esm.js +561 -770
- package/dist/xstate.umd.min.js +1 -1
- package/dist/xstate.umd.min.js.map +1 -1
- package/guards/dist/xstate-guards.cjs.js +12 -5
- package/guards/dist/xstate-guards.cjs.mjs +1 -2
- package/guards/dist/xstate-guards.development.cjs.js +14 -0
- package/guards/dist/xstate-guards.development.cjs.mjs +7 -0
- package/guards/dist/xstate-guards.development.esm.js +2 -0
- package/guards/dist/xstate-guards.esm.js +2 -2
- package/guards/dist/xstate-guards.umd.min.js +1 -1
- package/guards/dist/xstate-guards.umd.min.js.map +1 -1
- package/package.json +53 -1
- package/actions/dist/xstate-actions.cjs.dev.js +0 -32
- package/actions/dist/xstate-actions.cjs.prod.js +0 -32
- package/actions/dynamicAction.ts +0 -42
- package/actors/dist/xstate-actors.cjs.dev.js +0 -22
- package/actors/dist/xstate-actors.cjs.prod.js +0 -22
- package/dev/dist/xstate-dev.cjs.dev.js +0 -11
- package/dev/dist/xstate-dev.cjs.prod.js +0 -11
- package/dist/actions-b6357569.cjs.dev.js +0 -4437
- package/dist/actions-bd4a184d.cjs.prod.js +0 -4423
- package/dist/actions-de434a04.esm.js +0 -4348
- package/dist/declarations/actions/dynamicAction.d.ts +0 -5
- package/dist/declarations/src/Machine.d.ts +0 -4
- package/dist/declarations/src/Mailbox.d.ts +0 -12
- package/dist/declarations/src/actionTypes.d.ts +0 -16
- package/dist/declarations/src/actions/choose.d.ts +0 -3
- package/dist/declarations/src/actions/invoke.d.ts +0 -3
- package/dist/declarations/src/actions/pure.d.ts +0 -6
- package/dist/declarations/src/actions/stop.d.ts +0 -7
- package/dist/declarations/src/environment.d.ts +0 -1
- package/dist/declarations/src/mapState.d.ts +0 -3
- package/dist/declarations/src/memo.d.ts +0 -2
- package/dist/index-ebaab3c9.cjs.dev.js +0 -52
- package/dist/xstate.cjs.dev.js +0 -950
- package/dist/xstate.cjs.prod.js +0 -947
- package/guards/dist/xstate-guards.cjs.dev.js +0 -15
- package/guards/dist/xstate-guards.cjs.prod.js +0 -15
package/dist/xstate.cjs.prod.js
DELETED
|
@@ -1,947 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var actors_dist_xstateActors = require('./actions-bd4a184d.cjs.prod.js');
|
|
6
|
-
require('./index-0f3fdf0c.cjs.prod.js');
|
|
7
|
-
|
|
8
|
-
var _excluded = ["onDone", "onError"];
|
|
9
|
-
var EMPTY_OBJECT = {};
|
|
10
|
-
var StateNode = /*#__PURE__*/function () {
|
|
11
|
-
/**
|
|
12
|
-
* The relative key of the state node, which represents its location in the overall state value.
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* The unique ID of the state node.
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* The type of this state node:
|
|
21
|
-
*
|
|
22
|
-
* - `'atomic'` - no child state nodes
|
|
23
|
-
* - `'compound'` - nested child state nodes (XOR)
|
|
24
|
-
* - `'parallel'` - orthogonal nested child state nodes (AND)
|
|
25
|
-
* - `'history'` - history state node
|
|
26
|
-
* - `'final'` - final state node
|
|
27
|
-
*/
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* The string path from the root machine node to this node.
|
|
31
|
-
*/
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* The child state nodes.
|
|
35
|
-
*/
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* The type of history on this state node. Can be:
|
|
39
|
-
*
|
|
40
|
-
* - `'shallow'` - recalls only top-level historical state value
|
|
41
|
-
* - `'deep'` - recalls historical state value at all levels
|
|
42
|
-
*/
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* The action(s) to be executed upon entering the state node.
|
|
46
|
-
*/
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* The action(s) to be executed upon exiting the state node.
|
|
50
|
-
*/
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* The parent state node.
|
|
54
|
-
*/
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* The root machine node.
|
|
58
|
-
*/
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* The meta data associated with this state node, which will be returned in State instances.
|
|
62
|
-
*/
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* The output data sent with the "done.state._id_" event if this is a final state node.
|
|
66
|
-
*/
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* The order this state node appears. Corresponds to the implicit SCXML document order.
|
|
70
|
-
*/
|
|
71
|
-
|
|
72
|
-
function StateNode(
|
|
73
|
-
/**
|
|
74
|
-
* The raw config used to create the machine.
|
|
75
|
-
*/
|
|
76
|
-
config, options) {
|
|
77
|
-
var _this = this;
|
|
78
|
-
actors_dist_xstateActors._classCallCheck(this, StateNode);
|
|
79
|
-
this.config = config;
|
|
80
|
-
actors_dist_xstateActors._defineProperty(this, "key", void 0);
|
|
81
|
-
actors_dist_xstateActors._defineProperty(this, "id", void 0);
|
|
82
|
-
actors_dist_xstateActors._defineProperty(this, "type", void 0);
|
|
83
|
-
actors_dist_xstateActors._defineProperty(this, "path", void 0);
|
|
84
|
-
actors_dist_xstateActors._defineProperty(this, "states", void 0);
|
|
85
|
-
actors_dist_xstateActors._defineProperty(this, "history", void 0);
|
|
86
|
-
actors_dist_xstateActors._defineProperty(this, "entry", void 0);
|
|
87
|
-
actors_dist_xstateActors._defineProperty(this, "exit", void 0);
|
|
88
|
-
actors_dist_xstateActors._defineProperty(this, "parent", void 0);
|
|
89
|
-
actors_dist_xstateActors._defineProperty(this, "machine", void 0);
|
|
90
|
-
actors_dist_xstateActors._defineProperty(this, "meta", void 0);
|
|
91
|
-
actors_dist_xstateActors._defineProperty(this, "output", void 0);
|
|
92
|
-
actors_dist_xstateActors._defineProperty(this, "order", -1);
|
|
93
|
-
actors_dist_xstateActors._defineProperty(this, "description", void 0);
|
|
94
|
-
actors_dist_xstateActors._defineProperty(this, "tags", []);
|
|
95
|
-
actors_dist_xstateActors._defineProperty(this, "transitions", void 0);
|
|
96
|
-
actors_dist_xstateActors._defineProperty(this, "always", void 0);
|
|
97
|
-
this.parent = options._parent;
|
|
98
|
-
this.key = options._key;
|
|
99
|
-
this.machine = options._machine;
|
|
100
|
-
this.path = this.parent ? this.parent.path.concat(this.key) : [];
|
|
101
|
-
this.id = this.config.id || [this.machine.id].concat(actors_dist_xstateActors._toConsumableArray(this.path)).join(this.machine.delimiter);
|
|
102
|
-
this.type = this.config.type || (this.config.states && Object.keys(this.config.states).length ? 'compound' : this.config.history ? 'history' : 'atomic');
|
|
103
|
-
this.description = this.config.description;
|
|
104
|
-
this.order = this.machine.idMap.size;
|
|
105
|
-
this.machine.idMap.set(this.id, this);
|
|
106
|
-
this.states = this.config.states ? actors_dist_xstateActors.mapValues(this.config.states, function (stateConfig, key) {
|
|
107
|
-
var stateNode = new StateNode(stateConfig, {
|
|
108
|
-
_parent: _this,
|
|
109
|
-
_key: key,
|
|
110
|
-
_machine: _this.machine
|
|
111
|
-
});
|
|
112
|
-
return stateNode;
|
|
113
|
-
}) : EMPTY_OBJECT;
|
|
114
|
-
if (this.type === 'compound' && !this.config.initial) {
|
|
115
|
-
throw new Error("No initial state specified for compound state node \"#".concat(this.id, "\". Try adding { initial: \"").concat(Object.keys(this.states)[0], "\" } to the state config."));
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
// History config
|
|
119
|
-
this.history = this.config.history === true ? 'shallow' : this.config.history || false;
|
|
120
|
-
this.entry = actors_dist_xstateActors.toActionObjects(this.config.entry);
|
|
121
|
-
this.exit = actors_dist_xstateActors.toActionObjects(this.config.exit);
|
|
122
|
-
this.meta = this.config.meta;
|
|
123
|
-
this.output = this.type === 'final' ? this.config.output : undefined;
|
|
124
|
-
this.tags = actors_dist_xstateActors.toArray(config.tags);
|
|
125
|
-
}
|
|
126
|
-
actors_dist_xstateActors._createClass(StateNode, [{
|
|
127
|
-
key: "_initialize",
|
|
128
|
-
value: function _initialize() {
|
|
129
|
-
var _this2 = this;
|
|
130
|
-
this.transitions = actors_dist_xstateActors.formatTransitions(this);
|
|
131
|
-
if (this.config.always) {
|
|
132
|
-
this.always = actors_dist_xstateActors.toTransitionConfigArray(actors_dist_xstateActors.NULL_EVENT, this.config.always).map(function (t) {
|
|
133
|
-
return actors_dist_xstateActors.formatTransition(_this2, t);
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
Object.keys(this.states).forEach(function (key) {
|
|
137
|
-
_this2.states[key]._initialize();
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* The well-structured state node definition.
|
|
143
|
-
*/
|
|
144
|
-
}, {
|
|
145
|
-
key: "definition",
|
|
146
|
-
get: function get() {
|
|
147
|
-
var _this3 = this;
|
|
148
|
-
return {
|
|
149
|
-
id: this.id,
|
|
150
|
-
key: this.key,
|
|
151
|
-
version: this.machine.version,
|
|
152
|
-
type: this.type,
|
|
153
|
-
initial: this.initial ? {
|
|
154
|
-
target: this.initial.target,
|
|
155
|
-
source: this,
|
|
156
|
-
actions: this.initial.actions,
|
|
157
|
-
eventType: null,
|
|
158
|
-
reenter: false,
|
|
159
|
-
toJSON: function toJSON() {
|
|
160
|
-
return {
|
|
161
|
-
target: _this3.initial.target.map(function (t) {
|
|
162
|
-
return "#".concat(t.id);
|
|
163
|
-
}),
|
|
164
|
-
source: "#".concat(_this3.id),
|
|
165
|
-
actions: _this3.initial.actions,
|
|
166
|
-
eventType: null
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
} : undefined,
|
|
170
|
-
history: this.history,
|
|
171
|
-
states: actors_dist_xstateActors.mapValues(this.states, function (state) {
|
|
172
|
-
return state.definition;
|
|
173
|
-
}),
|
|
174
|
-
on: this.on,
|
|
175
|
-
transitions: this.transitions,
|
|
176
|
-
entry: this.entry,
|
|
177
|
-
exit: this.exit,
|
|
178
|
-
meta: this.meta,
|
|
179
|
-
order: this.order || -1,
|
|
180
|
-
output: this.output,
|
|
181
|
-
invoke: this.invoke,
|
|
182
|
-
description: this.description,
|
|
183
|
-
tags: this.tags
|
|
184
|
-
};
|
|
185
|
-
}
|
|
186
|
-
}, {
|
|
187
|
-
key: "toJSON",
|
|
188
|
-
value: function toJSON() {
|
|
189
|
-
return this.definition;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
/**
|
|
193
|
-
* The behaviors invoked as actors by this state node.
|
|
194
|
-
*/
|
|
195
|
-
}, {
|
|
196
|
-
key: "invoke",
|
|
197
|
-
get: function get() {
|
|
198
|
-
var _this4 = this;
|
|
199
|
-
return actors_dist_xstateActors.memo(this, 'invoke', function () {
|
|
200
|
-
return actors_dist_xstateActors.toArray(_this4.config.invoke).map(function (invocable, i) {
|
|
201
|
-
var generatedId = actors_dist_xstateActors.createInvokeId(_this4.id, i);
|
|
202
|
-
var invokeConfig = actors_dist_xstateActors.toInvokeConfig(invocable, generatedId);
|
|
203
|
-
var resolvedId = invokeConfig.id || generatedId;
|
|
204
|
-
var src = invokeConfig.src,
|
|
205
|
-
systemId = invokeConfig.systemId;
|
|
206
|
-
var resolvedSrc = actors_dist_xstateActors.isString(src) ? src : !('type' in src) ? resolvedId : src;
|
|
207
|
-
if (!_this4.machine.options.actors[resolvedId] && typeof src !== 'string' && !('type' in src)) {
|
|
208
|
-
_this4.machine.options.actors = actors_dist_xstateActors._objectSpread2(actors_dist_xstateActors._objectSpread2({}, _this4.machine.options.actors), {}, actors_dist_xstateActors._defineProperty({}, resolvedId, src));
|
|
209
|
-
}
|
|
210
|
-
return actors_dist_xstateActors._objectSpread2(actors_dist_xstateActors._objectSpread2({
|
|
211
|
-
type: actors_dist_xstateActors.invoke
|
|
212
|
-
}, invokeConfig), {}, {
|
|
213
|
-
src: resolvedSrc,
|
|
214
|
-
id: resolvedId,
|
|
215
|
-
systemId: systemId,
|
|
216
|
-
toJSON: function toJSON() {
|
|
217
|
-
invokeConfig.onDone;
|
|
218
|
-
invokeConfig.onError;
|
|
219
|
-
var invokeDefValues = actors_dist_xstateActors._objectWithoutProperties(invokeConfig, _excluded);
|
|
220
|
-
return actors_dist_xstateActors._objectSpread2(actors_dist_xstateActors._objectSpread2({}, invokeDefValues), {}, {
|
|
221
|
-
type: actors_dist_xstateActors.invoke,
|
|
222
|
-
src: resolvedSrc,
|
|
223
|
-
id: resolvedId
|
|
224
|
-
});
|
|
225
|
-
}
|
|
226
|
-
});
|
|
227
|
-
});
|
|
228
|
-
});
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
/**
|
|
232
|
-
* The mapping of events to transitions.
|
|
233
|
-
*/
|
|
234
|
-
}, {
|
|
235
|
-
key: "on",
|
|
236
|
-
get: function get() {
|
|
237
|
-
var _this5 = this;
|
|
238
|
-
return actors_dist_xstateActors.memo(this, 'on', function () {
|
|
239
|
-
var transitions = _this5.transitions;
|
|
240
|
-
return transitions.reduce(function (map, transition) {
|
|
241
|
-
map[transition.eventType] = map[transition.eventType] || [];
|
|
242
|
-
map[transition.eventType].push(transition);
|
|
243
|
-
return map;
|
|
244
|
-
}, {});
|
|
245
|
-
});
|
|
246
|
-
}
|
|
247
|
-
}, {
|
|
248
|
-
key: "after",
|
|
249
|
-
get: function get() {
|
|
250
|
-
var _this6 = this;
|
|
251
|
-
return actors_dist_xstateActors.memo(this, 'delayedTransitions', function () {
|
|
252
|
-
return actors_dist_xstateActors.getDelayedTransitions(_this6);
|
|
253
|
-
});
|
|
254
|
-
}
|
|
255
|
-
}, {
|
|
256
|
-
key: "initial",
|
|
257
|
-
get: function get() {
|
|
258
|
-
var _this7 = this;
|
|
259
|
-
return actors_dist_xstateActors.memo(this, 'initial', function () {
|
|
260
|
-
return actors_dist_xstateActors.formatInitialTransition(_this7, _this7.config.initial || []);
|
|
261
|
-
});
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
/**
|
|
265
|
-
* Returns `true` if this state node explicitly handles the given event.
|
|
266
|
-
*
|
|
267
|
-
* @param event The event in question
|
|
268
|
-
*/
|
|
269
|
-
}, {
|
|
270
|
-
key: "handles",
|
|
271
|
-
value: function handles(event) {
|
|
272
|
-
return this.events.includes(event.type);
|
|
273
|
-
}
|
|
274
|
-
}, {
|
|
275
|
-
key: "next",
|
|
276
|
-
value: function next(state, _event) {
|
|
277
|
-
var _this8 = this;
|
|
278
|
-
var eventName = _event.name;
|
|
279
|
-
var actions = [];
|
|
280
|
-
var selectedTransition;
|
|
281
|
-
var candidates = actors_dist_xstateActors.memo(this, "candidates-".concat(eventName.toString()), function () {
|
|
282
|
-
return actors_dist_xstateActors.getCandidates(_this8, eventName, _this8.machine.config.scxml // Whether token matching should be used
|
|
283
|
-
);
|
|
284
|
-
});
|
|
285
|
-
var _iterator = actors_dist_xstateActors._createForOfIteratorHelper(candidates),
|
|
286
|
-
_step;
|
|
287
|
-
try {
|
|
288
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
289
|
-
var candidate = _step.value;
|
|
290
|
-
var guard = candidate.guard;
|
|
291
|
-
var resolvedContext = state.context;
|
|
292
|
-
var guardPassed = false;
|
|
293
|
-
try {
|
|
294
|
-
guardPassed = !guard || actors_dist_xstateActors.evaluateGuard(guard, resolvedContext, _event, state);
|
|
295
|
-
} catch (err) {
|
|
296
|
-
throw new Error("Unable to evaluate guard '".concat(guard.type, "' in transition for event '").concat(eventName, "' in state node '").concat(this.id, "':\n").concat(err.message));
|
|
297
|
-
}
|
|
298
|
-
if (guardPassed) {
|
|
299
|
-
actions.push.apply(actions, actors_dist_xstateActors._toConsumableArray(candidate.actions));
|
|
300
|
-
selectedTransition = candidate;
|
|
301
|
-
break;
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
} catch (err) {
|
|
305
|
-
_iterator.e(err);
|
|
306
|
-
} finally {
|
|
307
|
-
_iterator.f();
|
|
308
|
-
}
|
|
309
|
-
return selectedTransition ? [selectedTransition] : undefined;
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
/**
|
|
313
|
-
* The target state value of the history state node, if it exists. This represents the
|
|
314
|
-
* default state value to transition to if no history value exists yet.
|
|
315
|
-
*/
|
|
316
|
-
}, {
|
|
317
|
-
key: "target",
|
|
318
|
-
get: function get() {
|
|
319
|
-
if (this.type === 'history') {
|
|
320
|
-
var historyConfig = this.config;
|
|
321
|
-
return historyConfig.target;
|
|
322
|
-
}
|
|
323
|
-
return undefined;
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
/**
|
|
327
|
-
* All the state node IDs of this state node and its descendant state nodes.
|
|
328
|
-
*/
|
|
329
|
-
}, {
|
|
330
|
-
key: "stateIds",
|
|
331
|
-
get: function get() {
|
|
332
|
-
var _this9 = this;
|
|
333
|
-
var childStateIds = actors_dist_xstateActors.flatten(Object.keys(this.states).map(function (stateKey) {
|
|
334
|
-
return _this9.states[stateKey].stateIds;
|
|
335
|
-
}));
|
|
336
|
-
return [this.id].concat(childStateIds);
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
/**
|
|
340
|
-
* All the event types accepted by this state node and its descendants.
|
|
341
|
-
*/
|
|
342
|
-
}, {
|
|
343
|
-
key: "events",
|
|
344
|
-
get: function get() {
|
|
345
|
-
var _this10 = this;
|
|
346
|
-
return actors_dist_xstateActors.memo(this, 'events', function () {
|
|
347
|
-
var states = _this10.states;
|
|
348
|
-
var events = new Set(_this10.ownEvents);
|
|
349
|
-
if (states) {
|
|
350
|
-
for (var _i = 0, _Object$keys = Object.keys(states); _i < _Object$keys.length; _i++) {
|
|
351
|
-
var stateId = _Object$keys[_i];
|
|
352
|
-
var state = states[stateId];
|
|
353
|
-
if (state.states) {
|
|
354
|
-
var _iterator2 = actors_dist_xstateActors._createForOfIteratorHelper(state.events),
|
|
355
|
-
_step2;
|
|
356
|
-
try {
|
|
357
|
-
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
358
|
-
var event = _step2.value;
|
|
359
|
-
events.add("".concat(event));
|
|
360
|
-
}
|
|
361
|
-
} catch (err) {
|
|
362
|
-
_iterator2.e(err);
|
|
363
|
-
} finally {
|
|
364
|
-
_iterator2.f();
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
return Array.from(events);
|
|
370
|
-
});
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
/**
|
|
374
|
-
* All the events that have transitions directly from this state node.
|
|
375
|
-
*
|
|
376
|
-
* Excludes any inert events.
|
|
377
|
-
*/
|
|
378
|
-
}, {
|
|
379
|
-
key: "ownEvents",
|
|
380
|
-
get: function get() {
|
|
381
|
-
var events = new Set(this.transitions.filter(function (transition) {
|
|
382
|
-
return !(!transition.target && !transition.actions.length && !transition.reenter);
|
|
383
|
-
}).map(function (transition) {
|
|
384
|
-
return transition.eventType;
|
|
385
|
-
}));
|
|
386
|
-
return Array.from(events);
|
|
387
|
-
}
|
|
388
|
-
}]);
|
|
389
|
-
return StateNode;
|
|
390
|
-
}();
|
|
391
|
-
|
|
392
|
-
var STATE_IDENTIFIER = '#';
|
|
393
|
-
function createDefaultOptions() {
|
|
394
|
-
return {
|
|
395
|
-
actions: {},
|
|
396
|
-
actors: {},
|
|
397
|
-
delays: {},
|
|
398
|
-
guards: {},
|
|
399
|
-
context: {}
|
|
400
|
-
};
|
|
401
|
-
}
|
|
402
|
-
var StateMachine = /*#__PURE__*/function () {
|
|
403
|
-
function StateMachine(
|
|
404
|
-
/**
|
|
405
|
-
* The raw config used to create the machine.
|
|
406
|
-
*/
|
|
407
|
-
config, options) {
|
|
408
|
-
var _this$config$types;
|
|
409
|
-
actors_dist_xstateActors._classCallCheck(this, StateMachine);
|
|
410
|
-
this.config = config;
|
|
411
|
-
actors_dist_xstateActors._defineProperty(this, "version", void 0);
|
|
412
|
-
actors_dist_xstateActors._defineProperty(this, "delimiter", void 0);
|
|
413
|
-
actors_dist_xstateActors._defineProperty(this, "options", void 0);
|
|
414
|
-
actors_dist_xstateActors._defineProperty(this, "types", void 0);
|
|
415
|
-
actors_dist_xstateActors._defineProperty(this, "__xstatenode", true);
|
|
416
|
-
actors_dist_xstateActors._defineProperty(this, "idMap", new Map());
|
|
417
|
-
actors_dist_xstateActors._defineProperty(this, "root", void 0);
|
|
418
|
-
actors_dist_xstateActors._defineProperty(this, "id", void 0);
|
|
419
|
-
actors_dist_xstateActors._defineProperty(this, "states", void 0);
|
|
420
|
-
actors_dist_xstateActors._defineProperty(this, "events", void 0);
|
|
421
|
-
actors_dist_xstateActors._defineProperty(this, "__TContext", void 0);
|
|
422
|
-
actors_dist_xstateActors._defineProperty(this, "__TEvent", void 0);
|
|
423
|
-
actors_dist_xstateActors._defineProperty(this, "__TAction", void 0);
|
|
424
|
-
actors_dist_xstateActors._defineProperty(this, "__TActorMap", void 0);
|
|
425
|
-
actors_dist_xstateActors._defineProperty(this, "__TResolvedTypesMeta", void 0);
|
|
426
|
-
this.id = config.id || '(machine)';
|
|
427
|
-
this.options = Object.assign(createDefaultOptions(), options);
|
|
428
|
-
this.delimiter = this.config.delimiter || actors_dist_xstateActors.STATE_DELIMITER;
|
|
429
|
-
this.version = this.config.version;
|
|
430
|
-
this.types = (_this$config$types = this.config.types) !== null && _this$config$types !== void 0 ? _this$config$types : {};
|
|
431
|
-
this.transition = this.transition.bind(this);
|
|
432
|
-
this.root = new StateNode(config, {
|
|
433
|
-
_key: this.id,
|
|
434
|
-
_machine: this
|
|
435
|
-
});
|
|
436
|
-
this.root._initialize();
|
|
437
|
-
this.states = this.root.states; // TODO: remove!
|
|
438
|
-
this.events = this.root.events;
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
/**
|
|
442
|
-
* Clones this state machine with the provided implementations
|
|
443
|
-
* and merges the `context` (if provided).
|
|
444
|
-
*
|
|
445
|
-
* @param implementations Options (`actions`, `guards`, `actors`, `delays`, `context`)
|
|
446
|
-
* to recursively merge with the existing options.
|
|
447
|
-
*
|
|
448
|
-
* @returns A new `StateMachine` instance with the provided implementations.
|
|
449
|
-
*/
|
|
450
|
-
actors_dist_xstateActors._createClass(StateMachine, [{
|
|
451
|
-
key: "getContext",
|
|
452
|
-
value:
|
|
453
|
-
// TODO: this getter should be removed
|
|
454
|
-
function getContext(input) {
|
|
455
|
-
return this.getContextAndActions(undefined, input)[0];
|
|
456
|
-
}
|
|
457
|
-
}, {
|
|
458
|
-
key: "getContextAndActions",
|
|
459
|
-
value: function getContextAndActions(actorCtx, input) {
|
|
460
|
-
var actions = [];
|
|
461
|
-
var context = this.config.context;
|
|
462
|
-
var resolvedContext = typeof context === 'function' ? context({
|
|
463
|
-
spawn: actors_dist_xstateActors.createSpawner(actorCtx === null || actorCtx === void 0 ? void 0 : actorCtx.self, this, undefined,
|
|
464
|
-
// TODO: this requires `| undefined` for all referenced dynamic inputs that are spawnable in the context factory,
|
|
465
|
-
actors_dist_xstateActors.createInitEvent(input), actions),
|
|
466
|
-
input: input
|
|
467
|
-
}) : context;
|
|
468
|
-
return [resolvedContext || {}, actions];
|
|
469
|
-
}
|
|
470
|
-
/**
|
|
471
|
-
* The machine's own version.
|
|
472
|
-
*/
|
|
473
|
-
}, {
|
|
474
|
-
key: "provide",
|
|
475
|
-
value: function provide(implementations) {
|
|
476
|
-
var _this$options = this.options,
|
|
477
|
-
actions = _this$options.actions,
|
|
478
|
-
guards = _this$options.guards,
|
|
479
|
-
actors = _this$options.actors,
|
|
480
|
-
delays = _this$options.delays;
|
|
481
|
-
return new StateMachine(this.config, {
|
|
482
|
-
actions: actors_dist_xstateActors._objectSpread2(actors_dist_xstateActors._objectSpread2({}, actions), implementations.actions),
|
|
483
|
-
guards: actors_dist_xstateActors._objectSpread2(actors_dist_xstateActors._objectSpread2({}, guards), implementations.guards),
|
|
484
|
-
actors: actors_dist_xstateActors._objectSpread2(actors_dist_xstateActors._objectSpread2({}, actors), implementations.actors),
|
|
485
|
-
delays: actors_dist_xstateActors._objectSpread2(actors_dist_xstateActors._objectSpread2({}, delays), implementations.delays)
|
|
486
|
-
});
|
|
487
|
-
}
|
|
488
|
-
|
|
489
|
-
/**
|
|
490
|
-
* Resolves the given `state` to a new `State` instance relative to this machine.
|
|
491
|
-
*
|
|
492
|
-
* This ensures that `.nextEvents` represent the correct values.
|
|
493
|
-
*
|
|
494
|
-
* @param state The state to resolve
|
|
495
|
-
*/
|
|
496
|
-
}, {
|
|
497
|
-
key: "resolveState",
|
|
498
|
-
value: function resolveState(state) {
|
|
499
|
-
var configurationSet = actors_dist_xstateActors.getConfiguration(actors_dist_xstateActors.getStateNodes(this.root, state.value));
|
|
500
|
-
var configuration = Array.from(configurationSet);
|
|
501
|
-
return this.createState(actors_dist_xstateActors._objectSpread2(actors_dist_xstateActors._objectSpread2({}, state), {}, {
|
|
502
|
-
value: actors_dist_xstateActors.resolveStateValue(this.root, state.value),
|
|
503
|
-
configuration: configuration,
|
|
504
|
-
done: actors_dist_xstateActors.isInFinalState(configuration)
|
|
505
|
-
}));
|
|
506
|
-
}
|
|
507
|
-
}, {
|
|
508
|
-
key: "resolveStateValue",
|
|
509
|
-
value: function resolveStateValue(stateValue) {
|
|
510
|
-
var resolvedStateValue = actors_dist_xstateActors.resolveStateValue(this.root, stateValue);
|
|
511
|
-
var resolvedContext = this.getContext();
|
|
512
|
-
return this.resolveState(actors_dist_xstateActors.State.from(resolvedStateValue, resolvedContext, this));
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
/**
|
|
516
|
-
* Determines the next state given the current `state` and received `event`.
|
|
517
|
-
* Calculates a full macrostep from all microsteps.
|
|
518
|
-
*
|
|
519
|
-
* @param state The current State instance or state value
|
|
520
|
-
* @param event The received event
|
|
521
|
-
*/
|
|
522
|
-
}, {
|
|
523
|
-
key: "transition",
|
|
524
|
-
value: function transition() {
|
|
525
|
-
var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.initialState;
|
|
526
|
-
var event = arguments.length > 1 ? arguments[1] : undefined;
|
|
527
|
-
var actorCtx = arguments.length > 2 ? arguments[2] : undefined;
|
|
528
|
-
var currentState = state instanceof actors_dist_xstateActors.State ? state : this.resolveStateValue(state);
|
|
529
|
-
// TODO: handle error events in a better way
|
|
530
|
-
var scxmlEvent = actors_dist_xstateActors.toSCXMLEvent(event);
|
|
531
|
-
if (actors_dist_xstateActors.isSCXMLErrorEvent(scxmlEvent) && !currentState.nextEvents.some(function (nextEvent) {
|
|
532
|
-
return nextEvent === scxmlEvent.name;
|
|
533
|
-
})) {
|
|
534
|
-
throw scxmlEvent.data.data;
|
|
535
|
-
}
|
|
536
|
-
var _macrostep = actors_dist_xstateActors.macrostep(currentState, scxmlEvent, actorCtx),
|
|
537
|
-
nextState = _macrostep.state;
|
|
538
|
-
return nextState;
|
|
539
|
-
}
|
|
540
|
-
|
|
541
|
-
/**
|
|
542
|
-
* Determines the next state given the current `state` and `event`.
|
|
543
|
-
* Calculates a microstep.
|
|
544
|
-
*
|
|
545
|
-
* @param state The current state
|
|
546
|
-
* @param event The received event
|
|
547
|
-
*/
|
|
548
|
-
}, {
|
|
549
|
-
key: "microstep",
|
|
550
|
-
value: function microstep() {
|
|
551
|
-
var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.initialState;
|
|
552
|
-
var event = arguments.length > 1 ? arguments[1] : undefined;
|
|
553
|
-
var actorCtx = arguments.length > 2 ? arguments[2] : undefined;
|
|
554
|
-
var scxmlEvent = actors_dist_xstateActors.toSCXMLEvent(event);
|
|
555
|
-
var _macrostep2 = actors_dist_xstateActors.macrostep(state, scxmlEvent, actorCtx),
|
|
556
|
-
microstates = _macrostep2.microstates;
|
|
557
|
-
return microstates;
|
|
558
|
-
}
|
|
559
|
-
}, {
|
|
560
|
-
key: "getTransitionData",
|
|
561
|
-
value: function getTransitionData(state, _event) {
|
|
562
|
-
return actors_dist_xstateActors.transitionNode(this.root, state.value, state, _event) || [];
|
|
563
|
-
}
|
|
564
|
-
|
|
565
|
-
/**
|
|
566
|
-
* The initial state _before_ evaluating any microsteps.
|
|
567
|
-
* This "pre-initial" state is provided to initial actions executed in the initial state.
|
|
568
|
-
*/
|
|
569
|
-
}, {
|
|
570
|
-
key: "getPreInitialState",
|
|
571
|
-
value: function getPreInitialState(actorCtx, input) {
|
|
572
|
-
var _preInitial$actions;
|
|
573
|
-
var _this$getContextAndAc = this.getContextAndActions(actorCtx, input),
|
|
574
|
-
_this$getContextAndAc2 = actors_dist_xstateActors._slicedToArray(_this$getContextAndAc, 2),
|
|
575
|
-
context = _this$getContextAndAc2[0],
|
|
576
|
-
actions = _this$getContextAndAc2[1];
|
|
577
|
-
var config = actors_dist_xstateActors.getInitialConfiguration(this.root);
|
|
578
|
-
var preInitial = this.resolveState(this.createState({
|
|
579
|
-
value: {},
|
|
580
|
-
// TODO: this is computed in state constructor
|
|
581
|
-
context: context,
|
|
582
|
-
_event: actors_dist_xstateActors.createInitEvent({}),
|
|
583
|
-
actions: [],
|
|
584
|
-
meta: undefined,
|
|
585
|
-
configuration: config,
|
|
586
|
-
transitions: [],
|
|
587
|
-
children: {}
|
|
588
|
-
}));
|
|
589
|
-
preInitial._initial = true;
|
|
590
|
-
(_preInitial$actions = preInitial.actions).unshift.apply(_preInitial$actions, actors_dist_xstateActors._toConsumableArray(actions));
|
|
591
|
-
if (actorCtx) {
|
|
592
|
-
var _resolveActionsAndCon = actors_dist_xstateActors.resolveActionsAndContext(actions, actors_dist_xstateActors.initEvent, preInitial, actorCtx),
|
|
593
|
-
nextState = _resolveActionsAndCon.nextState;
|
|
594
|
-
preInitial.children = nextState.children;
|
|
595
|
-
preInitial.actions = nextState.actions;
|
|
596
|
-
}
|
|
597
|
-
return preInitial;
|
|
598
|
-
}
|
|
599
|
-
|
|
600
|
-
/**
|
|
601
|
-
* The initial State instance, which includes all actions to be executed from
|
|
602
|
-
* entering the initial state.
|
|
603
|
-
*/
|
|
604
|
-
}, {
|
|
605
|
-
key: "initialState",
|
|
606
|
-
get: function get() {
|
|
607
|
-
return this.getInitialState();
|
|
608
|
-
}
|
|
609
|
-
|
|
610
|
-
/**
|
|
611
|
-
* Returns the initial `State` instance, with reference to `self` as an `ActorRef`.
|
|
612
|
-
*/
|
|
613
|
-
}, {
|
|
614
|
-
key: "getInitialState",
|
|
615
|
-
value: function getInitialState(actorCtx, input) {
|
|
616
|
-
var _nextState$actions;
|
|
617
|
-
var initEvent = actors_dist_xstateActors.createInitEvent(input); // TODO: fix;
|
|
618
|
-
|
|
619
|
-
var preInitialState = this.getPreInitialState(actorCtx, input);
|
|
620
|
-
var nextState = actors_dist_xstateActors.microstep([], preInitialState, actorCtx, initEvent);
|
|
621
|
-
(_nextState$actions = nextState.actions).unshift.apply(_nextState$actions, actors_dist_xstateActors._toConsumableArray(preInitialState.actions));
|
|
622
|
-
var _macrostep3 = actors_dist_xstateActors.macrostep(nextState, initEvent, actorCtx),
|
|
623
|
-
macroState = _macrostep3.state;
|
|
624
|
-
return macroState;
|
|
625
|
-
}
|
|
626
|
-
}, {
|
|
627
|
-
key: "start",
|
|
628
|
-
value: function start(state, actorCtx) {
|
|
629
|
-
state.actions.forEach(function (action) {
|
|
630
|
-
var _action$execute;
|
|
631
|
-
(_action$execute = action.execute) === null || _action$execute === void 0 ? void 0 : _action$execute.call(action, actorCtx);
|
|
632
|
-
});
|
|
633
|
-
Object.values(state.children).forEach(function (child) {
|
|
634
|
-
if (child.status === 0) {
|
|
635
|
-
try {
|
|
636
|
-
var _child$start;
|
|
637
|
-
(_child$start = child.start) === null || _child$start === void 0 ? void 0 : _child$start.call(child);
|
|
638
|
-
} catch (err) {
|
|
639
|
-
// TODO: unify error handling when child starts
|
|
640
|
-
actorCtx.self.send(actors_dist_xstateActors.error(child.id, err));
|
|
641
|
-
}
|
|
642
|
-
}
|
|
643
|
-
});
|
|
644
|
-
}
|
|
645
|
-
}, {
|
|
646
|
-
key: "getStateNodeById",
|
|
647
|
-
value: function getStateNodeById(stateId) {
|
|
648
|
-
var fullPath = stateId.split(this.delimiter);
|
|
649
|
-
var relativePath = fullPath.slice(1);
|
|
650
|
-
var resolvedStateId = actors_dist_xstateActors.isStateId(fullPath[0]) ? fullPath[0].slice(STATE_IDENTIFIER.length) : fullPath[0];
|
|
651
|
-
var stateNode = this.idMap.get(resolvedStateId);
|
|
652
|
-
if (!stateNode) {
|
|
653
|
-
throw new Error("Child state node '#".concat(resolvedStateId, "' does not exist on machine '").concat(this.id, "'"));
|
|
654
|
-
}
|
|
655
|
-
return actors_dist_xstateActors.getStateNodeByPath(stateNode, relativePath);
|
|
656
|
-
}
|
|
657
|
-
}, {
|
|
658
|
-
key: "definition",
|
|
659
|
-
get: function get() {
|
|
660
|
-
return actors_dist_xstateActors._objectSpread2({
|
|
661
|
-
context: this.getContext()
|
|
662
|
-
}, this.root.definition);
|
|
663
|
-
}
|
|
664
|
-
}, {
|
|
665
|
-
key: "toJSON",
|
|
666
|
-
value: function toJSON() {
|
|
667
|
-
return this.definition;
|
|
668
|
-
}
|
|
669
|
-
}, {
|
|
670
|
-
key: "getPersistedState",
|
|
671
|
-
value: function getPersistedState(state) {
|
|
672
|
-
return actors_dist_xstateActors.getPersistedState(state);
|
|
673
|
-
}
|
|
674
|
-
}, {
|
|
675
|
-
key: "createState",
|
|
676
|
-
value: function createState(stateConfig) {
|
|
677
|
-
var state = stateConfig instanceof actors_dist_xstateActors.State ? stateConfig : new actors_dist_xstateActors.State(stateConfig, this);
|
|
678
|
-
var _resolveActionsAndCon2 = actors_dist_xstateActors.resolveActionsAndContext(state.actions, state._event, state, undefined),
|
|
679
|
-
resolvedState = _resolveActionsAndCon2.nextState;
|
|
680
|
-
return resolvedState;
|
|
681
|
-
}
|
|
682
|
-
}, {
|
|
683
|
-
key: "getStatus",
|
|
684
|
-
value: function getStatus(state) {
|
|
685
|
-
return state.done ? {
|
|
686
|
-
status: 'done',
|
|
687
|
-
data: state.output
|
|
688
|
-
} : {
|
|
689
|
-
status: 'active'
|
|
690
|
-
};
|
|
691
|
-
}
|
|
692
|
-
}, {
|
|
693
|
-
key: "restoreState",
|
|
694
|
-
value: function restoreState(state, _actorCtx) {
|
|
695
|
-
var _this = this;
|
|
696
|
-
var children = {};
|
|
697
|
-
Object.keys(state.children).forEach(function (actorId) {
|
|
698
|
-
var _resolveReferencedAct, _behavior$restoreStat;
|
|
699
|
-
var actorData = state.children[actorId];
|
|
700
|
-
var childState = actorData.state;
|
|
701
|
-
var src = actorData.src;
|
|
702
|
-
var behavior = src ? (_resolveReferencedAct = actors_dist_xstateActors.resolveReferencedActor(_this.options.actors[src])) === null || _resolveReferencedAct === void 0 ? void 0 : _resolveReferencedAct.src : undefined;
|
|
703
|
-
if (!behavior) {
|
|
704
|
-
return;
|
|
705
|
-
}
|
|
706
|
-
var actorState = (_behavior$restoreStat = behavior.restoreState) === null || _behavior$restoreStat === void 0 ? void 0 : _behavior$restoreStat.call(behavior, childState, _actorCtx);
|
|
707
|
-
var actorRef = actors_dist_xstateActors.interpret(behavior, {
|
|
708
|
-
id: actorId,
|
|
709
|
-
state: actorState
|
|
710
|
-
});
|
|
711
|
-
children[actorId] = actorRef;
|
|
712
|
-
});
|
|
713
|
-
var restoredState = this.createState(new actors_dist_xstateActors.State(actors_dist_xstateActors._objectSpread2(actors_dist_xstateActors._objectSpread2({}, state), {}, {
|
|
714
|
-
children: children
|
|
715
|
-
}), this));
|
|
716
|
-
|
|
717
|
-
// TODO: DRY this up
|
|
718
|
-
restoredState.configuration.forEach(function (stateNode) {
|
|
719
|
-
if (stateNode.invoke) {
|
|
720
|
-
stateNode.invoke.forEach(function (invokeConfig) {
|
|
721
|
-
var id = invokeConfig.id,
|
|
722
|
-
src = invokeConfig.src;
|
|
723
|
-
if (children[id]) {
|
|
724
|
-
return;
|
|
725
|
-
}
|
|
726
|
-
var referenced = actors_dist_xstateActors.resolveReferencedActor(_this.options.actors[src]);
|
|
727
|
-
if (referenced) {
|
|
728
|
-
var actorRef = actors_dist_xstateActors.interpret(referenced.src, {
|
|
729
|
-
id: id,
|
|
730
|
-
parent: _actorCtx === null || _actorCtx === void 0 ? void 0 : _actorCtx.self,
|
|
731
|
-
input: 'input' in invokeConfig ? invokeConfig.input : referenced.input
|
|
732
|
-
});
|
|
733
|
-
children[id] = actorRef;
|
|
734
|
-
}
|
|
735
|
-
});
|
|
736
|
-
}
|
|
737
|
-
});
|
|
738
|
-
restoredState.actions = [];
|
|
739
|
-
return restoredState;
|
|
740
|
-
}
|
|
741
|
-
|
|
742
|
-
/**@deprecated an internal property acting as a "phantom" type, not meant to be used at runtime */
|
|
743
|
-
}]);
|
|
744
|
-
return StateMachine;
|
|
745
|
-
}();
|
|
746
|
-
|
|
747
|
-
function createMachine(config, implementations) {
|
|
748
|
-
return new StateMachine(config, implementations);
|
|
749
|
-
}
|
|
750
|
-
|
|
751
|
-
function mapState(stateMap, stateId) {
|
|
752
|
-
var foundStateId;
|
|
753
|
-
for (var _i = 0, _Object$keys = Object.keys(stateMap); _i < _Object$keys.length; _i++) {
|
|
754
|
-
var mappedStateId = _Object$keys[_i];
|
|
755
|
-
if (actors_dist_xstateActors.matchesState(mappedStateId, stateId) && (!foundStateId || stateId.length > foundStateId.length)) {
|
|
756
|
-
foundStateId = mappedStateId;
|
|
757
|
-
}
|
|
758
|
-
}
|
|
759
|
-
return stateMap[foundStateId];
|
|
760
|
-
}
|
|
761
|
-
|
|
762
|
-
var SimulatedClock = /*#__PURE__*/function () {
|
|
763
|
-
function SimulatedClock() {
|
|
764
|
-
actors_dist_xstateActors._classCallCheck(this, SimulatedClock);
|
|
765
|
-
actors_dist_xstateActors._defineProperty(this, "timeouts", new Map());
|
|
766
|
-
actors_dist_xstateActors._defineProperty(this, "_now", 0);
|
|
767
|
-
actors_dist_xstateActors._defineProperty(this, "_id", 0);
|
|
768
|
-
}
|
|
769
|
-
actors_dist_xstateActors._createClass(SimulatedClock, [{
|
|
770
|
-
key: "now",
|
|
771
|
-
value: function now() {
|
|
772
|
-
return this._now;
|
|
773
|
-
}
|
|
774
|
-
}, {
|
|
775
|
-
key: "getId",
|
|
776
|
-
value: function getId() {
|
|
777
|
-
return this._id++;
|
|
778
|
-
}
|
|
779
|
-
}, {
|
|
780
|
-
key: "setTimeout",
|
|
781
|
-
value: function setTimeout(fn, timeout) {
|
|
782
|
-
var id = this.getId();
|
|
783
|
-
this.timeouts.set(id, {
|
|
784
|
-
start: this.now(),
|
|
785
|
-
timeout: timeout,
|
|
786
|
-
fn: fn
|
|
787
|
-
});
|
|
788
|
-
return id;
|
|
789
|
-
}
|
|
790
|
-
}, {
|
|
791
|
-
key: "clearTimeout",
|
|
792
|
-
value: function clearTimeout(id) {
|
|
793
|
-
this.timeouts["delete"](id);
|
|
794
|
-
}
|
|
795
|
-
}, {
|
|
796
|
-
key: "set",
|
|
797
|
-
value: function set(time) {
|
|
798
|
-
if (this._now > time) {
|
|
799
|
-
throw new Error('Unable to travel back in time');
|
|
800
|
-
}
|
|
801
|
-
this._now = time;
|
|
802
|
-
this.flushTimeouts();
|
|
803
|
-
}
|
|
804
|
-
}, {
|
|
805
|
-
key: "flushTimeouts",
|
|
806
|
-
value: function flushTimeouts() {
|
|
807
|
-
var _this = this;
|
|
808
|
-
actors_dist_xstateActors._toConsumableArray(this.timeouts).sort(function (_ref, _ref2) {
|
|
809
|
-
var _ref3 = actors_dist_xstateActors._slicedToArray(_ref, 2);
|
|
810
|
-
_ref3[0];
|
|
811
|
-
var timeoutA = _ref3[1];
|
|
812
|
-
var _ref4 = actors_dist_xstateActors._slicedToArray(_ref2, 2);
|
|
813
|
-
_ref4[0];
|
|
814
|
-
var timeoutB = _ref4[1];
|
|
815
|
-
var endA = timeoutA.start + timeoutA.timeout;
|
|
816
|
-
var endB = timeoutB.start + timeoutB.timeout;
|
|
817
|
-
return endB > endA ? -1 : 1;
|
|
818
|
-
}).forEach(function (_ref5) {
|
|
819
|
-
var _ref6 = actors_dist_xstateActors._slicedToArray(_ref5, 2),
|
|
820
|
-
id = _ref6[0],
|
|
821
|
-
timeout = _ref6[1];
|
|
822
|
-
if (_this.now() - timeout.start >= timeout.timeout) {
|
|
823
|
-
_this.timeouts["delete"](id);
|
|
824
|
-
timeout.fn.call(null);
|
|
825
|
-
}
|
|
826
|
-
});
|
|
827
|
-
}
|
|
828
|
-
}, {
|
|
829
|
-
key: "increment",
|
|
830
|
-
value: function increment(ms) {
|
|
831
|
-
this._now += ms;
|
|
832
|
-
this.flushTimeouts();
|
|
833
|
-
}
|
|
834
|
-
}]);
|
|
835
|
-
return SimulatedClock;
|
|
836
|
-
}();
|
|
837
|
-
|
|
838
|
-
var defaultWaitForOptions = {
|
|
839
|
-
timeout: 10000 // 10 seconds
|
|
840
|
-
};
|
|
841
|
-
|
|
842
|
-
/**
|
|
843
|
-
* Subscribes to an actor ref and waits for its emitted value to satisfy
|
|
844
|
-
* a predicate, and then resolves with that value.
|
|
845
|
-
* Will throw if the desired state is not reached after a timeout
|
|
846
|
-
* (defaults to 10 seconds).
|
|
847
|
-
*
|
|
848
|
-
* @example
|
|
849
|
-
* ```js
|
|
850
|
-
* const state = await waitFor(someService, state => {
|
|
851
|
-
* return state.hasTag('loaded');
|
|
852
|
-
* });
|
|
853
|
-
*
|
|
854
|
-
* state.hasTag('loaded'); // true
|
|
855
|
-
* ```
|
|
856
|
-
*
|
|
857
|
-
* @param actorRef The actor ref to subscribe to
|
|
858
|
-
* @param predicate Determines if a value matches the condition to wait for
|
|
859
|
-
* @param options
|
|
860
|
-
* @returns A promise that eventually resolves to the emitted value
|
|
861
|
-
* that matches the condition
|
|
862
|
-
*/
|
|
863
|
-
function waitFor(actorRef, predicate, options) {
|
|
864
|
-
var resolvedOptions = actors_dist_xstateActors._objectSpread2(actors_dist_xstateActors._objectSpread2({}, defaultWaitForOptions), options);
|
|
865
|
-
return new Promise(function (res, rej) {
|
|
866
|
-
var done = false;
|
|
867
|
-
var handle = resolvedOptions.timeout === Infinity ? undefined : setTimeout(function () {
|
|
868
|
-
sub.unsubscribe();
|
|
869
|
-
rej(new Error("Timeout of ".concat(resolvedOptions.timeout, " ms exceeded")));
|
|
870
|
-
}, resolvedOptions.timeout);
|
|
871
|
-
var dispose = function dispose() {
|
|
872
|
-
clearTimeout(handle);
|
|
873
|
-
done = true;
|
|
874
|
-
sub === null || sub === void 0 ? void 0 : sub.unsubscribe();
|
|
875
|
-
};
|
|
876
|
-
function checkEmitted(emitted) {
|
|
877
|
-
if (predicate(emitted)) {
|
|
878
|
-
dispose();
|
|
879
|
-
res(emitted);
|
|
880
|
-
}
|
|
881
|
-
}
|
|
882
|
-
|
|
883
|
-
// See if the current snapshot already matches the predicate
|
|
884
|
-
checkEmitted(actorRef.getSnapshot());
|
|
885
|
-
var sub = actorRef.subscribe({
|
|
886
|
-
next: checkEmitted,
|
|
887
|
-
error: function error(err) {
|
|
888
|
-
dispose();
|
|
889
|
-
rej(err);
|
|
890
|
-
},
|
|
891
|
-
complete: function complete() {
|
|
892
|
-
dispose();
|
|
893
|
-
rej(new Error("Actor terminated without satisfying predicate"));
|
|
894
|
-
}
|
|
895
|
-
});
|
|
896
|
-
if (done) {
|
|
897
|
-
sub.unsubscribe();
|
|
898
|
-
}
|
|
899
|
-
});
|
|
900
|
-
}
|
|
901
|
-
|
|
902
|
-
Object.defineProperty(exports, 'ActionTypes', {
|
|
903
|
-
enumerable: true,
|
|
904
|
-
get: function () { return actors_dist_xstateActors.ActionTypes; }
|
|
905
|
-
});
|
|
906
|
-
exports.Interpreter = actors_dist_xstateActors.Interpreter;
|
|
907
|
-
Object.defineProperty(exports, 'InterpreterStatus', {
|
|
908
|
-
enumerable: true,
|
|
909
|
-
get: function () { return actors_dist_xstateActors.ActorStatus; }
|
|
910
|
-
});
|
|
911
|
-
Object.defineProperty(exports, 'SpecialTargets', {
|
|
912
|
-
enumerable: true,
|
|
913
|
-
get: function () { return actors_dist_xstateActors.SpecialTargets; }
|
|
914
|
-
});
|
|
915
|
-
exports.State = actors_dist_xstateActors.State;
|
|
916
|
-
exports.and = actors_dist_xstateActors.and;
|
|
917
|
-
exports.assign = actors_dist_xstateActors.assign;
|
|
918
|
-
exports.cancel = actors_dist_xstateActors.cancel;
|
|
919
|
-
exports.choose = actors_dist_xstateActors.choose;
|
|
920
|
-
exports.doneInvoke = actors_dist_xstateActors.doneInvoke;
|
|
921
|
-
exports.forwardTo = actors_dist_xstateActors.forwardTo;
|
|
922
|
-
exports.fromCallback = actors_dist_xstateActors.fromCallback;
|
|
923
|
-
exports.fromEventObservable = actors_dist_xstateActors.fromEventObservable;
|
|
924
|
-
exports.fromObservable = actors_dist_xstateActors.fromObservable;
|
|
925
|
-
exports.fromPromise = actors_dist_xstateActors.fromPromise;
|
|
926
|
-
exports.fromTransition = actors_dist_xstateActors.fromTransition;
|
|
927
|
-
exports.getStateNodes = actors_dist_xstateActors.getStateNodes;
|
|
928
|
-
exports.interpret = actors_dist_xstateActors.interpret;
|
|
929
|
-
exports.log = actors_dist_xstateActors.log;
|
|
930
|
-
exports.matchesState = actors_dist_xstateActors.matchesState;
|
|
931
|
-
exports.not = actors_dist_xstateActors.not;
|
|
932
|
-
exports.or = actors_dist_xstateActors.or;
|
|
933
|
-
exports.pathToStateValue = actors_dist_xstateActors.pathToStateValue;
|
|
934
|
-
exports.pure = actors_dist_xstateActors.pure;
|
|
935
|
-
exports.raise = actors_dist_xstateActors.raise;
|
|
936
|
-
exports.sendParent = actors_dist_xstateActors.sendParent;
|
|
937
|
-
exports.sendTo = actors_dist_xstateActors.sendTo;
|
|
938
|
-
exports.stateIn = actors_dist_xstateActors.stateIn;
|
|
939
|
-
exports.stop = actors_dist_xstateActors.stop;
|
|
940
|
-
exports.toObserver = actors_dist_xstateActors.toObserver;
|
|
941
|
-
exports.toSCXMLEvent = actors_dist_xstateActors.toSCXMLEvent;
|
|
942
|
-
exports.SimulatedClock = SimulatedClock;
|
|
943
|
-
exports.StateMachine = StateMachine;
|
|
944
|
-
exports.StateNode = StateNode;
|
|
945
|
-
exports.createMachine = createMachine;
|
|
946
|
-
exports.mapState = mapState;
|
|
947
|
-
exports.waitFor = waitFor;
|