xstate 5.0.0-alpha.5 → 5.0.0-beta.10
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/actions/dist/xstate-actions.cjs.d.mts +2 -0
- package/actions/dist/xstate-actions.cjs.d.mts.map +1 -0
- package/actions/dist/xstate-actions.cjs.d.ts +1 -0
- package/actions/dist/xstate-actions.cjs.d.ts.map +1 -0
- package/actions/dist/xstate-actions.cjs.dev.js +2 -2
- package/actions/dist/xstate-actions.cjs.mjs +24 -0
- package/actions/dist/xstate-actions.cjs.prod.js +3 -3
- package/actions/dist/xstate-actions.esm.js +1 -1
- 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.d.mts +2 -0
- package/actors/dist/xstate-actors.cjs.d.mts.map +1 -0
- package/actors/dist/xstate-actors.cjs.d.ts +1 -0
- package/actors/dist/xstate-actors.cjs.d.ts.map +1 -0
- package/actors/dist/xstate-actors.cjs.dev.js +2 -1
- package/actors/dist/xstate-actors.cjs.mjs +15 -0
- package/actors/dist/xstate-actors.cjs.prod.js +3 -2
- package/actors/dist/xstate-actors.esm.js +1 -1
- 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.d.mts +2 -0
- package/dev/dist/xstate-dev.cjs.d.mts.map +1 -0
- package/dev/dist/xstate-dev.cjs.d.ts +1 -0
- package/dev/dist/xstate-dev.cjs.d.ts.map +1 -0
- package/dev/dist/xstate-dev.cjs.mjs +5 -0
- package/dev/dist/xstate-dev.cjs.prod.js +6 -43
- package/dev/dist/xstate-dev.umd.min.js.map +1 -1
- package/dist/{actions-96f799fc.cjs.dev.js → actions-109712d3.cjs.dev.js} +397 -379
- package/dist/{actions-7678b87b.esm.js → actions-67f1d04e.esm.js} +351 -366
- package/dist/{actions-2479953d.cjs.prod.js → actions-d0262a43.cjs.prod.js} +420 -388
- package/dist/declarations/src/State.d.ts +2 -3
- package/dist/declarations/src/StateMachine.d.ts +6 -6
- package/dist/declarations/src/StateNode.d.ts +5 -11
- package/dist/declarations/src/actions/send.d.ts +0 -7
- package/dist/declarations/src/actions.d.ts +13 -12
- package/dist/declarations/src/actors/index.d.ts +2 -1
- package/dist/declarations/src/actors/observable.d.ts +1 -2
- package/dist/declarations/src/actors/promise.d.ts +1 -2
- package/dist/declarations/src/guards.d.ts +2 -2
- package/dist/declarations/src/index.d.ts +13 -29
- package/dist/declarations/src/interpreter.d.ts +5 -4
- package/dist/declarations/src/spawn.d.ts +2 -2
- package/dist/declarations/src/stateUtils.d.ts +15 -14
- package/dist/declarations/src/typegenTypes.d.ts +10 -4
- package/dist/declarations/src/types.d.ts +27 -101
- package/dist/declarations/src/utils.d.ts +3 -5
- package/dist/declarations/src/waitFor.d.ts +33 -0
- package/dist/index-0f3fdf0c.cjs.prod.js +52 -0
- package/dist/xstate.cjs.d.mts +2 -0
- package/dist/xstate.cjs.d.mts.map +1 -0
- package/dist/xstate.cjs.d.ts +1 -0
- package/dist/xstate.cjs.d.ts.map +1 -0
- package/dist/xstate.cjs.dev.js +125 -111
- package/dist/xstate.cjs.mjs +38 -0
- package/dist/xstate.cjs.prod.js +123 -112
- package/dist/xstate.esm.js +108 -99
- package/dist/xstate.umd.min.js +1 -1
- package/dist/xstate.umd.min.js.map +1 -1
- package/guards/dist/xstate-guards.cjs.d.mts +2 -0
- package/guards/dist/xstate-guards.cjs.d.mts.map +1 -0
- package/guards/dist/xstate-guards.cjs.d.ts +1 -0
- package/guards/dist/xstate-guards.cjs.d.ts.map +1 -0
- package/guards/dist/xstate-guards.cjs.dev.js +1 -1
- package/guards/dist/xstate-guards.cjs.mjs +8 -0
- package/guards/dist/xstate-guards.cjs.prod.js +2 -2
- package/guards/dist/xstate-guards.esm.js +1 -1
- package/guards/dist/xstate-guards.umd.min.js +1 -1
- package/guards/dist/xstate-guards.umd.min.js.map +1 -1
- package/package.json +7 -1
- package/dist/declarations/src/schema.d.ts +0 -2
|
@@ -1,8 +1,40 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var dev_dist_xstateDev = require('
|
|
3
|
+
var dev_dist_xstateDev = require('./index-0f3fdf0c.cjs.prod.js');
|
|
4
4
|
|
|
5
5
|
// https://github.com/microsoft/TypeScript/issues/23182#issuecomment-379091887
|
|
6
|
+
|
|
7
|
+
// TODO: replace in v5 with:
|
|
8
|
+
// export type IndexByType<T extends { type: string }> = { [E in T as E['type']]: E; };
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The full definition of an event, with a string `type`.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
// TODO: do not accept machines without all implementations
|
|
15
|
+
// we should also accept a raw machine as a behavior here
|
|
16
|
+
// or just make machine a behavior
|
|
17
|
+
|
|
18
|
+
// TODO: narrow this to behaviors from machine
|
|
19
|
+
|
|
20
|
+
// TODO: fix last param
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Extracts action objects that have no extra properties.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The string or object representing the state value relative to the parent state node.
|
|
28
|
+
*
|
|
29
|
+
* - For a child atomic state node, this is a string, e.g., `"pending"`.
|
|
30
|
+
* - For complex state nodes, this is an object, e.g., `{ success: "someChildState" }`.
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
// TODO: remove once TS fixes this type-widening issue
|
|
34
|
+
|
|
35
|
+
// TODO: possibly refactor this somehow, use even a simpler type, and maybe even make `machine.options` private or something
|
|
36
|
+
|
|
37
|
+
exports.ActionTypes = void 0;
|
|
6
38
|
(function (ActionTypes) {
|
|
7
39
|
ActionTypes["Stop"] = "xstate.stop";
|
|
8
40
|
ActionTypes["Raise"] = "xstate.raise";
|
|
@@ -22,45 +54,46 @@ var dev_dist_xstateDev = require('../dev/dist/xstate-dev.cjs.prod.js');
|
|
|
22
54
|
ActionTypes["Pure"] = "xstate.pure";
|
|
23
55
|
ActionTypes["Choose"] = "xstate.choose";
|
|
24
56
|
})(exports.ActionTypes || (exports.ActionTypes = {}));
|
|
57
|
+
exports.SpecialTargets = void 0;
|
|
25
58
|
(function (SpecialTargets) {
|
|
26
59
|
SpecialTargets["Parent"] = "#_parent";
|
|
27
60
|
SpecialTargets["Internal"] = "#_internal";
|
|
28
61
|
})(exports.SpecialTargets || (exports.SpecialTargets = {}));
|
|
29
62
|
|
|
30
63
|
// xstate-specific action types
|
|
31
|
-
var stop = exports.ActionTypes.Stop;
|
|
32
|
-
var raise = exports.ActionTypes.Raise;
|
|
33
|
-
var send = exports.ActionTypes.Send;
|
|
34
|
-
var cancel = exports.ActionTypes.Cancel;
|
|
35
|
-
var assign = exports.ActionTypes.Assign;
|
|
36
|
-
var after = exports.ActionTypes.After;
|
|
64
|
+
var stop$1 = exports.ActionTypes.Stop;
|
|
65
|
+
var raise$1 = exports.ActionTypes.Raise;
|
|
66
|
+
var send$1 = exports.ActionTypes.Send;
|
|
67
|
+
var cancel$1 = exports.ActionTypes.Cancel;
|
|
68
|
+
var assign$1 = exports.ActionTypes.Assign;
|
|
69
|
+
var after$1 = exports.ActionTypes.After;
|
|
37
70
|
var doneState = exports.ActionTypes.DoneState;
|
|
38
|
-
var log = exports.ActionTypes.Log;
|
|
71
|
+
var log$1 = exports.ActionTypes.Log;
|
|
39
72
|
var init = exports.ActionTypes.Init;
|
|
40
|
-
var invoke = exports.ActionTypes.Invoke;
|
|
73
|
+
var invoke$1 = exports.ActionTypes.Invoke;
|
|
41
74
|
var errorExecution = exports.ActionTypes.ErrorExecution;
|
|
42
75
|
var errorPlatform = exports.ActionTypes.ErrorPlatform;
|
|
43
|
-
var error = exports.ActionTypes.ErrorCustom;
|
|
44
|
-
var choose = exports.ActionTypes.Choose;
|
|
45
|
-
var pure = exports.ActionTypes.Pure;
|
|
76
|
+
var error$1 = exports.ActionTypes.ErrorCustom;
|
|
77
|
+
var choose$1 = exports.ActionTypes.Choose;
|
|
78
|
+
var pure$1 = exports.ActionTypes.Pure;
|
|
46
79
|
|
|
47
80
|
var actionTypes = /*#__PURE__*/Object.freeze({
|
|
48
81
|
__proto__: null,
|
|
49
|
-
stop: stop,
|
|
50
|
-
raise: raise,
|
|
51
|
-
send: send,
|
|
52
|
-
cancel: cancel,
|
|
53
|
-
assign: assign,
|
|
54
|
-
after: after,
|
|
82
|
+
stop: stop$1,
|
|
83
|
+
raise: raise$1,
|
|
84
|
+
send: send$1,
|
|
85
|
+
cancel: cancel$1,
|
|
86
|
+
assign: assign$1,
|
|
87
|
+
after: after$1,
|
|
55
88
|
doneState: doneState,
|
|
56
|
-
log: log,
|
|
89
|
+
log: log$1,
|
|
57
90
|
init: init,
|
|
58
|
-
invoke: invoke,
|
|
91
|
+
invoke: invoke$1,
|
|
59
92
|
errorExecution: errorExecution,
|
|
60
93
|
errorPlatform: errorPlatform,
|
|
61
|
-
error: error,
|
|
62
|
-
choose: choose,
|
|
63
|
-
pure: pure
|
|
94
|
+
error: error$1,
|
|
95
|
+
choose: choose$1,
|
|
96
|
+
pure: pure$1
|
|
64
97
|
});
|
|
65
98
|
|
|
66
99
|
function _toPrimitive(input, hint) {
|
|
@@ -288,7 +321,7 @@ function toStatePath(stateId, delimiter) {
|
|
|
288
321
|
}
|
|
289
322
|
}
|
|
290
323
|
function isStateLike(state) {
|
|
291
|
-
return _typeof(state) === 'object' && 'value' in state && 'context' in state && 'event' in state
|
|
324
|
+
return _typeof(state) === 'object' && 'value' in state && 'context' in state && 'event' in state;
|
|
292
325
|
}
|
|
293
326
|
function toStateValue(stateValue, delimiter) {
|
|
294
327
|
if (isStateLike(stateValue)) {
|
|
@@ -344,17 +377,17 @@ function toArray(value) {
|
|
|
344
377
|
}
|
|
345
378
|
return toArrayStrict(value);
|
|
346
379
|
}
|
|
347
|
-
function mapContext(mapper, context,
|
|
380
|
+
function mapContext(mapper, context, event) {
|
|
348
381
|
if (isFunction(mapper)) {
|
|
349
382
|
return mapper({
|
|
350
383
|
context: context,
|
|
351
|
-
event:
|
|
384
|
+
event: event
|
|
352
385
|
});
|
|
353
386
|
}
|
|
354
387
|
var result = {};
|
|
355
388
|
var args = {
|
|
356
389
|
context: context,
|
|
357
|
-
event:
|
|
390
|
+
event: event
|
|
358
391
|
};
|
|
359
392
|
for (var _i4 = 0, _Object$keys2 = Object.keys(mapper); _i4 < _Object$keys2.length; _i4++) {
|
|
360
393
|
var _key3 = _Object$keys2[_i4];
|
|
@@ -380,6 +413,22 @@ function isPromiseLike(value) {
|
|
|
380
413
|
|
|
381
414
|
// tslint:disable-next-line:no-empty
|
|
382
415
|
var warn = function warn() {};
|
|
416
|
+
if (!dev_dist_xstateDev.IS_PRODUCTION) {
|
|
417
|
+
warn = function warn(condition, message) {
|
|
418
|
+
var error = condition instanceof Error ? condition : undefined;
|
|
419
|
+
if (!error && condition) {
|
|
420
|
+
return;
|
|
421
|
+
}
|
|
422
|
+
if (console !== undefined) {
|
|
423
|
+
var args = ["Warning: ".concat(message)];
|
|
424
|
+
if (error) {
|
|
425
|
+
args.push(error);
|
|
426
|
+
}
|
|
427
|
+
// tslint:disable-next-line:no-console
|
|
428
|
+
console.warn.apply(console, args);
|
|
429
|
+
}
|
|
430
|
+
};
|
|
431
|
+
}
|
|
383
432
|
function isArray(value) {
|
|
384
433
|
return Array.isArray(value);
|
|
385
434
|
}
|
|
@@ -391,22 +440,8 @@ function isFunction(value) {
|
|
|
391
440
|
function isString(value) {
|
|
392
441
|
return typeof value === 'string';
|
|
393
442
|
}
|
|
394
|
-
function
|
|
395
|
-
return
|
|
396
|
-
}
|
|
397
|
-
function isSCXMLErrorEvent(event) {
|
|
398
|
-
return typeof event.name === 'string' && (event.name === errorExecution || event.name.startsWith(errorPlatform));
|
|
399
|
-
}
|
|
400
|
-
function toSCXMLEvent(event, scxmlEvent) {
|
|
401
|
-
if (isSCXMLEvent(event)) {
|
|
402
|
-
return event;
|
|
403
|
-
}
|
|
404
|
-
return _objectSpread2({
|
|
405
|
-
name: event.type,
|
|
406
|
-
data: event,
|
|
407
|
-
$$type: 'scxml',
|
|
408
|
-
type: 'external'
|
|
409
|
-
}, scxmlEvent);
|
|
443
|
+
function isErrorEvent(event) {
|
|
444
|
+
return typeof event.type === 'string' && (event.type === errorExecution || event.type.startsWith(errorPlatform));
|
|
410
445
|
}
|
|
411
446
|
function toTransitionConfigArray(event, configLike) {
|
|
412
447
|
var transitions = toArrayStrict(configLike).map(function (transitionLike) {
|
|
@@ -488,16 +523,16 @@ function isDynamicAction(action) {
|
|
|
488
523
|
* - `delay` - The number of milliseconds to delay the sending of the event.
|
|
489
524
|
* - `to` - The target of this event (by default, the machine the event was sent from).
|
|
490
525
|
*/
|
|
491
|
-
function send
|
|
526
|
+
function send(eventOrExpr, options) {
|
|
492
527
|
return createDynamicAction({
|
|
493
|
-
type: send,
|
|
528
|
+
type: send$1,
|
|
494
529
|
params: {
|
|
495
530
|
to: options ? options.to : undefined,
|
|
496
531
|
delay: options ? options.delay : undefined,
|
|
497
532
|
event: eventOrExpr,
|
|
498
533
|
id: options && options.id !== undefined ? options.id : isFunction(eventOrExpr) ? eventOrExpr.name : eventOrExpr.type
|
|
499
534
|
}
|
|
500
|
-
}, function (
|
|
535
|
+
}, function (event, _ref) {
|
|
501
536
|
var _actorContext$self;
|
|
502
537
|
var actorContext = _ref.actorContext,
|
|
503
538
|
state = _ref.state;
|
|
@@ -511,15 +546,17 @@ function send$1(eventOrExpr, options) {
|
|
|
511
546
|
};
|
|
512
547
|
var args = {
|
|
513
548
|
context: state.context,
|
|
514
|
-
event:
|
|
515
|
-
_event: _event,
|
|
549
|
+
event: event,
|
|
516
550
|
self: (_actorContext$self = actorContext === null || actorContext === void 0 ? void 0 : actorContext.self) !== null && _actorContext$self !== void 0 ? _actorContext$self : null,
|
|
517
551
|
system: actorContext === null || actorContext === void 0 ? void 0 : actorContext.system
|
|
518
552
|
};
|
|
519
553
|
var delaysMap = state.machine.options.delays;
|
|
520
554
|
|
|
521
555
|
// TODO: helper function for resolving Expr
|
|
522
|
-
|
|
556
|
+
if (typeof eventOrExpr === 'string') {
|
|
557
|
+
throw new Error("Only event objects may be used with sendTo; use sendTo({ type: \"".concat(eventOrExpr, "\" }) instead"));
|
|
558
|
+
}
|
|
559
|
+
var resolvedEvent = isFunction(eventOrExpr) ? eventOrExpr(args) : eventOrExpr;
|
|
523
560
|
var resolvedDelay;
|
|
524
561
|
if (isString(params.delay)) {
|
|
525
562
|
var configDelay = delaysMap && delaysMap[params.delay];
|
|
@@ -548,11 +585,10 @@ function send$1(eventOrExpr, options) {
|
|
|
548
585
|
targetActorRef = resolvedTarget || (actorContext === null || actorContext === void 0 ? void 0 : actorContext.self);
|
|
549
586
|
}
|
|
550
587
|
var resolvedAction = {
|
|
551
|
-
type: send,
|
|
588
|
+
type: send$1,
|
|
552
589
|
params: _objectSpread2(_objectSpread2({}, params), {}, {
|
|
553
590
|
to: targetActorRef,
|
|
554
|
-
|
|
555
|
-
event: resolvedEvent.data,
|
|
591
|
+
event: resolvedEvent,
|
|
556
592
|
delay: resolvedDelay,
|
|
557
593
|
internal: resolvedTarget === exports.SpecialTargets.Internal
|
|
558
594
|
}),
|
|
@@ -563,14 +599,12 @@ function send$1(eventOrExpr, options) {
|
|
|
563
599
|
return;
|
|
564
600
|
} else {
|
|
565
601
|
var target = sendAction.params.to;
|
|
566
|
-
var
|
|
602
|
+
var sentEvent = sendAction.params.event;
|
|
567
603
|
actorCtx.defer(function () {
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
});
|
|
573
|
-
target.send(resolvedEvent);
|
|
604
|
+
target.send(sentEvent.type === error$1 ? {
|
|
605
|
+
type: "".concat(error(actorCtx.self.id)),
|
|
606
|
+
data: sentEvent.data
|
|
607
|
+
} : sendAction.params.event);
|
|
574
608
|
});
|
|
575
609
|
}
|
|
576
610
|
}
|
|
@@ -586,26 +620,11 @@ function send$1(eventOrExpr, options) {
|
|
|
586
620
|
* @param options Options to pass into the send event.
|
|
587
621
|
*/
|
|
588
622
|
function sendParent(event, options) {
|
|
589
|
-
return send
|
|
623
|
+
return send(event, _objectSpread2(_objectSpread2({}, options), {}, {
|
|
590
624
|
to: exports.SpecialTargets.Parent
|
|
591
625
|
}));
|
|
592
626
|
}
|
|
593
627
|
|
|
594
|
-
/**
|
|
595
|
-
* Sends an event back to the sender of the original event.
|
|
596
|
-
*
|
|
597
|
-
* @param event The event to send back to the sender
|
|
598
|
-
* @param options Options to pass into the send event
|
|
599
|
-
*/
|
|
600
|
-
function respond(event, options) {
|
|
601
|
-
return send$1(event, _objectSpread2(_objectSpread2({}, options), {}, {
|
|
602
|
-
to: function to(_ref2) {
|
|
603
|
-
var _event = _ref2._event;
|
|
604
|
-
return _event.origin; // TODO: handle when _event.origin is undefined
|
|
605
|
-
}
|
|
606
|
-
}));
|
|
607
|
-
}
|
|
608
|
-
|
|
609
628
|
/**
|
|
610
629
|
* Forwards (sends) an event to a specified service.
|
|
611
630
|
*
|
|
@@ -613,18 +632,8 @@ function respond(event, options) {
|
|
|
613
632
|
* @param options Options to pass into the send action creator.
|
|
614
633
|
*/
|
|
615
634
|
function forwardTo(target, options) {
|
|
616
|
-
|
|
617
|
-
var
|
|
618
|
-
target = function target() {
|
|
619
|
-
var resolvedTarget = typeof originalTarget === 'function' ? originalTarget.apply(void 0, arguments) : originalTarget;
|
|
620
|
-
if (!resolvedTarget) {
|
|
621
|
-
throw new Error("Attempted to forward event to undefined actor. This risks an infinite loop in the sender.");
|
|
622
|
-
}
|
|
623
|
-
return resolvedTarget;
|
|
624
|
-
};
|
|
625
|
-
}
|
|
626
|
-
return send$1(function (_ref3) {
|
|
627
|
-
var event = _ref3.event;
|
|
635
|
+
return send(function (_ref2) {
|
|
636
|
+
var event = _ref2.event;
|
|
628
637
|
return event;
|
|
629
638
|
}, _objectSpread2(_objectSpread2({}, options), {}, {
|
|
630
639
|
to: target
|
|
@@ -641,7 +650,7 @@ function forwardTo(target, options) {
|
|
|
641
650
|
function escalate(errorData, options) {
|
|
642
651
|
return sendParent(function (arg) {
|
|
643
652
|
return {
|
|
644
|
-
type: error,
|
|
653
|
+
type: error$1,
|
|
645
654
|
data: isFunction(errorData) ? errorData(arg) : errorData
|
|
646
655
|
};
|
|
647
656
|
}, _objectSpread2(_objectSpread2({}, options), {}, {
|
|
@@ -658,7 +667,7 @@ function escalate(errorData, options) {
|
|
|
658
667
|
* @returns An XState send action object
|
|
659
668
|
*/
|
|
660
669
|
function sendTo(actor, event, options) {
|
|
661
|
-
return send
|
|
670
|
+
return send(event, _objectSpread2(_objectSpread2({}, options), {}, {
|
|
662
671
|
to: actor
|
|
663
672
|
}));
|
|
664
673
|
}
|
|
@@ -782,11 +791,9 @@ var symbolObservable = function () {
|
|
|
782
791
|
*/
|
|
783
792
|
function fromTransition(_transition, initialState) {
|
|
784
793
|
var behavior = {
|
|
794
|
+
config: _transition,
|
|
785
795
|
transition: function transition(state, event, actorContext) {
|
|
786
|
-
|
|
787
|
-
var resolvedEvent = isSCXMLEvent(event) ? event.data : event;
|
|
788
|
-
// @ts-ignore TODO
|
|
789
|
-
return _transition(state, resolvedEvent, actorContext);
|
|
796
|
+
return _transition(state, event, actorContext);
|
|
790
797
|
},
|
|
791
798
|
getInitialState: function getInitialState(_, input) {
|
|
792
799
|
return typeof initialState === 'function' ? initialState({
|
|
@@ -814,27 +821,29 @@ promiseCreator) {
|
|
|
814
821
|
|
|
815
822
|
// TODO: add event types
|
|
816
823
|
var behavior = {
|
|
824
|
+
config: promiseCreator,
|
|
817
825
|
transition: function transition(state, event) {
|
|
818
|
-
|
|
819
|
-
if (state.canceled) {
|
|
826
|
+
if (state.status !== 'active') {
|
|
820
827
|
return state;
|
|
821
828
|
}
|
|
822
|
-
|
|
823
|
-
switch (_event.name) {
|
|
829
|
+
switch (event.type) {
|
|
824
830
|
case resolveEventType:
|
|
825
|
-
state
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
831
|
+
return _objectSpread2(_objectSpread2({}, state), {}, {
|
|
832
|
+
status: 'done',
|
|
833
|
+
data: event.data,
|
|
834
|
+
input: undefined
|
|
835
|
+
});
|
|
829
836
|
case rejectEventType:
|
|
830
|
-
state
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
837
|
+
return _objectSpread2(_objectSpread2({}, state), {}, {
|
|
838
|
+
status: 'error',
|
|
839
|
+
data: event.data,
|
|
840
|
+
input: undefined
|
|
841
|
+
});
|
|
834
842
|
case stopSignalType:
|
|
835
|
-
state
|
|
836
|
-
|
|
837
|
-
|
|
843
|
+
return _objectSpread2(_objectSpread2({}, state), {}, {
|
|
844
|
+
status: 'canceled',
|
|
845
|
+
input: undefined
|
|
846
|
+
});
|
|
838
847
|
default:
|
|
839
848
|
return state;
|
|
840
849
|
}
|
|
@@ -850,11 +859,19 @@ promiseCreator) {
|
|
|
850
859
|
input: state.input
|
|
851
860
|
}));
|
|
852
861
|
resolvedPromise.then(function (response) {
|
|
862
|
+
// TODO: remove this condition once dead letter queue lands
|
|
863
|
+
if (self._state.status !== 'active') {
|
|
864
|
+
return;
|
|
865
|
+
}
|
|
853
866
|
self.send({
|
|
854
867
|
type: resolveEventType,
|
|
855
868
|
data: response
|
|
856
869
|
});
|
|
857
870
|
}, function (errorData) {
|
|
871
|
+
// TODO: remove this condition once dead letter queue lands
|
|
872
|
+
if (self._state.status !== 'active') {
|
|
873
|
+
return;
|
|
874
|
+
}
|
|
858
875
|
self.send({
|
|
859
876
|
type: rejectEventType,
|
|
860
877
|
data: errorData
|
|
@@ -863,7 +880,6 @@ promiseCreator) {
|
|
|
863
880
|
},
|
|
864
881
|
getInitialState: function getInitialState(_, input) {
|
|
865
882
|
return {
|
|
866
|
-
canceled: false,
|
|
867
883
|
status: 'active',
|
|
868
884
|
data: undefined,
|
|
869
885
|
input: input
|
|
@@ -893,43 +909,48 @@ function fromObservable(observableCreator) {
|
|
|
893
909
|
|
|
894
910
|
// TODO: add event types
|
|
895
911
|
var behavior = {
|
|
912
|
+
config: observableCreator,
|
|
896
913
|
transition: function transition(state, event, _ref) {
|
|
897
914
|
var self = _ref.self,
|
|
898
915
|
id = _ref.id,
|
|
899
916
|
defer = _ref.defer;
|
|
900
|
-
|
|
901
|
-
if (state.canceled) {
|
|
917
|
+
if (state.status !== 'active') {
|
|
902
918
|
return state;
|
|
903
919
|
}
|
|
904
|
-
switch (
|
|
920
|
+
switch (event.type) {
|
|
905
921
|
case nextEventType:
|
|
906
|
-
state.data = event.data.data;
|
|
907
922
|
// match the exact timing of events sent by machines
|
|
908
923
|
// send actions are not executed immediately
|
|
909
924
|
defer(function () {
|
|
910
925
|
var _self$_parent;
|
|
911
|
-
(_self$_parent = self._parent) === null || _self$_parent === void 0 ? void 0 : _self$_parent.send(
|
|
926
|
+
(_self$_parent = self._parent) === null || _self$_parent === void 0 ? void 0 : _self$_parent.send({
|
|
912
927
|
type: "xstate.snapshot.".concat(id),
|
|
913
|
-
data:
|
|
914
|
-
}
|
|
915
|
-
|
|
916
|
-
|
|
928
|
+
data: event.data
|
|
929
|
+
});
|
|
930
|
+
});
|
|
931
|
+
return _objectSpread2(_objectSpread2({}, state), {}, {
|
|
932
|
+
data: event.data
|
|
917
933
|
});
|
|
918
|
-
return state;
|
|
919
934
|
case errorEventType:
|
|
920
|
-
state
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
935
|
+
return _objectSpread2(_objectSpread2({}, state), {}, {
|
|
936
|
+
status: 'error',
|
|
937
|
+
input: undefined,
|
|
938
|
+
data: event.data,
|
|
939
|
+
subscription: undefined
|
|
940
|
+
});
|
|
924
941
|
case completeEventType:
|
|
925
|
-
state
|
|
926
|
-
|
|
927
|
-
|
|
942
|
+
return _objectSpread2(_objectSpread2({}, state), {}, {
|
|
943
|
+
status: 'done',
|
|
944
|
+
input: undefined,
|
|
945
|
+
subscription: undefined
|
|
946
|
+
});
|
|
928
947
|
case stopSignalType:
|
|
929
|
-
state.canceled = true;
|
|
930
|
-
delete state.input;
|
|
931
948
|
state.subscription.unsubscribe();
|
|
932
|
-
return state
|
|
949
|
+
return _objectSpread2(_objectSpread2({}, state), {}, {
|
|
950
|
+
status: 'canceled',
|
|
951
|
+
input: undefined,
|
|
952
|
+
subscription: undefined
|
|
953
|
+
});
|
|
933
954
|
default:
|
|
934
955
|
return state;
|
|
935
956
|
}
|
|
@@ -937,7 +958,6 @@ function fromObservable(observableCreator) {
|
|
|
937
958
|
getInitialState: function getInitialState(_, input) {
|
|
938
959
|
return {
|
|
939
960
|
subscription: undefined,
|
|
940
|
-
canceled: false,
|
|
941
961
|
status: 'active',
|
|
942
962
|
data: undefined,
|
|
943
963
|
input: input
|
|
@@ -975,12 +995,10 @@ function fromObservable(observableCreator) {
|
|
|
975
995
|
return state.data;
|
|
976
996
|
},
|
|
977
997
|
getPersistedState: function getPersistedState(_ref3) {
|
|
978
|
-
var
|
|
979
|
-
status = _ref3.status,
|
|
998
|
+
var status = _ref3.status,
|
|
980
999
|
data = _ref3.data,
|
|
981
1000
|
input = _ref3.input;
|
|
982
1001
|
return {
|
|
983
|
-
canceled: canceled,
|
|
984
1002
|
status: status,
|
|
985
1003
|
data: data,
|
|
986
1004
|
input: input
|
|
@@ -1013,26 +1031,32 @@ function fromEventObservable(lazyObservable) {
|
|
|
1013
1031
|
|
|
1014
1032
|
// TODO: event types
|
|
1015
1033
|
var behavior = {
|
|
1034
|
+
config: lazyObservable,
|
|
1016
1035
|
transition: function transition(state, event) {
|
|
1017
|
-
|
|
1018
|
-
if (state.canceled) {
|
|
1036
|
+
if (state.status !== 'active') {
|
|
1019
1037
|
return state;
|
|
1020
1038
|
}
|
|
1021
|
-
switch (
|
|
1039
|
+
switch (event.type) {
|
|
1022
1040
|
case errorEventType:
|
|
1023
|
-
state
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1041
|
+
return _objectSpread2(_objectSpread2({}, state), {}, {
|
|
1042
|
+
status: 'error',
|
|
1043
|
+
input: undefined,
|
|
1044
|
+
data: event.data,
|
|
1045
|
+
subscription: undefined
|
|
1046
|
+
});
|
|
1027
1047
|
case completeEventType:
|
|
1028
|
-
state
|
|
1029
|
-
|
|
1030
|
-
|
|
1048
|
+
return _objectSpread2(_objectSpread2({}, state), {}, {
|
|
1049
|
+
status: 'done',
|
|
1050
|
+
input: undefined,
|
|
1051
|
+
subscription: undefined
|
|
1052
|
+
});
|
|
1031
1053
|
case stopSignalType:
|
|
1032
|
-
state.canceled = true;
|
|
1033
|
-
delete state.input;
|
|
1034
1054
|
state.subscription.unsubscribe();
|
|
1035
|
-
return state
|
|
1055
|
+
return _objectSpread2(_objectSpread2({}, state), {}, {
|
|
1056
|
+
status: 'canceled',
|
|
1057
|
+
input: undefined,
|
|
1058
|
+
subscription: undefined
|
|
1059
|
+
});
|
|
1036
1060
|
default:
|
|
1037
1061
|
return state;
|
|
1038
1062
|
}
|
|
@@ -1040,7 +1064,6 @@ function fromEventObservable(lazyObservable) {
|
|
|
1040
1064
|
getInitialState: function getInitialState() {
|
|
1041
1065
|
return {
|
|
1042
1066
|
subscription: undefined,
|
|
1043
|
-
canceled: false,
|
|
1044
1067
|
status: 'active',
|
|
1045
1068
|
data: undefined
|
|
1046
1069
|
};
|
|
@@ -1056,9 +1079,7 @@ function fromEventObservable(lazyObservable) {
|
|
|
1056
1079
|
}).subscribe({
|
|
1057
1080
|
next: function next(value) {
|
|
1058
1081
|
var _self$_parent2;
|
|
1059
|
-
(_self$_parent2 = self._parent) === null || _self$_parent2 === void 0 ? void 0 : _self$_parent2.send(
|
|
1060
|
-
origin: self
|
|
1061
|
-
}));
|
|
1082
|
+
(_self$_parent2 = self._parent) === null || _self$_parent2 === void 0 ? void 0 : _self$_parent2.send(value);
|
|
1062
1083
|
},
|
|
1063
1084
|
error: function error(err) {
|
|
1064
1085
|
self.send({
|
|
@@ -1077,12 +1098,10 @@ function fromEventObservable(lazyObservable) {
|
|
|
1077
1098
|
return undefined;
|
|
1078
1099
|
},
|
|
1079
1100
|
getPersistedState: function getPersistedState(_ref5) {
|
|
1080
|
-
var
|
|
1081
|
-
status = _ref5.status,
|
|
1101
|
+
var status = _ref5.status,
|
|
1082
1102
|
data = _ref5.data,
|
|
1083
1103
|
input = _ref5.input;
|
|
1084
1104
|
return {
|
|
1085
|
-
canceled: canceled,
|
|
1086
1105
|
status: status,
|
|
1087
1106
|
data: data,
|
|
1088
1107
|
input: input
|
|
@@ -1102,6 +1121,7 @@ function fromEventObservable(lazyObservable) {
|
|
|
1102
1121
|
|
|
1103
1122
|
function fromCallback(invokeCallback) {
|
|
1104
1123
|
var behavior = {
|
|
1124
|
+
config: invokeCallback,
|
|
1105
1125
|
start: function start(_state, _ref) {
|
|
1106
1126
|
var self = _ref.self;
|
|
1107
1127
|
self.send({
|
|
@@ -1111,16 +1131,13 @@ function fromCallback(invokeCallback) {
|
|
|
1111
1131
|
transition: function transition(state, event, _ref2) {
|
|
1112
1132
|
var self = _ref2.self,
|
|
1113
1133
|
id = _ref2.id;
|
|
1114
|
-
|
|
1115
|
-
if (_event.name === startSignalType) {
|
|
1134
|
+
if (event.type === startSignalType) {
|
|
1116
1135
|
var sender = function sender(eventForParent) {
|
|
1117
1136
|
var _self$_parent;
|
|
1118
1137
|
if (state.canceled) {
|
|
1119
|
-
return
|
|
1138
|
+
return;
|
|
1120
1139
|
}
|
|
1121
|
-
(_self$_parent = self._parent) === null || _self$_parent === void 0 ? void 0 : _self$_parent.send(
|
|
1122
|
-
origin: self
|
|
1123
|
-
}));
|
|
1140
|
+
(_self$_parent = self._parent) === null || _self$_parent === void 0 ? void 0 : _self$_parent.send(eventForParent);
|
|
1124
1141
|
};
|
|
1125
1142
|
var receiver = function receiver(newListener) {
|
|
1126
1143
|
state.receivers.add(newListener);
|
|
@@ -1131,36 +1148,30 @@ function fromCallback(invokeCallback) {
|
|
|
1131
1148
|
if (isPromiseLike(state.dispose)) {
|
|
1132
1149
|
state.dispose.then(function (resolved) {
|
|
1133
1150
|
var _self$_parent2;
|
|
1134
|
-
(_self$_parent2 = self._parent) === null || _self$_parent2 === void 0 ? void 0 : _self$_parent2.send(
|
|
1135
|
-
origin: self
|
|
1136
|
-
}));
|
|
1151
|
+
(_self$_parent2 = self._parent) === null || _self$_parent2 === void 0 ? void 0 : _self$_parent2.send(doneInvoke(id, resolved));
|
|
1137
1152
|
state.canceled = true;
|
|
1138
1153
|
}, function (errorData) {
|
|
1139
1154
|
var _self$_parent3;
|
|
1140
|
-
var errorEvent = error$1(id, errorData);
|
|
1141
|
-
(_self$_parent3 = self._parent) === null || _self$_parent3 === void 0 ? void 0 : _self$_parent3.send(toSCXMLEvent(errorEvent, {
|
|
1142
|
-
origin: self
|
|
1143
|
-
}));
|
|
1144
1155
|
state.canceled = true;
|
|
1156
|
+
(_self$_parent3 = self._parent) === null || _self$_parent3 === void 0 ? void 0 : _self$_parent3.send(error(id, errorData));
|
|
1145
1157
|
});
|
|
1146
1158
|
}
|
|
1147
1159
|
return state;
|
|
1148
1160
|
}
|
|
1149
|
-
if (
|
|
1161
|
+
if (event.type === stopSignalType) {
|
|
1150
1162
|
state.canceled = true;
|
|
1151
1163
|
if (isFunction(state.dispose)) {
|
|
1152
1164
|
state.dispose();
|
|
1153
1165
|
}
|
|
1154
1166
|
return state;
|
|
1155
1167
|
}
|
|
1156
|
-
if (isSignal(
|
|
1168
|
+
if (isSignal(event.type)) {
|
|
1157
1169
|
// TODO: unrecognized signal
|
|
1158
1170
|
return state;
|
|
1159
1171
|
}
|
|
1160
|
-
|
|
1161
|
-
if (!isSignal(plainEvent.type)) {
|
|
1172
|
+
if (!isSignal(event.type)) {
|
|
1162
1173
|
state.receivers.forEach(function (receiver) {
|
|
1163
|
-
return receiver(
|
|
1174
|
+
return receiver(event);
|
|
1164
1175
|
});
|
|
1165
1176
|
}
|
|
1166
1177
|
return state;
|
|
@@ -1231,6 +1242,12 @@ function toActorRef(actorRefLike) {
|
|
|
1231
1242
|
return void 0;
|
|
1232
1243
|
}), _objectSpread2$1), actorRefLike);
|
|
1233
1244
|
}
|
|
1245
|
+
var emptyBehavior = fromTransition(function (_) {
|
|
1246
|
+
return undefined;
|
|
1247
|
+
}, undefined);
|
|
1248
|
+
function createEmptyActor() {
|
|
1249
|
+
return interpret(emptyBehavior);
|
|
1250
|
+
}
|
|
1234
1251
|
|
|
1235
1252
|
function createSystem() {
|
|
1236
1253
|
var sessionIdCounter = 0;
|
|
@@ -1268,6 +1285,7 @@ function createSystem() {
|
|
|
1268
1285
|
return system;
|
|
1269
1286
|
}
|
|
1270
1287
|
|
|
1288
|
+
exports.ActorStatus = void 0;
|
|
1271
1289
|
(function (ActorStatus) {
|
|
1272
1290
|
ActorStatus[ActorStatus["NotStarted"] = 0] = "NotStarted";
|
|
1273
1291
|
ActorStatus[ActorStatus["Running"] = 1] = "Running";
|
|
@@ -1423,9 +1441,9 @@ var Interpreter = /*#__PURE__*/function () {
|
|
|
1423
1441
|
_step;
|
|
1424
1442
|
try {
|
|
1425
1443
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
1426
|
-
var
|
|
1427
|
-
var
|
|
1428
|
-
(
|
|
1444
|
+
var _observer$next;
|
|
1445
|
+
var _observer = _step.value;
|
|
1446
|
+
(_observer$next = _observer.next) === null || _observer$next === void 0 ? void 0 : _observer$next.call(_observer, snapshot);
|
|
1429
1447
|
}
|
|
1430
1448
|
} catch (err) {
|
|
1431
1449
|
_iterator.e(err);
|
|
@@ -1435,30 +1453,15 @@ var Interpreter = /*#__PURE__*/function () {
|
|
|
1435
1453
|
var status = (_this$behavior$getSta = (_this$behavior = this.behavior).getStatus) === null || _this$behavior$getSta === void 0 ? void 0 : _this$behavior$getSta.call(_this$behavior, state);
|
|
1436
1454
|
switch (status === null || status === void 0 ? void 0 : status.status) {
|
|
1437
1455
|
case 'done':
|
|
1438
|
-
this._doneEvent = doneInvoke(this.id, status.data);
|
|
1439
|
-
(_this$_parent = this._parent) === null || _this$_parent === void 0 ? void 0 : _this$_parent.send(toSCXMLEvent(this._doneEvent, {
|
|
1440
|
-
origin: this,
|
|
1441
|
-
invokeid: this.id
|
|
1442
|
-
}));
|
|
1443
1456
|
this._stopProcedure();
|
|
1457
|
+
this._doneEvent = doneInvoke(this.id, status.data);
|
|
1458
|
+
(_this$_parent = this._parent) === null || _this$_parent === void 0 ? void 0 : _this$_parent.send(this._doneEvent);
|
|
1459
|
+
this._complete();
|
|
1444
1460
|
break;
|
|
1445
1461
|
case 'error':
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
var _iterator2 = _createForOfIteratorHelper(this.observers),
|
|
1450
|
-
_step2;
|
|
1451
|
-
try {
|
|
1452
|
-
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
1453
|
-
var _observer$error;
|
|
1454
|
-
var _observer = _step2.value;
|
|
1455
|
-
(_observer$error = _observer.error) === null || _observer$error === void 0 ? void 0 : _observer$error.call(_observer, status.data);
|
|
1456
|
-
}
|
|
1457
|
-
} catch (err) {
|
|
1458
|
-
_iterator2.e(err);
|
|
1459
|
-
} finally {
|
|
1460
|
-
_iterator2.f();
|
|
1461
|
-
}
|
|
1462
|
+
this._stopProcedure();
|
|
1463
|
+
(_this$_parent2 = this._parent) === null || _this$_parent2 === void 0 ? void 0 : _this$_parent2.send(error(this.id, status.data));
|
|
1464
|
+
this._error(status.data);
|
|
1462
1465
|
break;
|
|
1463
1466
|
}
|
|
1464
1467
|
}
|
|
@@ -1537,15 +1540,16 @@ var Interpreter = /*#__PURE__*/function () {
|
|
|
1537
1540
|
try {
|
|
1538
1541
|
var nextState = this.behavior.transition(this._state, event, this._actorContext);
|
|
1539
1542
|
this.update(nextState);
|
|
1540
|
-
if (event.
|
|
1543
|
+
if (event.type === stopSignalType) {
|
|
1541
1544
|
this._stopProcedure();
|
|
1545
|
+
this._complete();
|
|
1542
1546
|
}
|
|
1543
1547
|
} catch (err) {
|
|
1544
1548
|
// TODO: properly handle errors
|
|
1545
1549
|
if (this.observers.size > 0) {
|
|
1546
1550
|
this.observers.forEach(function (observer) {
|
|
1547
|
-
var _observer$
|
|
1548
|
-
(_observer$
|
|
1551
|
+
var _observer$error;
|
|
1552
|
+
(_observer$error = observer.error) === null || _observer$error === void 0 ? void 0 : _observer$error.call(observer, err);
|
|
1549
1553
|
});
|
|
1550
1554
|
this.stop();
|
|
1551
1555
|
} else {
|
|
@@ -1564,9 +1568,9 @@ var Interpreter = /*#__PURE__*/function () {
|
|
|
1564
1568
|
this.status = exports.ActorStatus.Stopped;
|
|
1565
1569
|
return this;
|
|
1566
1570
|
}
|
|
1567
|
-
this.mailbox.enqueue(
|
|
1571
|
+
this.mailbox.enqueue({
|
|
1568
1572
|
type: stopSignalType
|
|
1569
|
-
})
|
|
1573
|
+
});
|
|
1570
1574
|
return this;
|
|
1571
1575
|
}
|
|
1572
1576
|
|
|
@@ -1584,13 +1588,31 @@ var Interpreter = /*#__PURE__*/function () {
|
|
|
1584
1588
|
}, {
|
|
1585
1589
|
key: "_complete",
|
|
1586
1590
|
value: function _complete() {
|
|
1591
|
+
var _iterator2 = _createForOfIteratorHelper(this.observers),
|
|
1592
|
+
_step2;
|
|
1593
|
+
try {
|
|
1594
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
1595
|
+
var _observer2$complete;
|
|
1596
|
+
var _observer2 = _step2.value;
|
|
1597
|
+
(_observer2$complete = _observer2.complete) === null || _observer2$complete === void 0 ? void 0 : _observer2$complete.call(_observer2);
|
|
1598
|
+
}
|
|
1599
|
+
} catch (err) {
|
|
1600
|
+
_iterator2.e(err);
|
|
1601
|
+
} finally {
|
|
1602
|
+
_iterator2.f();
|
|
1603
|
+
}
|
|
1604
|
+
this.observers.clear();
|
|
1605
|
+
}
|
|
1606
|
+
}, {
|
|
1607
|
+
key: "_error",
|
|
1608
|
+
value: function _error(data) {
|
|
1587
1609
|
var _iterator3 = _createForOfIteratorHelper(this.observers),
|
|
1588
1610
|
_step3;
|
|
1589
1611
|
try {
|
|
1590
1612
|
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
1591
|
-
var _observer3$
|
|
1613
|
+
var _observer3$error;
|
|
1592
1614
|
var _observer3 = _step3.value;
|
|
1593
|
-
(_observer3$
|
|
1615
|
+
(_observer3$error = _observer3.error) === null || _observer3$error === void 0 ? void 0 : _observer3$error.call(_observer3, data);
|
|
1594
1616
|
}
|
|
1595
1617
|
} catch (err) {
|
|
1596
1618
|
_iterator3.e(err);
|
|
@@ -1602,7 +1624,6 @@ var Interpreter = /*#__PURE__*/function () {
|
|
|
1602
1624
|
}, {
|
|
1603
1625
|
key: "_stopProcedure",
|
|
1604
1626
|
value: function _stopProcedure() {
|
|
1605
|
-
this._complete();
|
|
1606
1627
|
if (this.status !== exports.ActorStatus.Running) {
|
|
1607
1628
|
// Interpreter already stopped; do nothing
|
|
1608
1629
|
return this;
|
|
@@ -1634,16 +1655,23 @@ var Interpreter = /*#__PURE__*/function () {
|
|
|
1634
1655
|
}, {
|
|
1635
1656
|
key: "send",
|
|
1636
1657
|
value: function send(event) {
|
|
1637
|
-
|
|
1658
|
+
if (typeof event === 'string') {
|
|
1659
|
+
throw new Error("Only event objects may be sent to actors; use .send({ type: \"".concat(event, "\" }) instead"));
|
|
1660
|
+
}
|
|
1638
1661
|
if (this.status === exports.ActorStatus.Stopped) {
|
|
1662
|
+
// do nothing
|
|
1663
|
+
if (!dev_dist_xstateDev.IS_PRODUCTION) {
|
|
1664
|
+
var eventString = JSON.stringify(event);
|
|
1665
|
+
warn(false, "Event \"".concat(event.type.toString(), "\" was sent to stopped actor \"").concat(this.id, " (").concat(this.sessionId, ")\". This actor has already reached its final state, and will not transition.\nEvent: ").concat(eventString));
|
|
1666
|
+
}
|
|
1639
1667
|
return;
|
|
1640
1668
|
}
|
|
1641
1669
|
if (this.status !== exports.ActorStatus.Running && !this.options.deferEvents) {
|
|
1642
|
-
throw new Error("Event \"".concat(
|
|
1670
|
+
throw new Error("Event \"".concat(event.type, "\" was sent to uninitialized actor \"").concat(this.id
|
|
1643
1671
|
// tslint:disable-next-line:max-line-length
|
|
1644
|
-
, "\". Make sure .start() is called for this actor, or set { deferEvents: true } in the actor options.\nEvent: ").concat(JSON.stringify(
|
|
1672
|
+
, "\". Make sure .start() is called for this actor, or set { deferEvents: true } in the actor options.\nEvent: ").concat(JSON.stringify(event)));
|
|
1645
1673
|
}
|
|
1646
|
-
this.mailbox.enqueue(
|
|
1674
|
+
this.mailbox.enqueue(event);
|
|
1647
1675
|
}
|
|
1648
1676
|
|
|
1649
1677
|
// TODO: make private (and figure out a way to do this within the machine)
|
|
@@ -1653,9 +1681,9 @@ var Interpreter = /*#__PURE__*/function () {
|
|
|
1653
1681
|
var _this4 = this;
|
|
1654
1682
|
this.delayedEventsMap[sendAction.params.id] = this.clock.setTimeout(function () {
|
|
1655
1683
|
if ('to' in sendAction.params && sendAction.params.to) {
|
|
1656
|
-
sendAction.params.to.send(sendAction.params.
|
|
1684
|
+
sendAction.params.to.send(sendAction.params.event);
|
|
1657
1685
|
} else {
|
|
1658
|
-
_this4.send(sendAction.params.
|
|
1686
|
+
_this4.send(sendAction.params.event);
|
|
1659
1687
|
}
|
|
1660
1688
|
}, sendAction.params.delay);
|
|
1661
1689
|
}
|
|
@@ -1721,18 +1749,18 @@ function interpret(behavior, options) {
|
|
|
1721
1749
|
* @param actorRef The actor to stop.
|
|
1722
1750
|
*/
|
|
1723
1751
|
|
|
1724
|
-
function stop
|
|
1752
|
+
function stop(actorRef) {
|
|
1725
1753
|
var actor = actorRef;
|
|
1726
1754
|
return createDynamicAction({
|
|
1727
|
-
type: stop,
|
|
1755
|
+
type: stop$1,
|
|
1728
1756
|
params: {
|
|
1729
1757
|
actor: actor
|
|
1730
1758
|
}
|
|
1731
|
-
}, function (
|
|
1759
|
+
}, function (event, _ref) {
|
|
1732
1760
|
var state = _ref.state;
|
|
1733
1761
|
var actorRefOrString = isFunction(actor) ? actor({
|
|
1734
1762
|
context: state.context,
|
|
1735
|
-
event:
|
|
1763
|
+
event: event
|
|
1736
1764
|
}) : actor;
|
|
1737
1765
|
var actorRef = typeof actorRefOrString === 'string' ? state.children[actorRefOrString] : actorRefOrString;
|
|
1738
1766
|
return [state, {
|
|
@@ -1774,23 +1802,22 @@ var defaultLogExpr = function defaultLogExpr(_ref) {
|
|
|
1774
1802
|
* @param label The label to give to the logged expression.
|
|
1775
1803
|
*/
|
|
1776
1804
|
|
|
1777
|
-
function log
|
|
1805
|
+
function log() {
|
|
1778
1806
|
var expr = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultLogExpr;
|
|
1779
1807
|
var label = arguments.length > 1 ? arguments[1] : undefined;
|
|
1780
1808
|
return createDynamicAction({
|
|
1781
|
-
type: log,
|
|
1809
|
+
type: log$1,
|
|
1782
1810
|
params: {
|
|
1783
1811
|
label: label,
|
|
1784
1812
|
expr: expr
|
|
1785
1813
|
}
|
|
1786
|
-
}, function (
|
|
1814
|
+
}, function (event, _ref2) {
|
|
1787
1815
|
var _actorContext$self;
|
|
1788
1816
|
var state = _ref2.state,
|
|
1789
1817
|
actorContext = _ref2.actorContext;
|
|
1790
1818
|
var resolvedValue = typeof expr === 'function' ? expr({
|
|
1791
1819
|
context: state.context,
|
|
1792
|
-
event:
|
|
1793
|
-
_event: _event,
|
|
1820
|
+
event: event,
|
|
1794
1821
|
self: (_actorContext$self = actorContext === null || actorContext === void 0 ? void 0 : actorContext.self) !== null && _actorContext$self !== void 0 ? _actorContext$self : {},
|
|
1795
1822
|
system: actorContext === null || actorContext === void 0 ? void 0 : actorContext.system
|
|
1796
1823
|
}) : expr;
|
|
@@ -1821,20 +1848,19 @@ function log$1() {
|
|
|
1821
1848
|
* @param sendId The `id` of the `send(...)` action to cancel.
|
|
1822
1849
|
*/
|
|
1823
1850
|
|
|
1824
|
-
function cancel
|
|
1851
|
+
function cancel(sendId) {
|
|
1825
1852
|
return createDynamicAction({
|
|
1826
|
-
type: cancel,
|
|
1853
|
+
type: cancel$1,
|
|
1827
1854
|
params: {
|
|
1828
1855
|
sendId: sendId
|
|
1829
1856
|
}
|
|
1830
|
-
}, function (
|
|
1857
|
+
}, function (event, _ref) {
|
|
1831
1858
|
var _actorContext$self;
|
|
1832
1859
|
var state = _ref.state,
|
|
1833
1860
|
actorContext = _ref.actorContext;
|
|
1834
1861
|
var resolvedSendId = isFunction(sendId) ? sendId({
|
|
1835
1862
|
context: state.context,
|
|
1836
|
-
event:
|
|
1837
|
-
_event: _event,
|
|
1863
|
+
event: event,
|
|
1838
1864
|
self: (_actorContext$self = actorContext === null || actorContext === void 0 ? void 0 : actorContext.self) !== null && _actorContext$self !== void 0 ? _actorContext$self : {},
|
|
1839
1865
|
system: actorContext === null || actorContext === void 0 ? void 0 : actorContext.system
|
|
1840
1866
|
}) : sendId;
|
|
@@ -1920,9 +1946,9 @@ function not(guard) {
|
|
|
1920
1946
|
var evaluate = _ref2.evaluate,
|
|
1921
1947
|
guard = _ref2.guard,
|
|
1922
1948
|
context = _ref2.context,
|
|
1923
|
-
|
|
1949
|
+
event = _ref2.event,
|
|
1924
1950
|
state = _ref2.state;
|
|
1925
|
-
return !evaluate(guard.children[0], context,
|
|
1951
|
+
return !evaluate(guard.children[0], context, event, state);
|
|
1926
1952
|
}
|
|
1927
1953
|
};
|
|
1928
1954
|
}
|
|
@@ -1939,10 +1965,10 @@ function and(guards) {
|
|
|
1939
1965
|
var evaluate = _ref3.evaluate,
|
|
1940
1966
|
guard = _ref3.guard,
|
|
1941
1967
|
context = _ref3.context,
|
|
1942
|
-
|
|
1968
|
+
event = _ref3.event,
|
|
1943
1969
|
state = _ref3.state;
|
|
1944
1970
|
return guard.children.every(function (childGuard) {
|
|
1945
|
-
return evaluate(childGuard, context,
|
|
1971
|
+
return evaluate(childGuard, context, event, state);
|
|
1946
1972
|
});
|
|
1947
1973
|
}
|
|
1948
1974
|
};
|
|
@@ -1960,15 +1986,15 @@ function or(guards) {
|
|
|
1960
1986
|
var evaluate = _ref4.evaluate,
|
|
1961
1987
|
guard = _ref4.guard,
|
|
1962
1988
|
context = _ref4.context,
|
|
1963
|
-
|
|
1989
|
+
event = _ref4.event,
|
|
1964
1990
|
state = _ref4.state;
|
|
1965
1991
|
return guard.children.some(function (childGuard) {
|
|
1966
|
-
return evaluate(childGuard, context,
|
|
1992
|
+
return evaluate(childGuard, context, event, state);
|
|
1967
1993
|
});
|
|
1968
1994
|
}
|
|
1969
1995
|
};
|
|
1970
1996
|
}
|
|
1971
|
-
function evaluateGuard(guard, context,
|
|
1997
|
+
function evaluateGuard(guard, context, event, state) {
|
|
1972
1998
|
var _machine$options$guar, _machine$options, _machine$options$guar2;
|
|
1973
1999
|
var machine = state.machine;
|
|
1974
2000
|
var predicate = (_machine$options$guar = machine === null || machine === void 0 ? void 0 : (_machine$options = machine.options) === null || _machine$options === void 0 ? void 0 : (_machine$options$guar2 = _machine$options.guards) === null || _machine$options$guar2 === void 0 ? void 0 : _machine$options$guar2[guard.type]) !== null && _machine$options$guar !== void 0 ? _machine$options$guar : guard.predicate;
|
|
@@ -1977,10 +2003,9 @@ function evaluateGuard(guard, context, _event, state) {
|
|
|
1977
2003
|
}
|
|
1978
2004
|
return predicate({
|
|
1979
2005
|
context: context,
|
|
1980
|
-
event:
|
|
2006
|
+
event: event,
|
|
1981
2007
|
state: state,
|
|
1982
2008
|
guard: guard,
|
|
1983
|
-
_event: _event,
|
|
1984
2009
|
evaluate: evaluateGuard
|
|
1985
2010
|
});
|
|
1986
2011
|
}
|
|
@@ -2015,13 +2040,12 @@ function toGuardDefinition(guardConfig, getPredicate) {
|
|
|
2015
2040
|
};
|
|
2016
2041
|
}
|
|
2017
2042
|
|
|
2018
|
-
function getOutput(configuration, context,
|
|
2043
|
+
function getOutput(configuration, context, event) {
|
|
2019
2044
|
var machine = configuration[0].machine;
|
|
2020
2045
|
var finalChildStateNode = configuration.find(function (stateNode) {
|
|
2021
2046
|
return stateNode.type === 'final' && stateNode.parent === machine.root;
|
|
2022
2047
|
});
|
|
2023
|
-
|
|
2024
|
-
return doneData;
|
|
2048
|
+
return finalChildStateNode && finalChildStateNode.output ? mapContext(finalChildStateNode.output, context, event) : undefined;
|
|
2025
2049
|
}
|
|
2026
2050
|
var isAtomicStateNode = function isAtomicStateNode(stateNode) {
|
|
2027
2051
|
return stateNode.type === 'atomic' || stateNode.type === 'final';
|
|
@@ -2185,7 +2209,6 @@ var isStateId = function isStateId(str) {
|
|
|
2185
2209
|
return str[0] === STATE_IDENTIFIER;
|
|
2186
2210
|
};
|
|
2187
2211
|
function getCandidates(stateNode, receivedEventType) {
|
|
2188
|
-
var partialMatch = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
2189
2212
|
var candidates = stateNode.transitions.filter(function (transition) {
|
|
2190
2213
|
var eventType = transition.eventType;
|
|
2191
2214
|
// First, check the trivial case: event names are exactly equal
|
|
@@ -2198,7 +2221,7 @@ function getCandidates(stateNode, receivedEventType) {
|
|
|
2198
2221
|
if (eventType === WILDCARD) {
|
|
2199
2222
|
return true;
|
|
2200
2223
|
}
|
|
2201
|
-
if (!
|
|
2224
|
+
if (!eventType.endsWith('.*')) {
|
|
2202
2225
|
return false;
|
|
2203
2226
|
}
|
|
2204
2227
|
var partialEventTokens = eventType.split('.');
|
|
@@ -2229,13 +2252,13 @@ function getDelayedTransitions(stateNode) {
|
|
|
2229
2252
|
}
|
|
2230
2253
|
var mutateEntryExit = function mutateEntryExit(delay, i) {
|
|
2231
2254
|
var delayRef = isFunction(delay) ? "".concat(stateNode.id, ":delay[").concat(i, "]") : delay;
|
|
2232
|
-
var eventType = after
|
|
2233
|
-
stateNode.entry.push(
|
|
2255
|
+
var eventType = after(delayRef, stateNode.id);
|
|
2256
|
+
stateNode.entry.push(raise({
|
|
2234
2257
|
type: eventType
|
|
2235
2258
|
}, {
|
|
2236
2259
|
delay: delay
|
|
2237
2260
|
}));
|
|
2238
|
-
stateNode.exit.push(cancel
|
|
2261
|
+
stateNode.exit.push(cancel(eventType));
|
|
2239
2262
|
return eventType;
|
|
2240
2263
|
};
|
|
2241
2264
|
var delayedTransitions = isArray(afterConfig) ? afterConfig.map(function (transition, i) {
|
|
@@ -2265,9 +2288,9 @@ function getDelayedTransitions(stateNode) {
|
|
|
2265
2288
|
});
|
|
2266
2289
|
}
|
|
2267
2290
|
function formatTransition(stateNode, transitionConfig) {
|
|
2268
|
-
var _transitionConfig$
|
|
2291
|
+
var _transitionConfig$ree;
|
|
2269
2292
|
var normalizedTarget = normalizeTarget(transitionConfig.target);
|
|
2270
|
-
var
|
|
2293
|
+
var reenter = (_transitionConfig$ree = transitionConfig.reenter) !== null && _transitionConfig$ree !== void 0 ? _transitionConfig$ree : false;
|
|
2271
2294
|
var guards = stateNode.machine.options.guards;
|
|
2272
2295
|
var target = resolveTarget(stateNode, normalizedTarget);
|
|
2273
2296
|
var transition = _objectSpread2(_objectSpread2({}, transitionConfig), {}, {
|
|
@@ -2277,7 +2300,7 @@ function formatTransition(stateNode, transitionConfig) {
|
|
|
2277
2300
|
}) : undefined,
|
|
2278
2301
|
target: target,
|
|
2279
2302
|
source: stateNode,
|
|
2280
|
-
|
|
2303
|
+
reenter: reenter,
|
|
2281
2304
|
eventType: transitionConfig.event,
|
|
2282
2305
|
toJSON: function toJSON() {
|
|
2283
2306
|
return _objectSpread2(_objectSpread2({}, transition), {}, {
|
|
@@ -2364,7 +2387,7 @@ function formatInitialTransition(stateNode, _target) {
|
|
|
2364
2387
|
source: stateNode,
|
|
2365
2388
|
actions: [],
|
|
2366
2389
|
eventType: null,
|
|
2367
|
-
|
|
2390
|
+
reenter: false,
|
|
2368
2391
|
target: resolvedTarget,
|
|
2369
2392
|
toJSON: function toJSON() {
|
|
2370
2393
|
return _objectSpread2(_objectSpread2({}, transition), {}, {
|
|
@@ -2397,6 +2420,9 @@ function resolveTarget(stateNode, targets) {
|
|
|
2397
2420
|
if (!isString(target)) {
|
|
2398
2421
|
return target;
|
|
2399
2422
|
}
|
|
2423
|
+
if (isStateId(target)) {
|
|
2424
|
+
return stateNode.machine.getStateNodeById(target);
|
|
2425
|
+
}
|
|
2400
2426
|
var isInternalTarget = target[0] === stateNode.machine.delimiter;
|
|
2401
2427
|
// If internal target is defined on machine,
|
|
2402
2428
|
// do not include machine key on target
|
|
@@ -2412,7 +2438,7 @@ function resolveTarget(stateNode, targets) {
|
|
|
2412
2438
|
throw new Error("Invalid transition definition for state node '".concat(stateNode.id, "':\n").concat(err.message));
|
|
2413
2439
|
}
|
|
2414
2440
|
} else {
|
|
2415
|
-
|
|
2441
|
+
throw new Error("Invalid target: \"".concat(target, "\" is not a valid target from the root node. Did you mean \".").concat(target, "\"?"));
|
|
2416
2442
|
}
|
|
2417
2443
|
});
|
|
2418
2444
|
}
|
|
@@ -2544,24 +2570,24 @@ function getStateNodes(stateNode, state) {
|
|
|
2544
2570
|
return allSubStateNodes.concat(subStateNodes);
|
|
2545
2571
|
}, []));
|
|
2546
2572
|
}
|
|
2547
|
-
function transitionAtomicNode(stateNode, stateValue, state,
|
|
2573
|
+
function transitionAtomicNode(stateNode, stateValue, state, event) {
|
|
2548
2574
|
var childStateNode = getStateNode(stateNode, stateValue);
|
|
2549
|
-
var next = childStateNode.next(state,
|
|
2575
|
+
var next = childStateNode.next(state, event);
|
|
2550
2576
|
if (!next || !next.length) {
|
|
2551
|
-
return stateNode.next(state,
|
|
2577
|
+
return stateNode.next(state, event);
|
|
2552
2578
|
}
|
|
2553
2579
|
return next;
|
|
2554
2580
|
}
|
|
2555
|
-
function transitionCompoundNode(stateNode, stateValue, state,
|
|
2581
|
+
function transitionCompoundNode(stateNode, stateValue, state, event) {
|
|
2556
2582
|
var subStateKeys = Object.keys(stateValue);
|
|
2557
2583
|
var childStateNode = getStateNode(stateNode, subStateKeys[0]);
|
|
2558
|
-
var next = transitionNode(childStateNode, stateValue[subStateKeys[0]], state,
|
|
2584
|
+
var next = transitionNode(childStateNode, stateValue[subStateKeys[0]], state, event);
|
|
2559
2585
|
if (!next || !next.length) {
|
|
2560
|
-
return stateNode.next(state,
|
|
2586
|
+
return stateNode.next(state, event);
|
|
2561
2587
|
}
|
|
2562
2588
|
return next;
|
|
2563
2589
|
}
|
|
2564
|
-
function transitionParallelNode(stateNode, stateValue, state,
|
|
2590
|
+
function transitionParallelNode(stateNode, stateValue, state, event) {
|
|
2565
2591
|
var allInnerTransitions = [];
|
|
2566
2592
|
for (var _i3 = 0, _Object$keys2 = Object.keys(stateValue); _i3 < _Object$keys2.length; _i3++) {
|
|
2567
2593
|
var subStateKey = _Object$keys2[_i3];
|
|
@@ -2570,29 +2596,29 @@ function transitionParallelNode(stateNode, stateValue, state, _event) {
|
|
|
2570
2596
|
continue;
|
|
2571
2597
|
}
|
|
2572
2598
|
var subStateNode = getStateNode(stateNode, subStateKey);
|
|
2573
|
-
var innerTransitions = transitionNode(subStateNode, subStateValue, state,
|
|
2599
|
+
var innerTransitions = transitionNode(subStateNode, subStateValue, state, event);
|
|
2574
2600
|
if (innerTransitions) {
|
|
2575
2601
|
allInnerTransitions.push.apply(allInnerTransitions, _toConsumableArray(innerTransitions));
|
|
2576
2602
|
}
|
|
2577
2603
|
}
|
|
2578
2604
|
if (!allInnerTransitions.length) {
|
|
2579
|
-
return stateNode.next(state,
|
|
2605
|
+
return stateNode.next(state, event);
|
|
2580
2606
|
}
|
|
2581
2607
|
return allInnerTransitions;
|
|
2582
2608
|
}
|
|
2583
|
-
function transitionNode(stateNode, stateValue, state,
|
|
2609
|
+
function transitionNode(stateNode, stateValue, state, event) {
|
|
2584
2610
|
// leaf node
|
|
2585
2611
|
if (isString(stateValue)) {
|
|
2586
|
-
return transitionAtomicNode(stateNode, stateValue, state,
|
|
2612
|
+
return transitionAtomicNode(stateNode, stateValue, state, event);
|
|
2587
2613
|
}
|
|
2588
2614
|
|
|
2589
2615
|
// compound node
|
|
2590
2616
|
if (Object.keys(stateValue).length === 1) {
|
|
2591
|
-
return transitionCompoundNode(stateNode, stateValue, state,
|
|
2617
|
+
return transitionCompoundNode(stateNode, stateValue, state, event);
|
|
2592
2618
|
}
|
|
2593
2619
|
|
|
2594
2620
|
// parallel node
|
|
2595
|
-
return transitionParallelNode(stateNode, stateValue, state,
|
|
2621
|
+
return transitionParallelNode(stateNode, stateValue, state, event);
|
|
2596
2622
|
}
|
|
2597
2623
|
function getHistoryNodes(stateNode) {
|
|
2598
2624
|
return Object.keys(stateNode.states).map(function (key) {
|
|
@@ -2784,7 +2810,7 @@ function getTransitionDomain(transition, historyValue) {
|
|
|
2784
2810
|
if (!targetStates) {
|
|
2785
2811
|
return null;
|
|
2786
2812
|
}
|
|
2787
|
-
if (!transition.
|
|
2813
|
+
if (!transition.reenter && transition.source.type !== 'parallel' && targetStates.every(function (targetStateNode) {
|
|
2788
2814
|
return isDescendant(targetStateNode, transition.source);
|
|
2789
2815
|
})) {
|
|
2790
2816
|
return transition.source;
|
|
@@ -2835,7 +2861,7 @@ function computeExitSet(transitions, configuration, historyValue) {
|
|
|
2835
2861
|
* @param mutConfiguration
|
|
2836
2862
|
*/
|
|
2837
2863
|
|
|
2838
|
-
function microstep(transitions, currentState, actorCtx,
|
|
2864
|
+
function microstep(transitions, currentState, actorCtx, event) {
|
|
2839
2865
|
var machine = currentState.machine;
|
|
2840
2866
|
// Transition will "apply" if:
|
|
2841
2867
|
// - the state node is the initial state (there is no current state)
|
|
@@ -2844,7 +2870,7 @@ function microstep(transitions, currentState, actorCtx, scxmlEvent) {
|
|
|
2844
2870
|
var mutConfiguration = new Set(currentState.configuration);
|
|
2845
2871
|
if (!currentState._initial && !willTransition) {
|
|
2846
2872
|
var inertState = cloneState(currentState, {
|
|
2847
|
-
|
|
2873
|
+
event: event,
|
|
2848
2874
|
actions: [],
|
|
2849
2875
|
transitions: []
|
|
2850
2876
|
});
|
|
@@ -2854,11 +2880,11 @@ function microstep(transitions, currentState, actorCtx, scxmlEvent) {
|
|
|
2854
2880
|
var microstate = microstepProcedure(currentState._initial ? [{
|
|
2855
2881
|
target: _toConsumableArray(currentState.configuration).filter(isAtomicStateNode),
|
|
2856
2882
|
source: machine.root,
|
|
2857
|
-
|
|
2883
|
+
reenter: true,
|
|
2858
2884
|
actions: [],
|
|
2859
2885
|
eventType: null,
|
|
2860
2886
|
toJSON: null // TODO: fix
|
|
2861
|
-
}] : transitions, currentState, mutConfiguration,
|
|
2887
|
+
}] : transitions, currentState, mutConfiguration, event, actorCtx);
|
|
2862
2888
|
var context = microstate.context,
|
|
2863
2889
|
nonRaisedActions = microstate.actions;
|
|
2864
2890
|
var children = setChildren(currentState, nonRaisedActions);
|
|
@@ -2878,12 +2904,12 @@ function setChildren(currentState, nonRaisedActions) {
|
|
|
2878
2904
|
try {
|
|
2879
2905
|
for (_iterator21.s(); !(_step21 = _iterator21.n()).done;) {
|
|
2880
2906
|
var action = _step21.value;
|
|
2881
|
-
if (action.type === invoke && action.params.ref) {
|
|
2907
|
+
if (action.type === invoke$1 && action.params.ref) {
|
|
2882
2908
|
var ref = action.params.ref;
|
|
2883
2909
|
if (ref) {
|
|
2884
2910
|
children[ref.id] = ref;
|
|
2885
2911
|
}
|
|
2886
|
-
} else if (action.type === stop) {
|
|
2912
|
+
} else if (action.type === stop$1) {
|
|
2887
2913
|
var _ref = action.params.actor;
|
|
2888
2914
|
if (_ref) {
|
|
2889
2915
|
delete children[_ref.id];
|
|
@@ -2897,8 +2923,7 @@ function setChildren(currentState, nonRaisedActions) {
|
|
|
2897
2923
|
}
|
|
2898
2924
|
return children;
|
|
2899
2925
|
}
|
|
2900
|
-
function microstepProcedure(transitions, currentState, mutConfiguration,
|
|
2901
|
-
var machine = currentState.machine;
|
|
2926
|
+
function microstepProcedure(transitions, currentState, mutConfiguration, event, actorCtx) {
|
|
2902
2927
|
var actions = [];
|
|
2903
2928
|
var historyValue = _objectSpread2({}, currentState.historyValue);
|
|
2904
2929
|
var filteredTransitions = removeConflictingTransitions(transitions, mutConfiguration, historyValue);
|
|
@@ -2927,9 +2952,9 @@ function microstepProcedure(transitions, currentState, mutConfiguration, scxmlEv
|
|
|
2927
2952
|
actions.push.apply(actions, _toConsumableArray(finalActions));
|
|
2928
2953
|
}
|
|
2929
2954
|
try {
|
|
2930
|
-
var _resolveActionsAndCon = resolveActionsAndContext(actions,
|
|
2955
|
+
var _resolveActionsAndCon = resolveActionsAndContext(actions, event, currentState, actorCtx),
|
|
2931
2956
|
nextState = _resolveActionsAndCon.nextState;
|
|
2932
|
-
var output = done ? getOutput(nextConfiguration, nextState.context,
|
|
2957
|
+
var output = done ? getOutput(nextConfiguration, nextState.context, event) : undefined;
|
|
2933
2958
|
internalQueue.push.apply(internalQueue, _toConsumableArray(nextState._internalQueue));
|
|
2934
2959
|
return cloneState(currentState, {
|
|
2935
2960
|
actions: nextState.actions,
|
|
@@ -2937,7 +2962,7 @@ function microstepProcedure(transitions, currentState, mutConfiguration, scxmlEv
|
|
|
2937
2962
|
historyValue: historyValue,
|
|
2938
2963
|
_internalQueue: internalQueue,
|
|
2939
2964
|
context: nextState.context,
|
|
2940
|
-
|
|
2965
|
+
event: event,
|
|
2941
2966
|
done: done,
|
|
2942
2967
|
output: output,
|
|
2943
2968
|
children: nextState.children
|
|
@@ -2945,19 +2970,7 @@ function microstepProcedure(transitions, currentState, mutConfiguration, scxmlEv
|
|
|
2945
2970
|
} catch (e) {
|
|
2946
2971
|
// TODO: Refactor this once proper error handling is implemented.
|
|
2947
2972
|
// See https://github.com/statelyai/rfcs/pull/4
|
|
2948
|
-
|
|
2949
|
-
return cloneState(currentState, {
|
|
2950
|
-
actions: [],
|
|
2951
|
-
configuration: Array.from(mutConfiguration),
|
|
2952
|
-
historyValue: historyValue,
|
|
2953
|
-
_internalQueue: [toSCXMLEvent({
|
|
2954
|
-
type: 'error.execution'
|
|
2955
|
-
})],
|
|
2956
|
-
context: currentState.context
|
|
2957
|
-
});
|
|
2958
|
-
} else {
|
|
2959
|
-
throw e;
|
|
2960
|
-
}
|
|
2973
|
+
throw e;
|
|
2961
2974
|
}
|
|
2962
2975
|
}
|
|
2963
2976
|
function enterStates(filteredTransitions, mutConfiguration, actions, internalQueue, currentState, historyValue) {
|
|
@@ -2982,7 +2995,7 @@ function enterStates(filteredTransitions, mutConfiguration, actions, internalQue
|
|
|
2982
2995
|
try {
|
|
2983
2996
|
for (_iterator23.s(); !(_step23 = _iterator23.n()).done;) {
|
|
2984
2997
|
var invokeDef = _step23.value;
|
|
2985
|
-
actions.push(invoke
|
|
2998
|
+
actions.push(invoke(invokeDef));
|
|
2986
2999
|
}
|
|
2987
3000
|
|
|
2988
3001
|
// Add entry actions
|
|
@@ -3012,14 +3025,14 @@ function enterStates(filteredTransitions, mutConfiguration, actions, internalQue
|
|
|
3012
3025
|
if (!parent.parent) {
|
|
3013
3026
|
continue;
|
|
3014
3027
|
}
|
|
3015
|
-
internalQueue.push(
|
|
3028
|
+
internalQueue.push(done(parent.id, stateNodeToEnter.output ? mapContext(stateNodeToEnter.output, currentState.context, currentState.event) : undefined));
|
|
3016
3029
|
if (parent.parent) {
|
|
3017
3030
|
var grandparent = parent.parent;
|
|
3018
3031
|
if (grandparent.type === 'parallel') {
|
|
3019
3032
|
if (getChildren(grandparent).every(function (parentNode) {
|
|
3020
3033
|
return isInFinalState(_toConsumableArray(mutConfiguration), parentNode);
|
|
3021
3034
|
})) {
|
|
3022
|
-
internalQueue.push(
|
|
3035
|
+
internalQueue.push(done(grandparent.id));
|
|
3023
3036
|
}
|
|
3024
3037
|
}
|
|
3025
3038
|
}
|
|
@@ -3292,7 +3305,7 @@ function exitStates(transitions, mutConfiguration, historyValue, actions) {
|
|
|
3292
3305
|
for (_iterator40.s(); !(_step40 = _iterator40.n()).done;) {
|
|
3293
3306
|
var s = _step40.value;
|
|
3294
3307
|
actions.push.apply(actions, _toConsumableArray(s.exit.flat()).concat(_toConsumableArray(s.invoke.map(function (def) {
|
|
3295
|
-
return stop
|
|
3308
|
+
return stop(def.id);
|
|
3296
3309
|
}))));
|
|
3297
3310
|
mutConfiguration["delete"](s);
|
|
3298
3311
|
}
|
|
@@ -3302,7 +3315,7 @@ function exitStates(transitions, mutConfiguration, historyValue, actions) {
|
|
|
3302
3315
|
_iterator40.f();
|
|
3303
3316
|
}
|
|
3304
3317
|
}
|
|
3305
|
-
function resolveActionsAndContext(actions,
|
|
3318
|
+
function resolveActionsAndContext(actions, event, currentState, actorCtx) {
|
|
3306
3319
|
var machine = currentState.machine;
|
|
3307
3320
|
var resolvedActions = [];
|
|
3308
3321
|
var raiseActions = [];
|
|
@@ -3320,7 +3333,7 @@ function resolveActionsAndContext(actions, scxmlEvent, currentState, actorCtx) {
|
|
|
3320
3333
|
var executableActionObject = resolveActionObject(actionObject, machine.options.actions);
|
|
3321
3334
|
if (isDynamicAction(executableActionObject)) {
|
|
3322
3335
|
var _resolvedAction$param;
|
|
3323
|
-
var _executableActionObje = executableActionObject.resolve(
|
|
3336
|
+
var _executableActionObje = executableActionObject.resolve(event, {
|
|
3324
3337
|
state: intermediateState,
|
|
3325
3338
|
action: actionObject,
|
|
3326
3339
|
actorContext: actorCtx
|
|
@@ -3330,12 +3343,12 @@ function resolveActionsAndContext(actions, scxmlEvent, currentState, actorCtx) {
|
|
|
3330
3343
|
resolvedAction = _executableActionObje2[1];
|
|
3331
3344
|
var matchedActions = (_resolvedAction$param = resolvedAction.params) === null || _resolvedAction$param === void 0 ? void 0 : _resolvedAction$param.actions;
|
|
3332
3345
|
intermediateState = nextState;
|
|
3333
|
-
if ((resolvedAction.type === raise || resolvedAction.type === send && resolvedAction.params.internal) && typeof resolvedAction.params.delay !== 'number') {
|
|
3346
|
+
if ((resolvedAction.type === raise$1 || resolvedAction.type === send$1 && resolvedAction.params.internal) && typeof resolvedAction.params.delay !== 'number') {
|
|
3334
3347
|
raiseActions.push(resolvedAction);
|
|
3335
3348
|
}
|
|
3336
3349
|
|
|
3337
3350
|
// TODO: remove the check; just handleAction
|
|
3338
|
-
if (resolvedAction.type !== pure) {
|
|
3351
|
+
if (resolvedAction.type !== pure$1) {
|
|
3339
3352
|
handleAction(resolvedAction);
|
|
3340
3353
|
}
|
|
3341
3354
|
toActionObjects(matchedActions).forEach(resolveAction);
|
|
@@ -3359,18 +3372,21 @@ function resolveActionsAndContext(actions, scxmlEvent, currentState, actorCtx) {
|
|
|
3359
3372
|
nextState: cloneState(intermediateState, {
|
|
3360
3373
|
actions: resolvedActions,
|
|
3361
3374
|
_internalQueue: raiseActions.map(function (a) {
|
|
3362
|
-
return a.params.
|
|
3375
|
+
return a.params.event;
|
|
3363
3376
|
})
|
|
3364
3377
|
})
|
|
3365
3378
|
};
|
|
3366
3379
|
}
|
|
3367
|
-
function macrostep(state,
|
|
3380
|
+
function macrostep(state, event, actorCtx) {
|
|
3381
|
+
if (!dev_dist_xstateDev.IS_PRODUCTION && event.type === WILDCARD) {
|
|
3382
|
+
throw new Error("An event cannot have the wildcard type ('".concat(WILDCARD, "')"));
|
|
3383
|
+
}
|
|
3368
3384
|
var nextState = state;
|
|
3369
3385
|
var states = [];
|
|
3370
3386
|
|
|
3371
3387
|
// Handle stop event
|
|
3372
|
-
if (
|
|
3373
|
-
nextState = stopStep(
|
|
3388
|
+
if (event.type === stopSignalType) {
|
|
3389
|
+
nextState = stopStep(event, nextState, actorCtx);
|
|
3374
3390
|
states.push(nextState);
|
|
3375
3391
|
return {
|
|
3376
3392
|
state: nextState,
|
|
@@ -3380,9 +3396,9 @@ function macrostep(state, scxmlEvent, actorCtx) {
|
|
|
3380
3396
|
|
|
3381
3397
|
// Assume the state is at rest (no raised events)
|
|
3382
3398
|
// Determine the next state based on the next microstep
|
|
3383
|
-
if (
|
|
3384
|
-
var transitions = selectTransitions(
|
|
3385
|
-
nextState = microstep(transitions, state, actorCtx,
|
|
3399
|
+
if (event.type !== init) {
|
|
3400
|
+
var transitions = selectTransitions(event, nextState);
|
|
3401
|
+
nextState = microstep(transitions, state, actorCtx, event);
|
|
3386
3402
|
states.push(nextState);
|
|
3387
3403
|
}
|
|
3388
3404
|
while (!nextState.done) {
|
|
@@ -3414,21 +3430,21 @@ function macrostep(state, scxmlEvent, actorCtx) {
|
|
|
3414
3430
|
if (enabledTransitions.length) {
|
|
3415
3431
|
var _nextState$actions2;
|
|
3416
3432
|
var _currentActions = nextState.actions;
|
|
3417
|
-
nextState = microstep(enabledTransitions, nextState, actorCtx, nextState.
|
|
3433
|
+
nextState = microstep(enabledTransitions, nextState, actorCtx, nextState.event);
|
|
3418
3434
|
(_nextState$actions2 = nextState.actions).unshift.apply(_nextState$actions2, _toConsumableArray(_currentActions));
|
|
3419
3435
|
states.push(nextState);
|
|
3420
3436
|
}
|
|
3421
3437
|
}
|
|
3422
3438
|
if (nextState.done) {
|
|
3423
3439
|
// Perform the stop step to ensure that child actors are stopped
|
|
3424
|
-
stopStep(nextState.
|
|
3440
|
+
stopStep(nextState.event, nextState, actorCtx);
|
|
3425
3441
|
}
|
|
3426
3442
|
return {
|
|
3427
3443
|
state: nextState,
|
|
3428
3444
|
microstates: states
|
|
3429
3445
|
};
|
|
3430
3446
|
}
|
|
3431
|
-
function stopStep(
|
|
3447
|
+
function stopStep(event, nextState, actorCtx) {
|
|
3432
3448
|
var actions = [];
|
|
3433
3449
|
var _iterator43 = _createForOfIteratorHelper(nextState.configuration.sort(function (a, b) {
|
|
3434
3450
|
return b.order - a.order;
|
|
@@ -3446,14 +3462,14 @@ function stopStep(scxmlEvent, nextState, actorCtx) {
|
|
|
3446
3462
|
}
|
|
3447
3463
|
for (var _i4 = 0, _Object$values = Object.values(nextState.children); _i4 < _Object$values.length; _i4++) {
|
|
3448
3464
|
var child = _Object$values[_i4];
|
|
3449
|
-
actions.push(stop
|
|
3465
|
+
actions.push(stop(child));
|
|
3450
3466
|
}
|
|
3451
|
-
var _resolveActionsAndCon2 = resolveActionsAndContext(actions,
|
|
3467
|
+
var _resolveActionsAndCon2 = resolveActionsAndContext(actions, event, nextState, actorCtx),
|
|
3452
3468
|
stoppedState = _resolveActionsAndCon2.nextState;
|
|
3453
3469
|
return stoppedState;
|
|
3454
3470
|
}
|
|
3455
|
-
function selectTransitions(
|
|
3456
|
-
return nextState.machine.getTransitionData(nextState,
|
|
3471
|
+
function selectTransitions(event, nextState) {
|
|
3472
|
+
return nextState.machine.getTransitionData(nextState, event);
|
|
3457
3473
|
}
|
|
3458
3474
|
function selectEventlessTransitions(nextState) {
|
|
3459
3475
|
var enabledTransitionSet = new Set();
|
|
@@ -3476,7 +3492,7 @@ function selectEventlessTransitions(nextState) {
|
|
|
3476
3492
|
try {
|
|
3477
3493
|
for (_iterator46.s(); !(_step46 = _iterator46.n()).done;) {
|
|
3478
3494
|
var transition = _step46.value;
|
|
3479
|
-
if (transition.guard === undefined || evaluateGuard(transition.guard, nextState.context, nextState.
|
|
3495
|
+
if (transition.guard === undefined || evaluateGuard(transition.guard, nextState.context, nextState.event, nextState)) {
|
|
3480
3496
|
enabledTransitionSet.add(transition);
|
|
3481
3497
|
break loop;
|
|
3482
3498
|
}
|
|
@@ -3570,16 +3586,14 @@ var State = /*#__PURE__*/function () {
|
|
|
3570
3586
|
_defineProperty(this, "actions", []);
|
|
3571
3587
|
_defineProperty(this, "event", void 0);
|
|
3572
3588
|
_defineProperty(this, "_internalQueue", void 0);
|
|
3573
|
-
_defineProperty(this, "_event", void 0);
|
|
3574
3589
|
_defineProperty(this, "_initial", false);
|
|
3575
3590
|
_defineProperty(this, "changed", void 0);
|
|
3576
3591
|
_defineProperty(this, "configuration", void 0);
|
|
3577
3592
|
_defineProperty(this, "transitions", void 0);
|
|
3578
3593
|
_defineProperty(this, "children", void 0);
|
|
3579
3594
|
this.context = config.context;
|
|
3580
|
-
this._event = config._event;
|
|
3581
3595
|
this._internalQueue = (_config$_internalQueu = config._internalQueue) !== null && _config$_internalQueu !== void 0 ? _config$_internalQueu : [];
|
|
3582
|
-
this.event =
|
|
3596
|
+
this.event = config.event;
|
|
3583
3597
|
this.historyValue = config.historyValue || {};
|
|
3584
3598
|
this.actions = (_config$actions = config.actions) !== null && _config$actions !== void 0 ? _config$actions : [];
|
|
3585
3599
|
this.matches = this.matches.bind(this);
|
|
@@ -3619,11 +3633,11 @@ var State = /*#__PURE__*/function () {
|
|
|
3619
3633
|
}, {
|
|
3620
3634
|
key: "toJSON",
|
|
3621
3635
|
value: function toJSON() {
|
|
3622
|
-
|
|
3623
|
-
|
|
3624
|
-
tags = this.tags
|
|
3625
|
-
|
|
3626
|
-
jsonValues = _objectWithoutProperties(this, _excluded);
|
|
3636
|
+
this.configuration;
|
|
3637
|
+
this.transitions;
|
|
3638
|
+
var tags = this.tags;
|
|
3639
|
+
this.machine;
|
|
3640
|
+
var jsonValues = _objectWithoutProperties(this, _excluded);
|
|
3627
3641
|
return _objectSpread2(_objectSpread2({}, jsonValues), {}, {
|
|
3628
3642
|
tags: Array.from(tags),
|
|
3629
3643
|
meta: this.meta
|
|
@@ -3661,10 +3675,10 @@ var State = /*#__PURE__*/function () {
|
|
|
3661
3675
|
}, {
|
|
3662
3676
|
key: "can",
|
|
3663
3677
|
value: function can(event) {
|
|
3664
|
-
{
|
|
3665
|
-
warn(!!this.machine);
|
|
3678
|
+
if (dev_dist_xstateDev.IS_PRODUCTION) {
|
|
3679
|
+
warn(!!this.machine, "state.can(...) used outside of a machine-created State object; this will always return false.");
|
|
3666
3680
|
}
|
|
3667
|
-
var transitionData = this.machine.getTransitionData(this,
|
|
3681
|
+
var transitionData = this.machine.getTransitionData(this, event);
|
|
3668
3682
|
return !!(transitionData !== null && transitionData !== void 0 && transitionData.length) &&
|
|
3669
3683
|
// Check that at least one transition is not forbidden
|
|
3670
3684
|
transitionData.some(function (t) {
|
|
@@ -3741,7 +3755,7 @@ var State = /*#__PURE__*/function () {
|
|
|
3741
3755
|
return new State({
|
|
3742
3756
|
value: stateValue.value,
|
|
3743
3757
|
context: context,
|
|
3744
|
-
|
|
3758
|
+
event: stateValue.event,
|
|
3745
3759
|
actions: [],
|
|
3746
3760
|
meta: {},
|
|
3747
3761
|
configuration: [],
|
|
@@ -3752,13 +3766,13 @@ var State = /*#__PURE__*/function () {
|
|
|
3752
3766
|
}
|
|
3753
3767
|
return stateValue;
|
|
3754
3768
|
}
|
|
3755
|
-
var
|
|
3769
|
+
var event = createInitEvent({}); // TODO: fix
|
|
3756
3770
|
|
|
3757
3771
|
var configuration = getConfiguration(getStateNodes(machine.root, stateValue));
|
|
3758
3772
|
return new State({
|
|
3759
3773
|
value: stateValue,
|
|
3760
3774
|
context: context,
|
|
3761
|
-
|
|
3775
|
+
event: event,
|
|
3762
3776
|
actions: [],
|
|
3763
3777
|
meta: undefined,
|
|
3764
3778
|
configuration: Array.from(configuration),
|
|
@@ -3774,11 +3788,11 @@ function cloneState(state) {
|
|
|
3774
3788
|
return new State(_objectSpread2(_objectSpread2({}, state), config), state.machine);
|
|
3775
3789
|
}
|
|
3776
3790
|
function getPersistedState(state) {
|
|
3777
|
-
|
|
3778
|
-
|
|
3779
|
-
|
|
3780
|
-
|
|
3781
|
-
children = state.children,
|
|
3791
|
+
state.configuration;
|
|
3792
|
+
state.transitions;
|
|
3793
|
+
state.tags;
|
|
3794
|
+
state.machine;
|
|
3795
|
+
var children = state.children,
|
|
3782
3796
|
jsonValues = _objectWithoutProperties(state, _excluded2);
|
|
3783
3797
|
var childrenJson = {};
|
|
3784
3798
|
for (var id in children) {
|
|
@@ -3793,14 +3807,14 @@ function getPersistedState(state) {
|
|
|
3793
3807
|
});
|
|
3794
3808
|
}
|
|
3795
3809
|
|
|
3796
|
-
function invoke
|
|
3810
|
+
function invoke(invokeDef) {
|
|
3797
3811
|
return createDynamicAction({
|
|
3798
|
-
type: invoke,
|
|
3812
|
+
type: invoke$1,
|
|
3799
3813
|
params: invokeDef
|
|
3800
|
-
}, function (
|
|
3814
|
+
}, function (event, _ref) {
|
|
3801
3815
|
var state = _ref.state,
|
|
3802
3816
|
actorContext = _ref.actorContext;
|
|
3803
|
-
var type = invoke;
|
|
3817
|
+
var type = invoke$1;
|
|
3804
3818
|
var id = invokeDef.id,
|
|
3805
3819
|
src = invokeDef.src;
|
|
3806
3820
|
var resolvedInvokeAction;
|
|
@@ -3827,7 +3841,7 @@ function invoke$1(invokeDef) {
|
|
|
3827
3841
|
systemId: invokeDef.systemId,
|
|
3828
3842
|
input: typeof input === 'function' ? input({
|
|
3829
3843
|
context: state.context,
|
|
3830
|
-
event:
|
|
3844
|
+
event: event,
|
|
3831
3845
|
self: actorContext === null || actorContext === void 0 ? void 0 : actorContext.self
|
|
3832
3846
|
}) : input
|
|
3833
3847
|
});
|
|
@@ -3859,7 +3873,7 @@ function invoke$1(invokeDef) {
|
|
|
3859
3873
|
var _actorRef$start;
|
|
3860
3874
|
(_actorRef$start = actorRef.start) === null || _actorRef$start === void 0 ? void 0 : _actorRef$start.call(actorRef);
|
|
3861
3875
|
} catch (err) {
|
|
3862
|
-
parent.send(error
|
|
3876
|
+
parent.send(error(id, err));
|
|
3863
3877
|
return;
|
|
3864
3878
|
}
|
|
3865
3879
|
});
|
|
@@ -3868,7 +3882,7 @@ function invoke$1(invokeDef) {
|
|
|
3868
3882
|
});
|
|
3869
3883
|
}
|
|
3870
3884
|
|
|
3871
|
-
function createSpawner(self, machine, context,
|
|
3885
|
+
function createSpawner(self, machine, context, event, mutCapturedActions) {
|
|
3872
3886
|
return function (src) {
|
|
3873
3887
|
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
3874
3888
|
if (isString(src)) {
|
|
@@ -3884,11 +3898,11 @@ function createSpawner(self, machine, context, _event, mutCapturedActions) {
|
|
|
3884
3898
|
parent: self,
|
|
3885
3899
|
input: typeof input === 'function' ? input({
|
|
3886
3900
|
context: context,
|
|
3887
|
-
event:
|
|
3901
|
+
event: event,
|
|
3888
3902
|
self: self
|
|
3889
3903
|
}) : input
|
|
3890
3904
|
});
|
|
3891
|
-
mutCapturedActions.push(invoke
|
|
3905
|
+
mutCapturedActions.push(invoke({
|
|
3892
3906
|
id: actorRef.id,
|
|
3893
3907
|
// @ts-ignore TODO: fix types
|
|
3894
3908
|
src: actorRef,
|
|
@@ -3909,7 +3923,7 @@ function createSpawner(self, machine, context, _event, mutCapturedActions) {
|
|
|
3909
3923
|
parent: self,
|
|
3910
3924
|
input: options.input
|
|
3911
3925
|
});
|
|
3912
|
-
mutCapturedActions.push(invoke
|
|
3926
|
+
mutCapturedActions.push(invoke({
|
|
3913
3927
|
// @ts-ignore TODO: fix types
|
|
3914
3928
|
src: _actorRef,
|
|
3915
3929
|
ref: _actorRef,
|
|
@@ -3927,13 +3941,13 @@ function createSpawner(self, machine, context, _event, mutCapturedActions) {
|
|
|
3927
3941
|
*
|
|
3928
3942
|
* @param assignment An object that represents the partial context to update.
|
|
3929
3943
|
*/
|
|
3930
|
-
function assign
|
|
3944
|
+
function assign(assignment) {
|
|
3931
3945
|
return createDynamicAction({
|
|
3932
|
-
type: assign,
|
|
3946
|
+
type: assign$1,
|
|
3933
3947
|
params: {
|
|
3934
3948
|
assignment: assignment
|
|
3935
3949
|
}
|
|
3936
|
-
}, function (
|
|
3950
|
+
}, function (event, _ref) {
|
|
3937
3951
|
var _actorContext$self;
|
|
3938
3952
|
var state = _ref.state,
|
|
3939
3953
|
action = _ref.action,
|
|
@@ -3944,10 +3958,9 @@ function assign$1(assignment) {
|
|
|
3944
3958
|
}
|
|
3945
3959
|
var args = {
|
|
3946
3960
|
context: state.context,
|
|
3947
|
-
event:
|
|
3961
|
+
event: event,
|
|
3948
3962
|
action: action,
|
|
3949
|
-
|
|
3950
|
-
spawn: createSpawner(actorContext === null || actorContext === void 0 ? void 0 : actorContext.self, state.machine, state.context, _event, capturedActions),
|
|
3963
|
+
spawn: createSpawner(actorContext === null || actorContext === void 0 ? void 0 : actorContext.self, state.machine, state.context, event, capturedActions),
|
|
3951
3964
|
self: (_actorContext$self = actorContext === null || actorContext === void 0 ? void 0 : actorContext.self) !== null && _actorContext$self !== void 0 ? _actorContext$self : {},
|
|
3952
3965
|
system: actorContext === null || actorContext === void 0 ? void 0 : actorContext.system
|
|
3953
3966
|
};
|
|
@@ -3965,7 +3978,7 @@ function assign$1(assignment) {
|
|
|
3965
3978
|
return [cloneState(state, {
|
|
3966
3979
|
context: updatedContext
|
|
3967
3980
|
}), {
|
|
3968
|
-
type: assign,
|
|
3981
|
+
type: assign$1,
|
|
3969
3982
|
params: {
|
|
3970
3983
|
context: updatedContext,
|
|
3971
3984
|
actions: capturedActions
|
|
@@ -3981,15 +3994,15 @@ function assign$1(assignment) {
|
|
|
3981
3994
|
* @param eventType The event to raise.
|
|
3982
3995
|
*/
|
|
3983
3996
|
|
|
3984
|
-
function raise
|
|
3997
|
+
function raise(eventOrExpr, options) {
|
|
3985
3998
|
return createDynamicAction({
|
|
3986
|
-
type: raise,
|
|
3999
|
+
type: raise$1,
|
|
3987
4000
|
params: {
|
|
3988
4001
|
delay: options ? options.delay : undefined,
|
|
3989
4002
|
event: eventOrExpr,
|
|
3990
4003
|
id: options && options.id !== undefined ? options.id : typeof eventOrExpr === 'function' ? eventOrExpr.name : eventOrExpr.type
|
|
3991
4004
|
}
|
|
3992
|
-
}, function (
|
|
4005
|
+
}, function (event, _ref) {
|
|
3993
4006
|
var _actorContext$self;
|
|
3994
4007
|
var state = _ref.state,
|
|
3995
4008
|
actorContext = _ref.actorContext;
|
|
@@ -4000,15 +4013,17 @@ function raise$1(eventOrExpr, options) {
|
|
|
4000
4013
|
};
|
|
4001
4014
|
var args = {
|
|
4002
4015
|
context: state.context,
|
|
4003
|
-
event:
|
|
4004
|
-
_event: _event,
|
|
4016
|
+
event: event,
|
|
4005
4017
|
self: (_actorContext$self = actorContext === null || actorContext === void 0 ? void 0 : actorContext.self) !== null && _actorContext$self !== void 0 ? _actorContext$self : {},
|
|
4006
4018
|
system: actorContext === null || actorContext === void 0 ? void 0 : actorContext.system
|
|
4007
4019
|
};
|
|
4008
4020
|
var delaysMap = state.machine.options.delays;
|
|
4009
4021
|
|
|
4010
4022
|
// TODO: helper function for resolving Expr
|
|
4011
|
-
|
|
4023
|
+
if (typeof eventOrExpr === 'string') {
|
|
4024
|
+
throw new Error("Only event objects may be used with raise; use raise({ type: \"".concat(eventOrExpr, "\" }) instead"));
|
|
4025
|
+
}
|
|
4026
|
+
var resolvedEvent = typeof eventOrExpr === 'function' ? eventOrExpr(args) : eventOrExpr;
|
|
4012
4027
|
var resolvedDelay;
|
|
4013
4028
|
if (typeof params.delay === 'string') {
|
|
4014
4029
|
var configDelay = delaysMap && delaysMap[params.delay];
|
|
@@ -4017,10 +4032,9 @@ function raise$1(eventOrExpr, options) {
|
|
|
4017
4032
|
resolvedDelay = typeof params.delay === 'function' ? params.delay(args) : params.delay;
|
|
4018
4033
|
}
|
|
4019
4034
|
var resolvedAction = {
|
|
4020
|
-
type: raise,
|
|
4035
|
+
type: raise$1,
|
|
4021
4036
|
params: _objectSpread2(_objectSpread2({}, params), {}, {
|
|
4022
|
-
|
|
4023
|
-
event: resolvedEvent.data,
|
|
4037
|
+
event: resolvedEvent,
|
|
4024
4038
|
delay: resolvedDelay
|
|
4025
4039
|
}),
|
|
4026
4040
|
execute: function execute(actorCtx) {
|
|
@@ -4034,23 +4048,23 @@ function raise$1(eventOrExpr, options) {
|
|
|
4034
4048
|
});
|
|
4035
4049
|
}
|
|
4036
4050
|
|
|
4037
|
-
function choose
|
|
4051
|
+
function choose(guards) {
|
|
4038
4052
|
return createDynamicAction({
|
|
4039
|
-
type: choose,
|
|
4053
|
+
type: choose$1,
|
|
4040
4054
|
params: {
|
|
4041
4055
|
guards: guards
|
|
4042
4056
|
}
|
|
4043
|
-
}, function (
|
|
4057
|
+
}, function (event, _ref) {
|
|
4044
4058
|
var _guards$find;
|
|
4045
4059
|
var state = _ref.state;
|
|
4046
4060
|
var matchedActions = (_guards$find = guards.find(function (condition) {
|
|
4047
4061
|
var guard = condition.guard && toGuardDefinition(condition.guard, function (guardType) {
|
|
4048
4062
|
return state.machine.options.guards[guardType];
|
|
4049
4063
|
});
|
|
4050
|
-
return !guard || evaluateGuard(guard, state.context,
|
|
4064
|
+
return !guard || evaluateGuard(guard, state.context, event, state);
|
|
4051
4065
|
})) === null || _guards$find === void 0 ? void 0 : _guards$find.actions;
|
|
4052
4066
|
return [state, {
|
|
4053
|
-
type: choose,
|
|
4067
|
+
type: choose$1,
|
|
4054
4068
|
params: {
|
|
4055
4069
|
actions: toActionObjects(matchedActions)
|
|
4056
4070
|
}
|
|
@@ -4058,9 +4072,30 @@ function choose$1(guards) {
|
|
|
4058
4072
|
});
|
|
4059
4073
|
}
|
|
4060
4074
|
|
|
4061
|
-
|
|
4075
|
+
function pure(getActions) {
|
|
4076
|
+
return createDynamicAction({
|
|
4077
|
+
type: pure$1,
|
|
4078
|
+
params: {
|
|
4079
|
+
get: getActions
|
|
4080
|
+
}
|
|
4081
|
+
}, function (event, _ref) {
|
|
4082
|
+
var _toArray;
|
|
4083
|
+
var state = _ref.state;
|
|
4084
|
+
return [state, {
|
|
4085
|
+
type: pure$1,
|
|
4086
|
+
params: {
|
|
4087
|
+
actions: (_toArray = toArray(toActionObjects(getActions({
|
|
4088
|
+
context: state.context,
|
|
4089
|
+
event: event
|
|
4090
|
+
})))) !== null && _toArray !== void 0 ? _toArray : []
|
|
4091
|
+
}
|
|
4092
|
+
}];
|
|
4093
|
+
});
|
|
4094
|
+
}
|
|
4095
|
+
|
|
4096
|
+
var initEvent = {
|
|
4062
4097
|
type: init
|
|
4063
|
-
}
|
|
4098
|
+
};
|
|
4064
4099
|
function resolveActionObject(actionObject, actionFunctionMap) {
|
|
4065
4100
|
if (isDynamicAction(actionObject)) {
|
|
4066
4101
|
return actionObject;
|
|
@@ -4071,7 +4106,7 @@ function resolveActionObject(actionObject, actionFunctionMap) {
|
|
|
4071
4106
|
return createDynamicAction({
|
|
4072
4107
|
type: 'xstate.function',
|
|
4073
4108
|
params: (_actionObject$params = actionObject.params) !== null && _actionObject$params !== void 0 ? _actionObject$params : {}
|
|
4074
|
-
}, function (
|
|
4109
|
+
}, function (event, _ref) {
|
|
4075
4110
|
var state = _ref.state;
|
|
4076
4111
|
var a = {
|
|
4077
4112
|
type: actionObject.type,
|
|
@@ -4079,9 +4114,8 @@ function resolveActionObject(actionObject, actionFunctionMap) {
|
|
|
4079
4114
|
execute: function execute(actorCtx) {
|
|
4080
4115
|
return dereferencedAction({
|
|
4081
4116
|
context: state.context,
|
|
4082
|
-
event:
|
|
4117
|
+
event: event,
|
|
4083
4118
|
action: a,
|
|
4084
|
-
_event: state._event,
|
|
4085
4119
|
system: actorCtx.system,
|
|
4086
4120
|
self: actorCtx.self
|
|
4087
4121
|
});
|
|
@@ -4110,7 +4144,7 @@ function toActionObject(action) {
|
|
|
4110
4144
|
return createDynamicAction({
|
|
4111
4145
|
type: type,
|
|
4112
4146
|
params: {}
|
|
4113
|
-
}, function (
|
|
4147
|
+
}, function (event, _ref2) {
|
|
4114
4148
|
var state = _ref2.state;
|
|
4115
4149
|
var actionObject = {
|
|
4116
4150
|
type: type,
|
|
@@ -4120,9 +4154,8 @@ function toActionObject(action) {
|
|
|
4120
4154
|
execute: function execute(actorCtx) {
|
|
4121
4155
|
return action({
|
|
4122
4156
|
context: state.context,
|
|
4123
|
-
event:
|
|
4157
|
+
event: event,
|
|
4124
4158
|
action: actionObject,
|
|
4125
|
-
_event: _event,
|
|
4126
4159
|
self: actorCtx.self,
|
|
4127
4160
|
system: actorCtx.system
|
|
4128
4161
|
});
|
|
@@ -4150,7 +4183,7 @@ var toActionObjects = function toActionObjects(action) {
|
|
|
4150
4183
|
* @param delayRef The delay in milliseconds
|
|
4151
4184
|
* @param id The state node ID where this event is handled
|
|
4152
4185
|
*/
|
|
4153
|
-
function after
|
|
4186
|
+
function after(delayRef, id) {
|
|
4154
4187
|
var idSuffix = id ? "#".concat(id) : '';
|
|
4155
4188
|
return "".concat(exports.ActionTypes.After, "(").concat(delayRef, ")").concat(idSuffix);
|
|
4156
4189
|
}
|
|
@@ -4160,13 +4193,13 @@ function after$1(delayRef, id) {
|
|
|
4160
4193
|
* has been reached in the parent state node.
|
|
4161
4194
|
*
|
|
4162
4195
|
* @param id The final state node's parent state node `id`
|
|
4163
|
-
* @param
|
|
4196
|
+
* @param output The data to pass into the event
|
|
4164
4197
|
*/
|
|
4165
|
-
function done(id,
|
|
4198
|
+
function done(id, output) {
|
|
4166
4199
|
var type = "".concat(exports.ActionTypes.DoneState, ".").concat(id);
|
|
4167
4200
|
var eventObject = {
|
|
4168
4201
|
type: type,
|
|
4169
|
-
|
|
4202
|
+
output: output
|
|
4170
4203
|
};
|
|
4171
4204
|
eventObject.toString = function () {
|
|
4172
4205
|
return type;
|
|
@@ -4181,20 +4214,20 @@ function done(id, data) {
|
|
|
4181
4214
|
* but not when it is canceled.
|
|
4182
4215
|
*
|
|
4183
4216
|
* @param invokeId The invoked service ID
|
|
4184
|
-
* @param
|
|
4217
|
+
* @param output The data to pass into the event
|
|
4185
4218
|
*/
|
|
4186
|
-
function doneInvoke(invokeId,
|
|
4219
|
+
function doneInvoke(invokeId, output) {
|
|
4187
4220
|
var type = "".concat(exports.ActionTypes.DoneInvoke, ".").concat(invokeId);
|
|
4188
4221
|
var eventObject = {
|
|
4189
4222
|
type: type,
|
|
4190
|
-
|
|
4223
|
+
output: output
|
|
4191
4224
|
};
|
|
4192
4225
|
eventObject.toString = function () {
|
|
4193
4226
|
return type;
|
|
4194
4227
|
};
|
|
4195
4228
|
return eventObject;
|
|
4196
4229
|
}
|
|
4197
|
-
function error
|
|
4230
|
+
function error(id, data) {
|
|
4198
4231
|
var type = "".concat(exports.ActionTypes.ErrorPlatform, ".").concat(id);
|
|
4199
4232
|
var eventObject = {
|
|
4200
4233
|
type: type,
|
|
@@ -4206,10 +4239,10 @@ function error$1(id, data) {
|
|
|
4206
4239
|
return eventObject;
|
|
4207
4240
|
}
|
|
4208
4241
|
function createInitEvent(input) {
|
|
4209
|
-
return
|
|
4242
|
+
return {
|
|
4210
4243
|
type: init,
|
|
4211
4244
|
input: input
|
|
4212
|
-
}
|
|
4245
|
+
};
|
|
4213
4246
|
}
|
|
4214
4247
|
|
|
4215
4248
|
exports.Interpreter = Interpreter;
|
|
@@ -4225,18 +4258,18 @@ exports._objectWithoutProperties = _objectWithoutProperties;
|
|
|
4225
4258
|
exports._slicedToArray = _slicedToArray;
|
|
4226
4259
|
exports._toConsumableArray = _toConsumableArray;
|
|
4227
4260
|
exports.actionTypes = actionTypes;
|
|
4228
|
-
exports.after = after
|
|
4261
|
+
exports.after = after;
|
|
4229
4262
|
exports.and = and;
|
|
4230
|
-
exports.assign = assign
|
|
4231
|
-
exports.cancel = cancel
|
|
4232
|
-
exports.choose = choose
|
|
4233
|
-
exports.
|
|
4263
|
+
exports.assign = assign;
|
|
4264
|
+
exports.cancel = cancel;
|
|
4265
|
+
exports.choose = choose;
|
|
4266
|
+
exports.createEmptyActor = createEmptyActor;
|
|
4234
4267
|
exports.createInitEvent = createInitEvent;
|
|
4235
4268
|
exports.createInvokeId = createInvokeId;
|
|
4236
4269
|
exports.createSpawner = createSpawner;
|
|
4237
4270
|
exports.done = done;
|
|
4238
4271
|
exports.doneInvoke = doneInvoke;
|
|
4239
|
-
exports.error = error
|
|
4272
|
+
exports.error = error;
|
|
4240
4273
|
exports.escalate = escalate;
|
|
4241
4274
|
exports.evaluateGuard = evaluateGuard;
|
|
4242
4275
|
exports.flatten = flatten;
|
|
@@ -4254,17 +4287,18 @@ exports.getConfiguration = getConfiguration;
|
|
|
4254
4287
|
exports.getDelayedTransitions = getDelayedTransitions;
|
|
4255
4288
|
exports.getInitialConfiguration = getInitialConfiguration;
|
|
4256
4289
|
exports.getPersistedState = getPersistedState;
|
|
4290
|
+
exports.getStateNodeByPath = getStateNodeByPath;
|
|
4257
4291
|
exports.getStateNodes = getStateNodes;
|
|
4258
4292
|
exports.initEvent = initEvent;
|
|
4259
4293
|
exports.interpret = interpret;
|
|
4260
|
-
exports.invoke = invoke;
|
|
4294
|
+
exports.invoke = invoke$1;
|
|
4261
4295
|
exports.isActorRef = isActorRef;
|
|
4296
|
+
exports.isErrorEvent = isErrorEvent;
|
|
4262
4297
|
exports.isInFinalState = isInFinalState;
|
|
4263
|
-
exports.isSCXMLErrorEvent = isSCXMLErrorEvent;
|
|
4264
4298
|
exports.isSignal = isSignal;
|
|
4265
4299
|
exports.isStateId = isStateId;
|
|
4266
4300
|
exports.isString = isString;
|
|
4267
|
-
exports.log = log
|
|
4301
|
+
exports.log = log;
|
|
4268
4302
|
exports.macrostep = macrostep;
|
|
4269
4303
|
exports.mapValues = mapValues;
|
|
4270
4304
|
exports.matchesState = matchesState;
|
|
@@ -4274,19 +4308,18 @@ exports.not = not;
|
|
|
4274
4308
|
exports.or = or;
|
|
4275
4309
|
exports.pathToStateValue = pathToStateValue;
|
|
4276
4310
|
exports.pure = pure;
|
|
4277
|
-
exports.raise = raise
|
|
4311
|
+
exports.raise = raise;
|
|
4278
4312
|
exports.resolveActionObject = resolveActionObject;
|
|
4279
4313
|
exports.resolveActionsAndContext = resolveActionsAndContext;
|
|
4280
4314
|
exports.resolveReferencedActor = resolveReferencedActor;
|
|
4281
4315
|
exports.resolveStateValue = resolveStateValue;
|
|
4282
|
-
exports.
|
|
4283
|
-
exports.send = send$1;
|
|
4316
|
+
exports.send = send;
|
|
4284
4317
|
exports.sendParent = sendParent;
|
|
4285
4318
|
exports.sendTo = sendTo;
|
|
4286
4319
|
exports.startSignal = startSignal;
|
|
4287
4320
|
exports.startSignalType = startSignalType;
|
|
4288
4321
|
exports.stateIn = stateIn;
|
|
4289
|
-
exports.stop = stop
|
|
4322
|
+
exports.stop = stop;
|
|
4290
4323
|
exports.stopSignal = stopSignal;
|
|
4291
4324
|
exports.stopSignalType = stopSignalType;
|
|
4292
4325
|
exports.toActionObject = toActionObject;
|
|
@@ -4296,6 +4329,5 @@ exports.toArray = toArray;
|
|
|
4296
4329
|
exports.toGuardDefinition = toGuardDefinition;
|
|
4297
4330
|
exports.toInvokeConfig = toInvokeConfig;
|
|
4298
4331
|
exports.toObserver = toObserver;
|
|
4299
|
-
exports.toSCXMLEvent = toSCXMLEvent;
|
|
4300
4332
|
exports.toTransitionConfigArray = toTransitionConfigArray;
|
|
4301
4333
|
exports.transitionNode = transitionNode;
|