xstate 4.20.0 → 4.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +205 -0
- package/dist/xstate.interpreter.js +1 -1
- package/dist/xstate.js +1 -1
- package/dist/xstate.web.js +2 -2
- package/es/Actor.d.ts +6 -5
- package/es/Actor.js +22 -7
- package/es/Machine.d.ts +10 -5
- package/es/Machine.js +3 -6
- package/es/State.js +3 -5
- package/es/StateNode.d.ts +4 -3
- package/es/StateNode.js +34 -28
- package/es/_virtual/_tslib.js +59 -73
- package/es/actionTypes.js +3 -2
- package/es/actions.d.ts +1 -1
- package/es/actions.js +51 -37
- package/es/behaviors.d.ts +37 -0
- package/es/behaviors.js +65 -0
- package/es/constants.js +2 -1
- package/es/devTools.js +1 -1
- package/es/environment.js +2 -1
- package/es/index.js +3 -1
- package/es/interpreter.d.ts +15 -8
- package/es/interpreter.js +48 -22
- package/es/invokeUtils.js +4 -3
- package/es/mapState.js +1 -1
- package/es/match.js +1 -1
- package/es/model.d.ts +2 -36
- package/es/model.types.d.ts +37 -0
- package/es/registry.js +2 -1
- package/es/scheduler.js +2 -1
- package/es/schema.js +1 -1
- package/es/serviceScope.js +1 -3
- package/es/stateUtils.d.ts +1 -0
- package/es/stateUtils.js +14 -8
- package/es/types.d.ts +35 -9
- package/es/types.js +1 -1
- package/es/utils.d.ts +3 -2
- package/es/utils.js +4 -40
- package/lib/Actor.d.ts +25 -24
- package/lib/Actor.js +87 -53
- package/lib/Machine.d.ts +17 -12
- package/lib/Machine.js +14 -14
- package/lib/SimulatedClock.d.ts +16 -16
- package/lib/State.d.ts +108 -108
- package/lib/State.js +246 -236
- package/lib/StateNode.d.ts +279 -278
- package/lib/StateNode.js +1535 -1350
- package/lib/_virtual/_tslib.js +81 -0
- package/lib/actionTypes.d.ts +19 -19
- package/lib/actionTypes.js +43 -23
- package/lib/actions.d.ts +138 -138
- package/lib/actions.js +465 -387
- package/lib/behaviors.d.ts +37 -0
- package/lib/behaviors.js +69 -0
- package/lib/constants.d.ts +5 -5
- package/lib/constants.js +13 -7
- package/lib/devTools.d.ts +15 -15
- package/lib/devTools.js +37 -26
- package/lib/each.d.ts +3 -3
- package/lib/environment.d.ts +1 -1
- package/lib/environment.js +7 -4
- package/lib/index.d.ts +30 -30
- package/lib/index.js +67 -57
- package/lib/interpreter.d.ts +205 -198
- package/lib/interpreter.js +1307 -1052
- package/lib/invoke.d.ts +10 -10
- package/lib/invokeUtils.d.ts +6 -6
- package/lib/invokeUtils.js +40 -37
- package/lib/json.d.ts +30 -30
- package/lib/mapState.d.ts +3 -3
- package/lib/mapState.js +31 -32
- package/lib/match.d.ts +8 -8
- package/lib/match.js +33 -47
- package/lib/model.d.ts +4 -38
- package/lib/model.js +5 -1
- package/lib/model.types.d.ts +37 -0
- package/lib/model.types.js +2 -0
- package/lib/patterns.d.ts +13 -13
- package/lib/registry.d.ts +8 -8
- package/lib/registry.js +21 -18
- package/lib/scheduler.d.ts +16 -16
- package/lib/scheduler.js +79 -70
- package/lib/schema.d.ts +1 -1
- package/lib/schema.js +6 -4
- package/lib/scxml.d.ts +5 -5
- package/lib/serviceScope.d.ts +3 -3
- package/lib/serviceScope.js +16 -12
- package/lib/stateUtils.d.ts +14 -13
- package/lib/stateUtils.js +232 -190
- package/lib/types.d.ts +928 -902
- package/lib/types.js +29 -29
- package/lib/utils.d.ts +68 -67
- package/lib/utils.js +530 -529
- package/package.json +5 -5
package/es/_virtual/_tslib.js
CHANGED
|
@@ -11,78 +11,64 @@ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
|
11
11
|
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
12
12
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
13
13
|
PERFORMANCE OF THIS SOFTWARE.
|
|
14
|
-
***************************************************************************** */
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
function
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
try {
|
|
73
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
74
|
-
} finally {
|
|
75
|
-
if (e) throw e.error;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
return ar;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
function __spreadArray(to, from) {
|
|
83
|
-
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++) to[j] = from[i];
|
|
84
|
-
|
|
85
|
-
return to;
|
|
14
|
+
***************************************************************************** */
|
|
15
|
+
|
|
16
|
+
var __assign = function() {
|
|
17
|
+
__assign = Object.assign || function __assign(t) {
|
|
18
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
19
|
+
s = arguments[i];
|
|
20
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
21
|
+
}
|
|
22
|
+
return t;
|
|
23
|
+
};
|
|
24
|
+
return __assign.apply(this, arguments);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
function __rest(s, e) {
|
|
28
|
+
var t = {};
|
|
29
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
30
|
+
t[p] = s[p];
|
|
31
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
32
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
33
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
34
|
+
t[p[i]] = s[p[i]];
|
|
35
|
+
}
|
|
36
|
+
return t;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function __values(o) {
|
|
40
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
41
|
+
if (m) return m.call(o);
|
|
42
|
+
if (o && typeof o.length === "number") return {
|
|
43
|
+
next: function () {
|
|
44
|
+
if (o && i >= o.length) o = void 0;
|
|
45
|
+
return { value: o && o[i++], done: !o };
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function __read(o, n) {
|
|
52
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
53
|
+
if (!m) return o;
|
|
54
|
+
var i = m.call(o), r, ar = [], e;
|
|
55
|
+
try {
|
|
56
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
57
|
+
}
|
|
58
|
+
catch (error) { e = { error: error }; }
|
|
59
|
+
finally {
|
|
60
|
+
try {
|
|
61
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
62
|
+
}
|
|
63
|
+
finally { if (e) throw e.error; }
|
|
64
|
+
}
|
|
65
|
+
return ar;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function __spreadArray(to, from) {
|
|
69
|
+
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
|
|
70
|
+
to[j] = from[i];
|
|
71
|
+
return to;
|
|
86
72
|
}
|
|
87
73
|
|
|
88
|
-
export { __assign, __read, __rest, __spreadArray, __values };
|
|
74
|
+
export { __assign, __read, __rest, __spreadArray, __values };
|
package/es/actionTypes.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ActionTypes } from './types.js';
|
|
1
|
+
import { ActionTypes } from './types.js';
|
|
2
2
|
|
|
3
3
|
var start = ActionTypes.Start;
|
|
4
4
|
var stop = ActionTypes.Stop;
|
|
@@ -18,4 +18,5 @@ var error = ActionTypes.ErrorCustom;
|
|
|
18
18
|
var update = ActionTypes.Update;
|
|
19
19
|
var choose = ActionTypes.Choose;
|
|
20
20
|
var pure = ActionTypes.Pure;
|
|
21
|
-
|
|
21
|
+
|
|
22
|
+
export { after, assign, cancel, choose, doneState, error, errorExecution, errorPlatform, init, invoke, log, nullEvent, pure, raise, send, start, stop, update };
|
package/es/actions.d.ts
CHANGED
|
@@ -135,5 +135,5 @@ export declare function forwardTo<TContext, TEvent extends EventObject>(target:
|
|
|
135
135
|
*/
|
|
136
136
|
export declare function escalate<TContext, TEvent extends EventObject, TErrorData = any>(errorData: TErrorData | ExprWithMeta<TContext, TEvent, TErrorData>, options?: SendActionOptions<TContext, TEvent>): SendAction<TContext, TEvent, AnyEventObject>;
|
|
137
137
|
export declare function choose<TContext, TEvent extends EventObject>(conds: Array<ChooseConditon<TContext, TEvent>>): ChooseAction<TContext, TEvent>;
|
|
138
|
-
export declare function resolveActions<TContext, TEvent extends EventObject>(machine: StateNode<TContext, any, TEvent, any>, currentState: State<TContext, TEvent> | undefined, currentContext: TContext, _event: SCXML.Event<TEvent>, actions: Array<ActionObject<TContext, TEvent
|
|
138
|
+
export declare function resolveActions<TContext, TEvent extends EventObject>(machine: StateNode<TContext, any, TEvent, any>, currentState: State<TContext, TEvent> | undefined, currentContext: TContext, _event: SCXML.Event<TEvent>, actions: Array<ActionObject<TContext, TEvent>>, preserveActionOrder?: boolean): [Array<ActionObject<TContext, TEvent>>, TContext];
|
|
139
139
|
//# sourceMappingURL=actions.d.ts.map
|
package/es/actions.js
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
import { __assign, __read } from './_virtual/_tslib.js';
|
|
1
|
+
import { __assign, __read, __spreadArray } from './_virtual/_tslib.js';
|
|
2
2
|
import { IS_PRODUCTION } from './environment.js';
|
|
3
|
-
import {
|
|
3
|
+
import { isFunction, toEventObject, getEventType, toSCXMLEvent, isString, partition, updateContext, flatten, toArray, toGuard, evaluateGuard, warn, isArray } from './utils.js';
|
|
4
4
|
import { SpecialTargets, ActionTypes } from './types.js';
|
|
5
5
|
import { send as send$1, update, assign as assign$1, init, raise as raise$1, log as log$1, cancel as cancel$1, error as error$1, stop as stop$1, pure as pure$1, choose as choose$1 } from './actionTypes.js';
|
|
6
|
+
|
|
6
7
|
var initEvent = /*#__PURE__*/toSCXMLEvent({
|
|
7
8
|
type: init
|
|
8
9
|
});
|
|
9
|
-
|
|
10
10
|
function getActionFunction(actionType, actionFunctionMap) {
|
|
11
11
|
return actionFunctionMap ? actionFunctionMap[actionType] || undefined : undefined;
|
|
12
12
|
}
|
|
13
|
-
|
|
14
13
|
function toActionObject(action, actionFunctionMap) {
|
|
15
14
|
var actionObject;
|
|
16
15
|
|
|
@@ -62,7 +61,6 @@ function toActionObject(action, actionFunctionMap) {
|
|
|
62
61
|
});
|
|
63
62
|
return actionObject;
|
|
64
63
|
}
|
|
65
|
-
|
|
66
64
|
var toActionObjects = function (action, actionFunctionMap) {
|
|
67
65
|
if (!action) {
|
|
68
66
|
return [];
|
|
@@ -73,7 +71,6 @@ var toActionObjects = function (action, actionFunctionMap) {
|
|
|
73
71
|
return toActionObject(subAction, actionFunctionMap);
|
|
74
72
|
});
|
|
75
73
|
};
|
|
76
|
-
|
|
77
74
|
function toActivityDefinition(action) {
|
|
78
75
|
var actionObject = toActionObject(action);
|
|
79
76
|
return __assign(__assign({
|
|
@@ -89,7 +86,6 @@ function toActivityDefinition(action) {
|
|
|
89
86
|
* @param eventType The event to raise.
|
|
90
87
|
*/
|
|
91
88
|
|
|
92
|
-
|
|
93
89
|
function raise(event) {
|
|
94
90
|
if (!isString(event)) {
|
|
95
91
|
return send(event, {
|
|
@@ -102,7 +98,6 @@ function raise(event) {
|
|
|
102
98
|
event: event
|
|
103
99
|
};
|
|
104
100
|
}
|
|
105
|
-
|
|
106
101
|
function resolveRaise(action) {
|
|
107
102
|
return {
|
|
108
103
|
type: raise$1,
|
|
@@ -120,7 +115,6 @@ function resolveRaise(action) {
|
|
|
120
115
|
* - `to` - The target of this event (by default, the machine the event was sent from).
|
|
121
116
|
*/
|
|
122
117
|
|
|
123
|
-
|
|
124
118
|
function send(event, options) {
|
|
125
119
|
return {
|
|
126
120
|
to: options ? options.to : undefined,
|
|
@@ -130,7 +124,6 @@ function send(event, options) {
|
|
|
130
124
|
id: options && options.id !== undefined ? options.id : isFunction(event) ? event.name : getEventType(event)
|
|
131
125
|
};
|
|
132
126
|
}
|
|
133
|
-
|
|
134
127
|
function resolveSend(action, ctx, _event, delaysMap) {
|
|
135
128
|
var meta = {
|
|
136
129
|
_event: _event
|
|
@@ -161,7 +154,6 @@ function resolveSend(action, ctx, _event, delaysMap) {
|
|
|
161
154
|
* @param options Options to pass into the send event.
|
|
162
155
|
*/
|
|
163
156
|
|
|
164
|
-
|
|
165
157
|
function sendParent(event, options) {
|
|
166
158
|
return send(event, __assign(__assign({}, options), {
|
|
167
159
|
to: SpecialTargets.Parent
|
|
@@ -171,7 +163,6 @@ function sendParent(event, options) {
|
|
|
171
163
|
* Sends an update event to this machine's parent.
|
|
172
164
|
*/
|
|
173
165
|
|
|
174
|
-
|
|
175
166
|
function sendUpdate() {
|
|
176
167
|
return sendParent(update);
|
|
177
168
|
}
|
|
@@ -182,7 +173,6 @@ function sendUpdate() {
|
|
|
182
173
|
* @param options Options to pass into the send event
|
|
183
174
|
*/
|
|
184
175
|
|
|
185
|
-
|
|
186
176
|
function respond(event, options) {
|
|
187
177
|
return send(event, __assign(__assign({}, options), {
|
|
188
178
|
to: function (_, __, _a) {
|
|
@@ -219,7 +209,6 @@ function log(expr, label) {
|
|
|
219
209
|
expr: expr
|
|
220
210
|
};
|
|
221
211
|
}
|
|
222
|
-
|
|
223
212
|
var resolveLog = function (action, ctx, _event) {
|
|
224
213
|
return __assign(__assign({}, action), {
|
|
225
214
|
value: isString(action.expr) ? action.expr : action.expr(ctx, _event.data, {
|
|
@@ -235,7 +224,6 @@ var resolveLog = function (action, ctx, _event) {
|
|
|
235
224
|
* @param sendId The `id` of the `send(...)` action to cancel.
|
|
236
225
|
*/
|
|
237
226
|
|
|
238
|
-
|
|
239
227
|
var cancel = function (sendId) {
|
|
240
228
|
return {
|
|
241
229
|
type: cancel$1,
|
|
@@ -248,7 +236,6 @@ var cancel = function (sendId) {
|
|
|
248
236
|
* @param activity The activity to start.
|
|
249
237
|
*/
|
|
250
238
|
|
|
251
|
-
|
|
252
239
|
function start(activity) {
|
|
253
240
|
var activityDef = toActivityDefinition(activity);
|
|
254
241
|
return {
|
|
@@ -263,7 +250,6 @@ function start(activity) {
|
|
|
263
250
|
* @param actorRef The activity to stop.
|
|
264
251
|
*/
|
|
265
252
|
|
|
266
|
-
|
|
267
253
|
function stop(actorRef) {
|
|
268
254
|
var activity = isFunction(actorRef) ? actorRef : toActivityDefinition(actorRef);
|
|
269
255
|
return {
|
|
@@ -272,7 +258,6 @@ function stop(actorRef) {
|
|
|
272
258
|
exec: undefined
|
|
273
259
|
};
|
|
274
260
|
}
|
|
275
|
-
|
|
276
261
|
function resolveStop(action, context, _event) {
|
|
277
262
|
var actorRefOrString = isFunction(action.activity) ? action.activity(context, _event.data) : action.activity;
|
|
278
263
|
var resolvedActorRef = typeof actorRefOrString === 'string' ? {
|
|
@@ -290,7 +275,6 @@ function resolveStop(action, context, _event) {
|
|
|
290
275
|
* @param assignment An object that represents the partial context to update.
|
|
291
276
|
*/
|
|
292
277
|
|
|
293
|
-
|
|
294
278
|
var assign = function (assignment) {
|
|
295
279
|
return {
|
|
296
280
|
type: assign$1,
|
|
@@ -305,7 +289,6 @@ var assign = function (assignment) {
|
|
|
305
289
|
* @param id The state node ID where this event is handled
|
|
306
290
|
*/
|
|
307
291
|
|
|
308
|
-
|
|
309
292
|
function after(delayRef, id) {
|
|
310
293
|
var idSuffix = id ? "#" + id : '';
|
|
311
294
|
return ActionTypes.After + "(" + delayRef + ")" + idSuffix;
|
|
@@ -318,7 +301,6 @@ function after(delayRef, id) {
|
|
|
318
301
|
* @param data The data to pass into the event
|
|
319
302
|
*/
|
|
320
303
|
|
|
321
|
-
|
|
322
304
|
function done(id, data) {
|
|
323
305
|
var type = ActionTypes.DoneState + "." + id;
|
|
324
306
|
var eventObject = {
|
|
@@ -342,7 +324,6 @@ function done(id, data) {
|
|
|
342
324
|
* @param data The data to pass into the event
|
|
343
325
|
*/
|
|
344
326
|
|
|
345
|
-
|
|
346
327
|
function doneInvoke(id, data) {
|
|
347
328
|
var type = ActionTypes.DoneInvoke + "." + id;
|
|
348
329
|
var eventObject = {
|
|
@@ -356,7 +337,6 @@ function doneInvoke(id, data) {
|
|
|
356
337
|
|
|
357
338
|
return eventObject;
|
|
358
339
|
}
|
|
359
|
-
|
|
360
340
|
function error(id, data) {
|
|
361
341
|
var type = ActionTypes.ErrorPlatform + "." + id;
|
|
362
342
|
var eventObject = {
|
|
@@ -370,7 +350,6 @@ function error(id, data) {
|
|
|
370
350
|
|
|
371
351
|
return eventObject;
|
|
372
352
|
}
|
|
373
|
-
|
|
374
353
|
function pure(getActions) {
|
|
375
354
|
return {
|
|
376
355
|
type: ActionTypes.Pure,
|
|
@@ -384,7 +363,6 @@ function pure(getActions) {
|
|
|
384
363
|
* @param options Options to pass into the send action creator.
|
|
385
364
|
*/
|
|
386
365
|
|
|
387
|
-
|
|
388
366
|
function forwardTo(target, options) {
|
|
389
367
|
return send(function (_, event) {
|
|
390
368
|
return event;
|
|
@@ -400,7 +378,6 @@ function forwardTo(target, options) {
|
|
|
400
378
|
* @param options Options to pass into the send action creator.
|
|
401
379
|
*/
|
|
402
380
|
|
|
403
|
-
|
|
404
381
|
function escalate(errorData, options) {
|
|
405
382
|
return sendParent(function (context, event, meta) {
|
|
406
383
|
return {
|
|
@@ -411,22 +388,25 @@ function escalate(errorData, options) {
|
|
|
411
388
|
to: SpecialTargets.Parent
|
|
412
389
|
}));
|
|
413
390
|
}
|
|
414
|
-
|
|
415
391
|
function choose(conds) {
|
|
416
392
|
return {
|
|
417
393
|
type: ActionTypes.Choose,
|
|
418
394
|
conds: conds
|
|
419
395
|
};
|
|
420
396
|
}
|
|
397
|
+
function resolveActions(machine, currentState, currentContext, _event, actions, preserveActionOrder) {
|
|
398
|
+
if (preserveActionOrder === void 0) {
|
|
399
|
+
preserveActionOrder = false;
|
|
400
|
+
}
|
|
421
401
|
|
|
422
|
-
|
|
423
|
-
var _a = __read(partition(actions, function (action) {
|
|
402
|
+
var _a = __read(preserveActionOrder ? [[], actions] : partition(actions, function (action) {
|
|
424
403
|
return action.type === assign$1;
|
|
425
404
|
}), 2),
|
|
426
405
|
assignActions = _a[0],
|
|
427
406
|
otherActions = _a[1];
|
|
428
407
|
|
|
429
408
|
var updatedContext = assignActions.length ? updateContext(currentContext, _event, assignActions, currentState) : currentContext;
|
|
409
|
+
var preservedContexts = preserveActionOrder ? [currentContext] : undefined;
|
|
430
410
|
var resolvedActions = flatten(otherActions.map(function (actionObject) {
|
|
431
411
|
var _a;
|
|
432
412
|
|
|
@@ -460,9 +440,13 @@ function resolveActions(machine, currentState, currentContext, _event, actions)
|
|
|
460
440
|
return [];
|
|
461
441
|
}
|
|
462
442
|
|
|
463
|
-
var
|
|
464
|
-
|
|
465
|
-
|
|
443
|
+
var _b = __read(resolveActions(machine, currentState, updatedContext, _event, toActionObjects(toArray(matchedActions), machine.options.actions), preserveActionOrder), 2),
|
|
444
|
+
resolvedActionsFromChoose = _b[0],
|
|
445
|
+
resolvedContextFromChoose = _b[1];
|
|
446
|
+
|
|
447
|
+
updatedContext = resolvedContextFromChoose;
|
|
448
|
+
preservedContexts === null || preservedContexts === void 0 ? void 0 : preservedContexts.push(updatedContext);
|
|
449
|
+
return resolvedActionsFromChoose;
|
|
466
450
|
}
|
|
467
451
|
|
|
468
452
|
case pure$1:
|
|
@@ -473,9 +457,13 @@ function resolveActions(machine, currentState, currentContext, _event, actions)
|
|
|
473
457
|
return [];
|
|
474
458
|
}
|
|
475
459
|
|
|
476
|
-
var
|
|
477
|
-
|
|
478
|
-
|
|
460
|
+
var _c = __read(resolveActions(machine, currentState, updatedContext, _event, toActionObjects(toArray(matchedActions), machine.options.actions), preserveActionOrder), 2),
|
|
461
|
+
resolvedActionsFromPure = _c[0],
|
|
462
|
+
resolvedContext = _c[1];
|
|
463
|
+
|
|
464
|
+
updatedContext = resolvedContext;
|
|
465
|
+
preservedContexts === null || preservedContexts === void 0 ? void 0 : preservedContexts.push(updatedContext);
|
|
466
|
+
return resolvedActionsFromPure;
|
|
479
467
|
}
|
|
480
468
|
|
|
481
469
|
case stop$1:
|
|
@@ -483,11 +471,37 @@ function resolveActions(machine, currentState, currentContext, _event, actions)
|
|
|
483
471
|
return resolveStop(actionObject, updatedContext, _event);
|
|
484
472
|
}
|
|
485
473
|
|
|
474
|
+
case assign$1:
|
|
475
|
+
{
|
|
476
|
+
updatedContext = updateContext(updatedContext, _event, [actionObject], currentState);
|
|
477
|
+
preservedContexts === null || preservedContexts === void 0 ? void 0 : preservedContexts.push(updatedContext);
|
|
478
|
+
break;
|
|
479
|
+
}
|
|
480
|
+
|
|
486
481
|
default:
|
|
487
|
-
|
|
482
|
+
var resolvedActionObject = toActionObject(actionObject, machine.options.actions);
|
|
483
|
+
var exec_1 = resolvedActionObject.exec;
|
|
484
|
+
|
|
485
|
+
if (exec_1 && preservedContexts) {
|
|
486
|
+
var contextIndex_1 = preservedContexts.length - 1;
|
|
487
|
+
|
|
488
|
+
resolvedActionObject.exec = function (_ctx) {
|
|
489
|
+
var args = [];
|
|
490
|
+
|
|
491
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
492
|
+
args[_i - 1] = arguments[_i];
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
exec_1 === null || exec_1 === void 0 ? void 0 : exec_1.apply(void 0, __spreadArray([preservedContexts[contextIndex_1]], __read(args)));
|
|
496
|
+
};
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
return resolvedActionObject;
|
|
488
500
|
}
|
|
501
|
+
}).filter(function (a) {
|
|
502
|
+
return !!a;
|
|
489
503
|
}));
|
|
490
504
|
return [resolvedActions, updatedContext];
|
|
491
505
|
}
|
|
492
506
|
|
|
493
|
-
export { after, assign, cancel, choose, done, doneInvoke, error, escalate, forwardTo, getActionFunction, initEvent, log, pure, raise, resolveActions, resolveLog, resolveRaise, resolveSend, resolveStop, respond, send, sendParent, sendUpdate, start, stop, toActionObject, toActionObjects, toActivityDefinition };
|
|
507
|
+
export { after, assign, cancel, choose, done, doneInvoke, error, escalate, forwardTo, getActionFunction, initEvent, log, pure, raise, resolveActions, resolveLog, resolveRaise, resolveSend, resolveStop, respond, send, sendParent, sendUpdate, start, stop, toActionObject, toActionObjects, toActivityDefinition };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { ActorContext, ActorRef, Behavior, EventObject } from '.';
|
|
2
|
+
/**
|
|
3
|
+
* Returns an actor behavior from a reducer and its initial state.
|
|
4
|
+
*
|
|
5
|
+
* @param transition The pure reducer that returns the next state given the current state and event.
|
|
6
|
+
* @param initialState The initial state of the reducer.
|
|
7
|
+
* @returns An actor behavior
|
|
8
|
+
*/
|
|
9
|
+
export declare function fromReducer<TState, TEvent extends EventObject>(transition: (state: TState, event: TEvent, actorContext: ActorContext<TEvent, TState>) => TState, initialState: TState): Behavior<TEvent, TState>;
|
|
10
|
+
declare type PromiseEvents<T> = {
|
|
11
|
+
type: 'fulfill';
|
|
12
|
+
data: T;
|
|
13
|
+
} | {
|
|
14
|
+
type: 'reject';
|
|
15
|
+
error: unknown;
|
|
16
|
+
};
|
|
17
|
+
declare type PromiseState<T> = {
|
|
18
|
+
status: 'pending';
|
|
19
|
+
data: undefined;
|
|
20
|
+
error: undefined;
|
|
21
|
+
} | {
|
|
22
|
+
status: 'fulfilled';
|
|
23
|
+
data: T;
|
|
24
|
+
error: undefined;
|
|
25
|
+
} | {
|
|
26
|
+
status: 'rejected';
|
|
27
|
+
data: undefined;
|
|
28
|
+
error: any;
|
|
29
|
+
};
|
|
30
|
+
export declare function fromPromise<T>(promiseFn: () => Promise<T>): Behavior<PromiseEvents<T>, PromiseState<T>>;
|
|
31
|
+
interface SpawnBehaviorOptions {
|
|
32
|
+
id?: string;
|
|
33
|
+
parent?: ActorRef<any>;
|
|
34
|
+
}
|
|
35
|
+
export declare function spawnBehavior<TEvent extends EventObject, TEmitted>(behavior: Behavior<TEvent, TEmitted>, options?: SpawnBehaviorOptions): ActorRef<TEvent, TEmitted>;
|
|
36
|
+
export {};
|
|
37
|
+
//# sourceMappingURL=behaviors.d.ts.map
|
package/es/behaviors.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import './environment.js';
|
|
2
|
+
import { toObserver } from './utils.js';
|
|
3
|
+
import './types.js';
|
|
4
|
+
import './actionTypes.js';
|
|
5
|
+
import { toActorRef } from './Actor.js';
|
|
6
|
+
|
|
7
|
+
function spawnBehavior(behavior, options) {
|
|
8
|
+
if (options === void 0) {
|
|
9
|
+
options = {};
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
var state = behavior.initialState;
|
|
13
|
+
var observers = new Set();
|
|
14
|
+
var mailbox = [];
|
|
15
|
+
var flushing = false;
|
|
16
|
+
|
|
17
|
+
var flush = function () {
|
|
18
|
+
if (flushing) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
flushing = true;
|
|
23
|
+
|
|
24
|
+
while (mailbox.length > 0) {
|
|
25
|
+
var event_1 = mailbox.shift();
|
|
26
|
+
state = behavior.transition(state, event_1, actorCtx);
|
|
27
|
+
observers.forEach(function (observer) {
|
|
28
|
+
return observer.next(state);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
flushing = false;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
var actor = toActorRef({
|
|
36
|
+
id: options.id,
|
|
37
|
+
send: function (event) {
|
|
38
|
+
mailbox.push(event);
|
|
39
|
+
flush();
|
|
40
|
+
},
|
|
41
|
+
getSnapshot: function () {
|
|
42
|
+
return state;
|
|
43
|
+
},
|
|
44
|
+
subscribe: function (next, handleError, complete) {
|
|
45
|
+
var observer = toObserver(next, handleError, complete);
|
|
46
|
+
observers.add(observer);
|
|
47
|
+
observer.next(state);
|
|
48
|
+
return {
|
|
49
|
+
unsubscribe: function () {
|
|
50
|
+
observers.delete(observer);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
var actorCtx = {
|
|
56
|
+
parent: options.parent,
|
|
57
|
+
self: actor,
|
|
58
|
+
id: options.id || 'anonymous',
|
|
59
|
+
observers: observers
|
|
60
|
+
};
|
|
61
|
+
state = behavior.start ? behavior.start(actorCtx) : state;
|
|
62
|
+
return actor;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export { spawnBehavior };
|
package/es/constants.js
CHANGED
|
@@ -2,4 +2,5 @@ var STATE_DELIMITER = '.';
|
|
|
2
2
|
var EMPTY_ACTIVITY_MAP = {};
|
|
3
3
|
var DEFAULT_GUARD_TYPE = 'xstate.guard';
|
|
4
4
|
var TARGETLESS_KEY = '';
|
|
5
|
-
|
|
5
|
+
|
|
6
|
+
export { DEFAULT_GUARD_TYPE, EMPTY_ACTIVITY_MAP, STATE_DELIMITER, TARGETLESS_KEY };
|
package/es/devTools.js
CHANGED
package/es/environment.js
CHANGED
package/es/index.js
CHANGED
|
@@ -9,6 +9,7 @@ export { Machine, createMachine } from './Machine.js';
|
|
|
9
9
|
export { Interpreter, InterpreterStatus, interpret, spawn } from './interpreter.js';
|
|
10
10
|
export { matchState } from './match.js';
|
|
11
11
|
export { createSchema } from './schema.js';
|
|
12
|
+
|
|
12
13
|
var actions = {
|
|
13
14
|
raise: raise,
|
|
14
15
|
send: send,
|
|
@@ -27,4 +28,5 @@ var actions = {
|
|
|
27
28
|
choose: choose,
|
|
28
29
|
pure: pure
|
|
29
30
|
};
|
|
30
|
-
|
|
31
|
+
|
|
32
|
+
export { actions };
|
package/es/interpreter.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { StateMachine, Event, EventObject, DefaultContext, StateSchema, StateValue, InterpreterOptions, SingleOrArray, DoneEvent, MachineOptions, SCXML, EventData, Observer, Spawnable, Typestate } from './types';
|
|
1
|
+
import { StateMachine, Event, EventObject, DefaultContext, StateSchema, StateValue, InterpreterOptions, SingleOrArray, Subscribable, DoneEvent, MachineOptions, SCXML, EventData, Observer, Spawnable, Typestate, ActorRef, ActorRefFrom, Behavior, Subscription } from './types';
|
|
2
2
|
import { State } from './State';
|
|
3
|
-
import { ActorRefFrom, SpawnedActorRef, Subscription } from '.';
|
|
4
3
|
export declare type StateListener<TContext, TEvent extends EventObject, TStateSchema extends StateSchema<TContext> = any, TTypestate extends Typestate<TContext> = {
|
|
5
4
|
value: any;
|
|
6
5
|
context: TContext;
|
|
@@ -22,10 +21,15 @@ export declare enum InterpreterStatus {
|
|
|
22
21
|
Running = 1,
|
|
23
22
|
Stopped = 2
|
|
24
23
|
}
|
|
24
|
+
declare global {
|
|
25
|
+
interface SymbolConstructor {
|
|
26
|
+
readonly observable: symbol;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
25
29
|
export declare class Interpreter<TContext, TStateSchema extends StateSchema = any, TEvent extends EventObject = EventObject, TTypestate extends Typestate<TContext> = {
|
|
26
30
|
value: any;
|
|
27
31
|
context: TContext;
|
|
28
|
-
}> implements
|
|
32
|
+
}> implements ActorRef<TEvent, State<TContext, TEvent, TStateSchema, TTypestate>> {
|
|
29
33
|
machine: StateMachine<TContext, TStateSchema, TEvent, TTypestate>;
|
|
30
34
|
/**
|
|
31
35
|
* The default interpreter options:
|
|
@@ -64,7 +68,7 @@ export declare class Interpreter<TContext, TStateSchema extends StateSchema = an
|
|
|
64
68
|
* The globally unique process ID for this invocation.
|
|
65
69
|
*/
|
|
66
70
|
sessionId: string;
|
|
67
|
-
children: Map<string | number,
|
|
71
|
+
children: Map<string | number, ActorRef<any>>;
|
|
68
72
|
private forwardTo;
|
|
69
73
|
private devTools?;
|
|
70
74
|
/**
|
|
@@ -86,8 +90,8 @@ export declare class Interpreter<TContext, TStateSchema extends StateSchema = an
|
|
|
86
90
|
execute(state: State<TContext, TEvent, TStateSchema, TTypestate>, actionsConfig?: MachineOptions<TContext, TEvent>['actions']): void;
|
|
87
91
|
private update;
|
|
88
92
|
onTransition(listener: StateListener<TContext, TEvent, TStateSchema, TTypestate>): this;
|
|
89
|
-
subscribe(observer: Observer<State<TContext, TEvent, any, TTypestate>>): Subscription;
|
|
90
93
|
subscribe(nextListener?: (state: State<TContext, TEvent, any, TTypestate>) => void, errorListener?: (error: any) => void, completeListener?: () => void): Subscription;
|
|
94
|
+
subscribe(observer: Observer<State<TContext, TEvent, any, TTypestate>>): Subscription;
|
|
91
95
|
/**
|
|
92
96
|
* Adds an event listener that is notified whenever an event is sent to the running interpreter.
|
|
93
97
|
* @param listener The event listener
|
|
@@ -165,12 +169,13 @@ export declare class Interpreter<TContext, TStateSchema extends StateSchema = an
|
|
|
165
169
|
private exec;
|
|
166
170
|
private removeChild;
|
|
167
171
|
private stopChild;
|
|
168
|
-
spawn(entity: Spawnable, name: string, options?: SpawnOptions):
|
|
172
|
+
spawn(entity: Spawnable, name: string, options?: SpawnOptions): ActorRef<any>;
|
|
169
173
|
spawnMachine<TChildContext, TChildStateSchema, TChildEvent extends EventObject>(machine: StateMachine<TChildContext, TChildStateSchema, TChildEvent>, options?: {
|
|
170
174
|
id?: string;
|
|
171
175
|
autoForward?: boolean;
|
|
172
176
|
sync?: boolean;
|
|
173
|
-
}):
|
|
177
|
+
}): ActorRef<TChildEvent, State<TChildContext, TChildEvent>>;
|
|
178
|
+
private spawnBehavior;
|
|
174
179
|
private spawnPromise;
|
|
175
180
|
private spawnCallback;
|
|
176
181
|
private spawnObservable;
|
|
@@ -181,10 +186,12 @@ export declare class Interpreter<TContext, TStateSchema extends StateSchema = an
|
|
|
181
186
|
toJSON(): {
|
|
182
187
|
id: string;
|
|
183
188
|
};
|
|
189
|
+
[Symbol.observable](): Subscribable<State<TContext, TEvent, TStateSchema, TTypestate>>;
|
|
184
190
|
getSnapshot(): State<TContext, TEvent, TStateSchema, TTypestate>;
|
|
185
191
|
}
|
|
192
|
+
export declare function spawn<T extends Behavior<any, any>>(entity: T, nameOrOptions?: string | SpawnOptions): ActorRefFrom<T>;
|
|
186
193
|
export declare function spawn<TC, TE extends EventObject>(entity: StateMachine<TC, any, TE>, nameOrOptions?: string | SpawnOptions): ActorRefFrom<StateMachine<TC, any, TE>>;
|
|
187
|
-
export declare function spawn(entity: Spawnable, nameOrOptions?: string | SpawnOptions):
|
|
194
|
+
export declare function spawn(entity: Spawnable, nameOrOptions?: string | SpawnOptions): ActorRef<any>;
|
|
188
195
|
/**
|
|
189
196
|
* Creates a new Interpreter instance for the given machine with the provided options, if any.
|
|
190
197
|
*
|