xstate 4.22.0 → 4.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +58 -4
- package/dist/xstate.interpreter.js +1 -1
- package/dist/xstate.js +1 -1
- package/dist/xstate.web.js +2 -2
- package/es/Actor.js +1 -6
- package/es/Machine.d.ts +3 -3
- package/es/Machine.js +1 -2
- package/es/State.js +1 -3
- package/es/StateNode.js +3 -2
- 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.js +4 -2
- 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 +8 -2
- package/es/interpreter.js +8 -6
- package/es/invokeUtils.js +4 -3
- package/es/mapState.js +1 -1
- package/es/match.js +1 -1
- package/es/model.d.ts +2 -37
- 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.js +1 -9
- package/es/types.d.ts +12 -2
- package/es/types.js +1 -1
- package/es/utils.js +1 -41
- package/lib/Actor.d.ts +25 -25
- package/lib/Actor.js +85 -66
- package/lib/Machine.d.ts +17 -17
- package/lib/Machine.js +14 -8
- 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 -279
- package/lib/StateNode.js +1535 -1357
- 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 +36 -36
- package/lib/behaviors.js +65 -106
- 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 -199
- package/lib/interpreter.js +1306 -1060
- 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 -39
- 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 -14
- package/lib/stateUtils.js +231 -199
- package/lib/types.d.ts +928 -918
- package/lib/types.js +29 -29
- package/lib/utils.d.ts +68 -68
- package/lib/utils.js +528 -534
- package/package.json +5 -5
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 };
|
package/es/behaviors.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import './environment.js';
|
|
1
2
|
import { toObserver } from './utils.js';
|
|
2
|
-
import './
|
|
3
|
+
import './types.js';
|
|
4
|
+
import './actionTypes.js';
|
|
3
5
|
import { toActorRef } from './Actor.js';
|
|
4
6
|
|
|
5
7
|
function spawnBehavior(behavior, options) {
|
|
@@ -60,4 +62,4 @@ function spawnBehavior(behavior, options) {
|
|
|
60
62
|
return actor;
|
|
61
63
|
}
|
|
62
64
|
|
|
63
|
-
export { spawnBehavior };
|
|
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,4 +1,4 @@
|
|
|
1
|
-
import { StateMachine, Event, EventObject, DefaultContext, StateSchema, StateValue, InterpreterOptions, SingleOrArray, DoneEvent, MachineOptions, SCXML, EventData, Observer, Spawnable, Typestate, ActorRef, ActorRefFrom, Behavior, Subscription } 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
3
|
export declare type StateListener<TContext, TEvent extends EventObject, TStateSchema extends StateSchema<TContext> = any, TTypestate extends Typestate<TContext> = {
|
|
4
4
|
value: any;
|
|
@@ -21,6 +21,11 @@ export declare enum InterpreterStatus {
|
|
|
21
21
|
Running = 1,
|
|
22
22
|
Stopped = 2
|
|
23
23
|
}
|
|
24
|
+
declare global {
|
|
25
|
+
interface SymbolConstructor {
|
|
26
|
+
readonly observable: symbol;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
24
29
|
export declare class Interpreter<TContext, TStateSchema extends StateSchema = any, TEvent extends EventObject = EventObject, TTypestate extends Typestate<TContext> = {
|
|
25
30
|
value: any;
|
|
26
31
|
context: TContext;
|
|
@@ -85,8 +90,8 @@ export declare class Interpreter<TContext, TStateSchema extends StateSchema = an
|
|
|
85
90
|
execute(state: State<TContext, TEvent, TStateSchema, TTypestate>, actionsConfig?: MachineOptions<TContext, TEvent>['actions']): void;
|
|
86
91
|
private update;
|
|
87
92
|
onTransition(listener: StateListener<TContext, TEvent, TStateSchema, TTypestate>): this;
|
|
88
|
-
subscribe(observer: Observer<State<TContext, TEvent, any, TTypestate>>): Subscription;
|
|
89
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;
|
|
90
95
|
/**
|
|
91
96
|
* Adds an event listener that is notified whenever an event is sent to the running interpreter.
|
|
92
97
|
* @param listener The event listener
|
|
@@ -181,6 +186,7 @@ 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
|
}
|
|
186
192
|
export declare function spawn<T extends Behavior<any, any>>(entity: T, nameOrOptions?: string | SpawnOptions): ActorRefFrom<T>;
|
package/es/interpreter.js
CHANGED
|
@@ -12,6 +12,7 @@ import { Scheduler } from './scheduler.js';
|
|
|
12
12
|
import { registry } from './registry.js';
|
|
13
13
|
import { registerService, getGlobal } from './devTools.js';
|
|
14
14
|
import { spawnBehavior } from './behaviors.js';
|
|
15
|
+
|
|
15
16
|
var DEFAULT_SPAWN_OPTIONS = {
|
|
16
17
|
sync: false,
|
|
17
18
|
autoForward: false
|
|
@@ -919,7 +920,7 @@ function () {
|
|
|
919
920
|
} else if (isFunction(entity)) {
|
|
920
921
|
return this.spawnCallback(entity, name);
|
|
921
922
|
} else if (isSpawnedActor(entity)) {
|
|
922
|
-
return this.spawnActor(entity);
|
|
923
|
+
return this.spawnActor(entity, name);
|
|
923
924
|
} else if (isObservable(entity)) {
|
|
924
925
|
return this.spawnObservable(entity, name);
|
|
925
926
|
} else if (isMachine(entity)) {
|
|
@@ -1195,8 +1196,8 @@ function () {
|
|
|
1195
1196
|
return actor;
|
|
1196
1197
|
};
|
|
1197
1198
|
|
|
1198
|
-
Interpreter.prototype.spawnActor = function (actor) {
|
|
1199
|
-
this.children.set(
|
|
1199
|
+
Interpreter.prototype.spawnActor = function (actor, name) {
|
|
1200
|
+
this.children.set(name, actor);
|
|
1200
1201
|
return actor;
|
|
1201
1202
|
};
|
|
1202
1203
|
|
|
@@ -1280,7 +1281,9 @@ function () {
|
|
|
1280
1281
|
|
|
1281
1282
|
Interpreter.prototype[symbolObservable] = function () {
|
|
1282
1283
|
return this;
|
|
1283
|
-
};
|
|
1284
|
+
}; // this gets stripped by Babel to avoid having "undefined" property in environments without this non-standard Symbol
|
|
1285
|
+
// it has to be here to be included in the generated .d.ts
|
|
1286
|
+
|
|
1284
1287
|
|
|
1285
1288
|
Interpreter.prototype.getSnapshot = function () {
|
|
1286
1289
|
if (this.status === InterpreterStatus.NotStarted) {
|
|
@@ -1352,10 +1355,9 @@ function spawn(entity, nameOrOptions) {
|
|
|
1352
1355
|
* @param options Interpreter options
|
|
1353
1356
|
*/
|
|
1354
1357
|
|
|
1355
|
-
|
|
1356
1358
|
function interpret(machine, options) {
|
|
1357
1359
|
var interpreter = new Interpreter(machine, options);
|
|
1358
1360
|
return interpreter;
|
|
1359
1361
|
}
|
|
1360
1362
|
|
|
1361
|
-
export { Interpreter, InterpreterStatus, interpret, spawn };
|
|
1363
|
+
export { Interpreter, InterpreterStatus, interpret, spawn };
|
package/es/invokeUtils.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { __assign, __rest } from './_virtual/_tslib.js';
|
|
2
|
+
import './environment.js';
|
|
3
|
+
import './utils.js';
|
|
4
|
+
import './types.js';
|
|
2
5
|
import { invoke } from './actionTypes.js';
|
|
3
|
-
import './actions.js';
|
|
4
6
|
|
|
5
7
|
function toInvokeSource(src) {
|
|
6
8
|
if (typeof src === 'string') {
|
|
@@ -18,7 +20,6 @@ function toInvokeSource(src) {
|
|
|
18
20
|
|
|
19
21
|
return src;
|
|
20
22
|
}
|
|
21
|
-
|
|
22
23
|
function toInvokeDefinition(invokeConfig) {
|
|
23
24
|
return __assign(__assign({
|
|
24
25
|
type: invoke
|
|
@@ -36,4 +37,4 @@ function toInvokeDefinition(invokeConfig) {
|
|
|
36
37
|
});
|
|
37
38
|
}
|
|
38
39
|
|
|
39
|
-
export { toInvokeDefinition, toInvokeSource };
|
|
40
|
+
export { toInvokeDefinition, toInvokeSource };
|
package/es/mapState.js
CHANGED
package/es/match.js
CHANGED
package/es/model.d.ts
CHANGED
|
@@ -1,40 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
declare type Cast<A1 extends any, A2 extends any> = A1 extends A2 ? A1 : A2;
|
|
4
|
-
declare type Compute<A extends any> = {
|
|
5
|
-
[K in keyof A]: A[K];
|
|
6
|
-
} & unknown;
|
|
7
|
-
declare type Prop<T, K> = K extends keyof T ? T[K] : never;
|
|
8
|
-
export interface Model<TContext, TEvent extends EventObject, TModelCreators = void> {
|
|
9
|
-
initialContext: TContext;
|
|
10
|
-
assign: <TEventType extends TEvent['type'] = TEvent['type']>(assigner: Assigner<TContext, ExtractEvent<TEvent, TEventType>> | PropertyAssigner<TContext, ExtractEvent<TEvent, TEventType>>, eventType?: TEventType) => AssignAction<TContext, ExtractEvent<TEvent, TEventType>>;
|
|
11
|
-
events: Prop<TModelCreators, 'events'>;
|
|
12
|
-
reset: () => AssignAction<TContext, any>;
|
|
13
|
-
createMachine: (config: MachineConfig<TContext, any, TEvent>, implementations?: Partial<MachineOptions<TContext, TEvent>>) => StateMachine<TContext, any, TEvent, any>;
|
|
14
|
-
}
|
|
15
|
-
export declare type ModelContextFrom<TModel extends Model<any, any, any>> = TModel extends Model<infer TContext, any, any> ? TContext : never;
|
|
16
|
-
export declare type ModelEventsFrom<TModel extends Model<any, any, any>> = TModel extends Model<any, infer TEvent, any> ? TEvent : never;
|
|
17
|
-
declare type EventCreator<Self extends AnyFunction, Return = ReturnType<Self>> = Return extends object ? Return extends {
|
|
18
|
-
type: any;
|
|
19
|
-
} ? "An event creator can't return an object with a type property" : Self : 'An event creator must return an object';
|
|
20
|
-
declare type EventCreators<Self> = {
|
|
21
|
-
[K in keyof Self]: Self[K] extends AnyFunction ? EventCreator<Self[K]> : 'An event creator must be a function';
|
|
22
|
-
};
|
|
23
|
-
declare type ModelCreators<Self> = {
|
|
24
|
-
events: EventCreators<Prop<Self, 'events'>>;
|
|
25
|
-
};
|
|
26
|
-
declare type FinalEventCreators<Self> = {
|
|
27
|
-
[K in keyof Self]: Self[K] extends AnyFunction ? (...args: Parameters<Self[K]>) => Compute<ReturnType<Self[K]> & {
|
|
28
|
-
type: K;
|
|
29
|
-
}> : never;
|
|
30
|
-
};
|
|
31
|
-
declare type FinalModelCreators<Self> = {
|
|
32
|
-
events: FinalEventCreators<Prop<Self, 'events'>>;
|
|
33
|
-
};
|
|
34
|
-
declare type EventFromEventCreators<EventCreators> = {
|
|
35
|
-
[K in keyof EventCreators]: EventCreators[K] extends AnyFunction ? ReturnType<EventCreators[K]> : never;
|
|
36
|
-
}[keyof EventCreators];
|
|
1
|
+
import type { EventObject } from './types';
|
|
2
|
+
import { Cast, EventFromEventCreators, FinalModelCreators, Model, ModelCreators, Prop } from './model.types';
|
|
37
3
|
export declare function createModel<TContext, TEvent extends EventObject>(initialContext: TContext): Model<TContext, TEvent, void>;
|
|
38
4
|
export declare function createModel<TContext, TModelCreators extends ModelCreators<TModelCreators>, TFinalModelCreators = FinalModelCreators<TModelCreators>>(initialContext: TContext, creators: TModelCreators): Model<TContext, Cast<EventFromEventCreators<Prop<TFinalModelCreators, 'events'>>, EventObject>, TFinalModelCreators>;
|
|
39
|
-
export {};
|
|
40
5
|
//# sourceMappingURL=model.d.ts.map
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { EventObject, Assigner, ExtractEvent, PropertyAssigner, AssignAction, MachineConfig, MachineOptions, StateMachine } from './types';
|
|
2
|
+
export declare type AnyFunction = (...args: any[]) => any;
|
|
3
|
+
export declare type Cast<A1 extends any, A2 extends any> = A1 extends A2 ? A1 : A2;
|
|
4
|
+
export declare type Compute<A extends any> = {
|
|
5
|
+
[K in keyof A]: A[K];
|
|
6
|
+
} & unknown;
|
|
7
|
+
export declare type Prop<T, K> = K extends keyof T ? T[K] : never;
|
|
8
|
+
export interface Model<TContext, TEvent extends EventObject, TModelCreators = void> {
|
|
9
|
+
initialContext: TContext;
|
|
10
|
+
assign: <TEventType extends TEvent['type'] = TEvent['type']>(assigner: Assigner<TContext, ExtractEvent<TEvent, TEventType>> | PropertyAssigner<TContext, ExtractEvent<TEvent, TEventType>>, eventType?: TEventType) => AssignAction<TContext, ExtractEvent<TEvent, TEventType>>;
|
|
11
|
+
events: Prop<TModelCreators, 'events'>;
|
|
12
|
+
reset: () => AssignAction<TContext, any>;
|
|
13
|
+
createMachine: (config: MachineConfig<TContext, any, TEvent>, implementations?: Partial<MachineOptions<TContext, TEvent>>) => StateMachine<TContext, any, TEvent, any>;
|
|
14
|
+
}
|
|
15
|
+
export declare type ModelContextFrom<TModel extends Model<any, any, any>> = TModel extends Model<infer TContext, any, any> ? TContext : never;
|
|
16
|
+
export declare type ModelEventsFrom<TModel extends Model<any, any, any>> = TModel extends Model<any, infer TEvent, any> ? TEvent : never;
|
|
17
|
+
export declare type EventCreator<Self extends AnyFunction, Return = ReturnType<Self>> = Return extends object ? Return extends {
|
|
18
|
+
type: any;
|
|
19
|
+
} ? "An event creator can't return an object with a type property" : Self : 'An event creator must return an object';
|
|
20
|
+
export declare type EventCreators<Self> = {
|
|
21
|
+
[K in keyof Self]: Self[K] extends AnyFunction ? EventCreator<Self[K]> : 'An event creator must be a function';
|
|
22
|
+
};
|
|
23
|
+
export declare type ModelCreators<Self> = {
|
|
24
|
+
events: EventCreators<Prop<Self, 'events'>>;
|
|
25
|
+
};
|
|
26
|
+
export declare type FinalEventCreators<Self> = {
|
|
27
|
+
[K in keyof Self]: Self[K] extends AnyFunction ? (...args: Parameters<Self[K]>) => Compute<ReturnType<Self[K]> & {
|
|
28
|
+
type: K;
|
|
29
|
+
}> : never;
|
|
30
|
+
};
|
|
31
|
+
export declare type FinalModelCreators<Self> = {
|
|
32
|
+
events: FinalEventCreators<Prop<Self, 'events'>>;
|
|
33
|
+
};
|
|
34
|
+
export declare type EventFromEventCreators<EventCreators> = {
|
|
35
|
+
[K in keyof EventCreators]: EventCreators[K] extends AnyFunction ? ReturnType<EventCreators[K]> : never;
|
|
36
|
+
}[keyof EventCreators];
|
|
37
|
+
//# sourceMappingURL=model.types.d.ts.map
|
package/es/registry.js
CHANGED
package/es/scheduler.js
CHANGED
package/es/schema.js
CHANGED
package/es/serviceScope.js
CHANGED
|
@@ -3,16 +3,14 @@
|
|
|
3
3
|
* This is used to provide the correct service to spawn().
|
|
4
4
|
*/
|
|
5
5
|
var serviceStack = [];
|
|
6
|
-
|
|
7
6
|
var provide = function (service, fn) {
|
|
8
7
|
serviceStack.push(service);
|
|
9
8
|
var result = fn(service);
|
|
10
9
|
serviceStack.pop();
|
|
11
10
|
return result;
|
|
12
11
|
};
|
|
13
|
-
|
|
14
12
|
var consume = function (fn) {
|
|
15
13
|
return fn(serviceStack[serviceStack.length - 1]);
|
|
16
14
|
};
|
|
17
15
|
|
|
18
|
-
export { consume, provide };
|
|
16
|
+
export { consume, provide };
|
package/es/stateUtils.js
CHANGED
|
@@ -4,13 +4,11 @@ import { keys, flatten } from './utils.js';
|
|
|
4
4
|
var isLeafNode = function (stateNode) {
|
|
5
5
|
return stateNode.type === 'atomic' || stateNode.type === 'final';
|
|
6
6
|
};
|
|
7
|
-
|
|
8
7
|
function getChildren(stateNode) {
|
|
9
8
|
return keys(stateNode.states).map(function (key) {
|
|
10
9
|
return stateNode.states[key];
|
|
11
10
|
});
|
|
12
11
|
}
|
|
13
|
-
|
|
14
12
|
function getAllStateNodes(stateNode) {
|
|
15
13
|
var stateNodes = [stateNode];
|
|
16
14
|
|
|
@@ -20,7 +18,6 @@ function getAllStateNodes(stateNode) {
|
|
|
20
18
|
|
|
21
19
|
return stateNodes.concat(flatten(getChildren(stateNode).map(getAllStateNodes)));
|
|
22
20
|
}
|
|
23
|
-
|
|
24
21
|
function getConfiguration(prevStateNodes, stateNodes) {
|
|
25
22
|
var e_1, _a, e_2, _b, e_3, _c, e_4, _d;
|
|
26
23
|
|
|
@@ -205,12 +202,10 @@ function getAdjList(configuration) {
|
|
|
205
202
|
|
|
206
203
|
return adjList;
|
|
207
204
|
}
|
|
208
|
-
|
|
209
205
|
function getValue(rootNode, configuration) {
|
|
210
206
|
var config = getConfiguration([rootNode], configuration);
|
|
211
207
|
return getValueFromAdj(rootNode, getAdjList(config));
|
|
212
208
|
}
|
|
213
|
-
|
|
214
209
|
function has(iterable, item) {
|
|
215
210
|
if (Array.isArray(iterable)) {
|
|
216
211
|
return iterable.some(function (member) {
|
|
@@ -224,13 +219,11 @@ function has(iterable, item) {
|
|
|
224
219
|
|
|
225
220
|
return false; // TODO: fix
|
|
226
221
|
}
|
|
227
|
-
|
|
228
222
|
function nextEvents(configuration) {
|
|
229
223
|
return __spreadArray([], __read(new Set(flatten(__spreadArray([], __read(configuration.map(function (sn) {
|
|
230
224
|
return sn.ownEvents;
|
|
231
225
|
})))))));
|
|
232
226
|
}
|
|
233
|
-
|
|
234
227
|
function isInFinalState(configuration, stateNode) {
|
|
235
228
|
if (stateNode.type === 'compound') {
|
|
236
229
|
return getChildren(stateNode).some(function (s) {
|
|
@@ -246,7 +239,6 @@ function isInFinalState(configuration, stateNode) {
|
|
|
246
239
|
|
|
247
240
|
return false;
|
|
248
241
|
}
|
|
249
|
-
|
|
250
242
|
function getMeta(configuration) {
|
|
251
243
|
if (configuration === void 0) {
|
|
252
244
|
configuration = [];
|
|
@@ -261,4 +253,4 @@ function getMeta(configuration) {
|
|
|
261
253
|
}, {});
|
|
262
254
|
}
|
|
263
255
|
|
|
264
|
-
export { getAdjList, getAllStateNodes, getChildren, getConfiguration, getMeta, getValue, has, isInFinalState, isLeafNode, nextEvents };
|
|
256
|
+
export { getAdjList, getAllStateNodes, getChildren, getConfiguration, getMeta, getValue, has, isInFinalState, isLeafNode, nextEvents };
|