xstate 4.33.0 → 4.33.3
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/dist/xstate.interpreter.js +1 -1
- package/dist/xstate.js +1 -1
- package/dist/xstate.web.js +2 -2
- package/es/StateNode.js +62 -45
- package/es/actions.d.ts +1 -1
- package/es/actions.js +84 -18
- package/es/interpreter.d.ts +2 -0
- package/es/interpreter.js +44 -19
- package/lib/StateNode.js +61 -44
- package/lib/actions.d.ts +1 -1
- package/lib/actions.js +82 -16
- package/lib/interpreter.d.ts +2 -0
- package/lib/interpreter.js +43 -18
- package/package.json +1 -1
package/es/interpreter.d.ts
CHANGED
|
@@ -73,6 +73,7 @@ export declare class Interpreter<TContext, TStateSchema extends StateSchema = an
|
|
|
73
73
|
sessionId: string;
|
|
74
74
|
children: Map<string | number, ActorRef<any>>;
|
|
75
75
|
private forwardTo;
|
|
76
|
+
private _outgoingQueue;
|
|
76
77
|
private devTools?;
|
|
77
78
|
/**
|
|
78
79
|
* Creates a new Interpreter instance (i.e., service) for the given machine with the provided options, if any.
|
|
@@ -134,6 +135,7 @@ export declare class Interpreter<TContext, TStateSchema extends StateSchema = an
|
|
|
134
135
|
* @param initialState The state to start the statechart from
|
|
135
136
|
*/
|
|
136
137
|
start(initialState?: State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta> | StateConfig<TContext, TEvent> | StateValue): this;
|
|
138
|
+
private _stopChildren;
|
|
137
139
|
private _stop;
|
|
138
140
|
/**
|
|
139
141
|
* Stops the interpreter and unsubscribe all listeners.
|
package/es/interpreter.js
CHANGED
|
@@ -4,7 +4,7 @@ import { isStateConfig, State, bindActionToState } from './State.js';
|
|
|
4
4
|
import { raise, send, errorPlatform, update, error as error$1, log, stop, start, cancel } from './actionTypes.js';
|
|
5
5
|
import { initEvent, doneInvoke, toActionObjects, resolveActions, error, getActionFunction } from './actions.js';
|
|
6
6
|
import { IS_PRODUCTION } from './environment.js';
|
|
7
|
-
import { warn, mapContext, toObserver, toSCXMLEvent, flatten,
|
|
7
|
+
import { warn, mapContext, toObserver, isFunction, toSCXMLEvent, flatten, isPromiseLike, isObservable, isMachine, isBehavior, reportUnhandledExceptionOnInvocation, symbolObservable, isArray, toEventObject, isString, isActor, toInvokeSource, uniqueId } from './utils.js';
|
|
8
8
|
import { Scheduler } from './scheduler.js';
|
|
9
9
|
import { createDeferredActor, isSpawnedActor } from './Actor.js';
|
|
10
10
|
import { registry } from './registry.js';
|
|
@@ -58,6 +58,7 @@ function () {
|
|
|
58
58
|
this.status = InterpreterStatus.NotStarted;
|
|
59
59
|
this.children = new Map();
|
|
60
60
|
this.forwardTo = new Set();
|
|
61
|
+
this._outgoingQueue = [];
|
|
61
62
|
/**
|
|
62
63
|
* Alias for Interpreter.prototype.start
|
|
63
64
|
*/
|
|
@@ -100,7 +101,7 @@ function () {
|
|
|
100
101
|
// Forward copy of event to child actors
|
|
101
102
|
_this.forward(_event);
|
|
102
103
|
|
|
103
|
-
var nextState = _this.
|
|
104
|
+
var nextState = _this._nextState(_event);
|
|
104
105
|
|
|
105
106
|
_this.update(nextState, _event);
|
|
106
107
|
});
|
|
@@ -132,14 +133,24 @@ function () {
|
|
|
132
133
|
if (_this.status !== InterpreterStatus.Stopped || _this.parent !== target || // we need to send events to the parent from exit handlers of a machine that reached its final state
|
|
133
134
|
_this.state.done) {
|
|
134
135
|
// Send SCXML events to machines
|
|
135
|
-
|
|
136
|
+
var scxmlEvent = __assign(__assign({}, event), {
|
|
136
137
|
name: event.name === error$1 ? "".concat(error(_this.id)) : event.name,
|
|
137
138
|
origin: _this.sessionId
|
|
138
|
-
})
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
if (_this.machine.config.predictableActionArguments) {
|
|
142
|
+
_this._outgoingQueue.push([target, scxmlEvent]);
|
|
143
|
+
} else {
|
|
144
|
+
target.send(scxmlEvent);
|
|
145
|
+
}
|
|
139
146
|
}
|
|
140
147
|
} else {
|
|
141
148
|
// Send normal events to other targets
|
|
142
|
-
|
|
149
|
+
if (_this.machine.config.predictableActionArguments) {
|
|
150
|
+
_this._outgoingQueue.push([target, event.data]);
|
|
151
|
+
} else {
|
|
152
|
+
target.send(event.data);
|
|
153
|
+
}
|
|
143
154
|
}
|
|
144
155
|
};
|
|
145
156
|
|
|
@@ -384,6 +395,12 @@ function () {
|
|
|
384
395
|
// we can't just recompute it (and execute actions while doing so) because we try to preserve identity of actors created within initial assigns
|
|
385
396
|
_event === initEvent) && this.options.execute) {
|
|
386
397
|
this.execute(this.state);
|
|
398
|
+
} else {
|
|
399
|
+
var item = void 0;
|
|
400
|
+
|
|
401
|
+
while (item = this._outgoingQueue.shift()) {
|
|
402
|
+
item[0].send(item[1]);
|
|
403
|
+
}
|
|
387
404
|
} // Update children
|
|
388
405
|
|
|
389
406
|
|
|
@@ -474,6 +491,8 @@ function () {
|
|
|
474
491
|
}
|
|
475
492
|
|
|
476
493
|
this._stop();
|
|
494
|
+
|
|
495
|
+
this._stopChildren();
|
|
477
496
|
}
|
|
478
497
|
};
|
|
479
498
|
/*
|
|
@@ -632,6 +651,16 @@ function () {
|
|
|
632
651
|
return this;
|
|
633
652
|
};
|
|
634
653
|
|
|
654
|
+
Interpreter.prototype._stopChildren = function () {
|
|
655
|
+
// TODO: think about converting those to actions
|
|
656
|
+
this.children.forEach(function (child) {
|
|
657
|
+
if (isFunction(child.stop)) {
|
|
658
|
+
child.stop();
|
|
659
|
+
}
|
|
660
|
+
});
|
|
661
|
+
this.children.clear();
|
|
662
|
+
};
|
|
663
|
+
|
|
635
664
|
Interpreter.prototype._stop = function () {
|
|
636
665
|
var e_6, _a, e_7, _b, e_8, _c, e_9, _d, e_10, _e;
|
|
637
666
|
|
|
@@ -769,7 +798,7 @@ function () {
|
|
|
769
798
|
return toActionObjects(stateNode.onExit, _this.machine.options.actions);
|
|
770
799
|
}));
|
|
771
800
|
|
|
772
|
-
var _a = __read(resolveActions(_this.machine, _this.state, _this.state.context, _event, exitActions, _this.machine.config.predictableActionArguments ? _this._exec : undefined, _this.machine.config.predictableActionArguments || _this.machine.config.preserveActionOrder), 2),
|
|
801
|
+
var _a = __read(resolveActions(_this.machine, _this.state, _this.state.context, _event, [exitActions], _this.machine.config.predictableActionArguments ? _this._exec : undefined, _this.machine.config.predictableActionArguments || _this.machine.config.preserveActionOrder), 2),
|
|
773
802
|
resolvedActions = _a[0],
|
|
774
803
|
updatedContext = _a[1];
|
|
775
804
|
|
|
@@ -796,17 +825,9 @@ function () {
|
|
|
796
825
|
return newState;
|
|
797
826
|
});
|
|
798
827
|
|
|
799
|
-
_this.update(nextState, _event);
|
|
800
|
-
// Stop all children
|
|
801
|
-
|
|
828
|
+
_this.update(nextState, _event);
|
|
802
829
|
|
|
803
|
-
_this.
|
|
804
|
-
if (isFunction(child.stop)) {
|
|
805
|
-
child.stop();
|
|
806
|
-
}
|
|
807
|
-
});
|
|
808
|
-
|
|
809
|
-
_this.children.clear();
|
|
830
|
+
_this._stopChildren();
|
|
810
831
|
|
|
811
832
|
registry.free(_this.sessionId);
|
|
812
833
|
});
|
|
@@ -882,9 +903,13 @@ function () {
|
|
|
882
903
|
return this.send.bind(this, event);
|
|
883
904
|
};
|
|
884
905
|
|
|
885
|
-
Interpreter.prototype._nextState = function (event) {
|
|
906
|
+
Interpreter.prototype._nextState = function (event, exec) {
|
|
886
907
|
var _this = this;
|
|
887
908
|
|
|
909
|
+
if (exec === void 0) {
|
|
910
|
+
exec = !!this.machine.config.predictableActionArguments && this._exec;
|
|
911
|
+
}
|
|
912
|
+
|
|
888
913
|
var _event = toSCXMLEvent(event);
|
|
889
914
|
|
|
890
915
|
if (_event.name.indexOf(errorPlatform) === 0 && !this.state.nextEvents.some(function (nextEvent) {
|
|
@@ -894,7 +919,7 @@ function () {
|
|
|
894
919
|
}
|
|
895
920
|
|
|
896
921
|
var nextState = provide(this, function () {
|
|
897
|
-
return _this.machine.transition(_this.state, _event, undefined,
|
|
922
|
+
return _this.machine.transition(_this.state, _event, undefined, exec || undefined);
|
|
898
923
|
});
|
|
899
924
|
return nextState;
|
|
900
925
|
};
|
|
@@ -908,7 +933,7 @@ function () {
|
|
|
908
933
|
|
|
909
934
|
|
|
910
935
|
Interpreter.prototype.nextState = function (event) {
|
|
911
|
-
return this._nextState(event);
|
|
936
|
+
return this._nextState(event, false);
|
|
912
937
|
};
|
|
913
938
|
|
|
914
939
|
Interpreter.prototype.forward = function (event) {
|
package/lib/StateNode.js
CHANGED
|
@@ -671,9 +671,11 @@ function () {
|
|
|
671
671
|
return nodes;
|
|
672
672
|
};
|
|
673
673
|
|
|
674
|
-
StateNode.prototype.getActions = function (resolvedConfig, isDone, transition, currentContext, _event, prevState) {
|
|
674
|
+
StateNode.prototype.getActions = function (resolvedConfig, isDone, transition, currentContext, _event, prevState, predictableExec) {
|
|
675
675
|
var e_4, _a, e_5, _b;
|
|
676
676
|
|
|
677
|
+
var _this = this;
|
|
678
|
+
|
|
677
679
|
var prevConfig = stateUtils.getConfiguration([], prevState ? this.getStateNodes(prevState.value) : [this]);
|
|
678
680
|
|
|
679
681
|
try {
|
|
@@ -751,20 +753,19 @@ function () {
|
|
|
751
753
|
});
|
|
752
754
|
var entryStates = new Set(transition.entrySet);
|
|
753
755
|
var exitStates = new Set(transition.exitSet);
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
756
|
+
var entryActions = Array.from(entryStates).map(function (stateNode) {
|
|
757
|
+
var entryActions = stateNode.onEntry;
|
|
758
|
+
var invokeActions = stateNode.activities.map(function (activity) {
|
|
757
759
|
return actions.start(activity);
|
|
758
|
-
})
|
|
759
|
-
|
|
760
|
-
|
|
760
|
+
});
|
|
761
|
+
return actions.toActionObjects(predictableExec ? _tslib.__spreadArray(_tslib.__spreadArray([], _tslib.__read(entryActions), false), _tslib.__read(invokeActions), false) : _tslib.__spreadArray(_tslib.__spreadArray([], _tslib.__read(invokeActions), false), _tslib.__read(entryActions), false), _this.machine.options.actions);
|
|
762
|
+
}).concat([doneEvents.map(actions.raise)]);
|
|
763
|
+
var exitActions = Array.from(exitStates).map(function (stateNode) {
|
|
764
|
+
return actions.toActionObjects(_tslib.__spreadArray(_tslib.__spreadArray([], _tslib.__read(stateNode.onExit), false), _tslib.__read(stateNode.activities.map(function (activity) {
|
|
761
765
|
return actions.stop(activity);
|
|
762
|
-
})), false);
|
|
763
|
-
})
|
|
764
|
-
|
|
765
|
-
exitActions = _c[1];
|
|
766
|
-
|
|
767
|
-
var actions$1 = actions.toActionObjects(exitActions.concat(transition.actions).concat(entryActions), this.machine.options.actions);
|
|
766
|
+
})), false), _this.machine.options.actions);
|
|
767
|
+
});
|
|
768
|
+
var actions$1 = exitActions.concat([actions.toActionObjects(transition.actions, this.machine.options.actions)]).concat(entryActions);
|
|
768
769
|
|
|
769
770
|
if (isDone) {
|
|
770
771
|
var stopActions = actions.toActionObjects(utils.flatten(_tslib.__spreadArray([], _tslib.__read(resolvedConfig), false).sort(function (a, b) {
|
|
@@ -774,7 +775,7 @@ function () {
|
|
|
774
775
|
})), this.machine.options.actions).filter(function (action) {
|
|
775
776
|
return action.type !== actionTypes.raise && (action.type !== actionTypes.send || !!action.to && action.to !== types.SpecialTargets.Internal);
|
|
776
777
|
});
|
|
777
|
-
return actions$1.concat(stopActions);
|
|
778
|
+
return actions$1.concat([stopActions]);
|
|
778
779
|
}
|
|
779
780
|
|
|
780
781
|
return actions$1;
|
|
@@ -845,7 +846,7 @@ function () {
|
|
|
845
846
|
};
|
|
846
847
|
|
|
847
848
|
StateNode.prototype.resolveTransition = function (stateTransition, currentState, context, predictableExec, _event) {
|
|
848
|
-
var e_6, _a;
|
|
849
|
+
var e_6, _a, e_7, _b;
|
|
849
850
|
|
|
850
851
|
var _this = this;
|
|
851
852
|
|
|
@@ -862,17 +863,33 @@ function () {
|
|
|
862
863
|
var isDone = stateUtils.isInFinalState(resolvedConfiguration, this);
|
|
863
864
|
var resolvedStateValue = willTransition ? stateUtils.getValue(this.machine, configuration) : undefined;
|
|
864
865
|
var historyValue = currentState ? currentState.historyValue ? currentState.historyValue : stateTransition.source ? this.machine.historyValue(currentState.value) : undefined : undefined;
|
|
865
|
-
var
|
|
866
|
+
var actionBlocks = this.getActions(new Set(resolvedConfiguration), isDone, stateTransition, context, _event, currentState, predictableExec);
|
|
866
867
|
var activities = currentState ? _tslib.__assign({}, currentState.activities) : {};
|
|
867
868
|
|
|
868
869
|
try {
|
|
869
|
-
for (var
|
|
870
|
-
var
|
|
870
|
+
for (var actionBlocks_1 = _tslib.__values(actionBlocks), actionBlocks_1_1 = actionBlocks_1.next(); !actionBlocks_1_1.done; actionBlocks_1_1 = actionBlocks_1.next()) {
|
|
871
|
+
var block = actionBlocks_1_1.value;
|
|
871
872
|
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
873
|
+
try {
|
|
874
|
+
for (var block_1 = (e_7 = void 0, _tslib.__values(block)), block_1_1 = block_1.next(); !block_1_1.done; block_1_1 = block_1.next()) {
|
|
875
|
+
var action = block_1_1.value;
|
|
876
|
+
|
|
877
|
+
if (action.type === actionTypes.start) {
|
|
878
|
+
activities[action.activity.id || action.activity.type] = action;
|
|
879
|
+
} else if (action.type === actionTypes.stop) {
|
|
880
|
+
activities[action.activity.id || action.activity.type] = false;
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
} catch (e_7_1) {
|
|
884
|
+
e_7 = {
|
|
885
|
+
error: e_7_1
|
|
886
|
+
};
|
|
887
|
+
} finally {
|
|
888
|
+
try {
|
|
889
|
+
if (block_1_1 && !block_1_1.done && (_b = block_1.return)) _b.call(block_1);
|
|
890
|
+
} finally {
|
|
891
|
+
if (e_7) throw e_7.error;
|
|
892
|
+
}
|
|
876
893
|
}
|
|
877
894
|
}
|
|
878
895
|
} catch (e_6_1) {
|
|
@@ -881,21 +898,21 @@ function () {
|
|
|
881
898
|
};
|
|
882
899
|
} finally {
|
|
883
900
|
try {
|
|
884
|
-
if (
|
|
901
|
+
if (actionBlocks_1_1 && !actionBlocks_1_1.done && (_a = actionBlocks_1.return)) _a.call(actionBlocks_1);
|
|
885
902
|
} finally {
|
|
886
903
|
if (e_6) throw e_6.error;
|
|
887
904
|
}
|
|
888
905
|
}
|
|
889
906
|
|
|
890
|
-
var
|
|
891
|
-
resolvedActions =
|
|
892
|
-
updatedContext =
|
|
907
|
+
var _c = _tslib.__read(actions.resolveActions(this, currentState, context, _event, actionBlocks, predictableExec, this.machine.config.predictableActionArguments || this.machine.config.preserveActionOrder), 2),
|
|
908
|
+
resolvedActions = _c[0],
|
|
909
|
+
updatedContext = _c[1];
|
|
893
910
|
|
|
894
|
-
var
|
|
911
|
+
var _d = _tslib.__read(utils.partition(resolvedActions, function (action) {
|
|
895
912
|
return action.type === actionTypes.raise || action.type === actionTypes.send && action.to === types.SpecialTargets.Internal;
|
|
896
913
|
}), 2),
|
|
897
|
-
raisedEvents =
|
|
898
|
-
nonRaisedActions =
|
|
914
|
+
raisedEvents = _d[0],
|
|
915
|
+
nonRaisedActions = _d[1];
|
|
899
916
|
|
|
900
917
|
var invokeActions = resolvedActions.filter(function (action) {
|
|
901
918
|
var _a;
|
|
@@ -1344,7 +1361,7 @@ function () {
|
|
|
1344
1361
|
* All the event types accepted by this state node and its descendants.
|
|
1345
1362
|
*/
|
|
1346
1363
|
get: function () {
|
|
1347
|
-
var
|
|
1364
|
+
var e_8, _a, e_9, _b;
|
|
1348
1365
|
|
|
1349
1366
|
if (this.__cache.events) {
|
|
1350
1367
|
return this.__cache.events;
|
|
@@ -1361,32 +1378,32 @@ function () {
|
|
|
1361
1378
|
|
|
1362
1379
|
if (state.states) {
|
|
1363
1380
|
try {
|
|
1364
|
-
for (var _e = (
|
|
1381
|
+
for (var _e = (e_9 = void 0, _tslib.__values(state.events)), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
1365
1382
|
var event_1 = _f.value;
|
|
1366
1383
|
events.add("".concat(event_1));
|
|
1367
1384
|
}
|
|
1368
|
-
} catch (
|
|
1369
|
-
|
|
1370
|
-
error:
|
|
1385
|
+
} catch (e_9_1) {
|
|
1386
|
+
e_9 = {
|
|
1387
|
+
error: e_9_1
|
|
1371
1388
|
};
|
|
1372
1389
|
} finally {
|
|
1373
1390
|
try {
|
|
1374
1391
|
if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
|
|
1375
1392
|
} finally {
|
|
1376
|
-
if (
|
|
1393
|
+
if (e_9) throw e_9.error;
|
|
1377
1394
|
}
|
|
1378
1395
|
}
|
|
1379
1396
|
}
|
|
1380
1397
|
}
|
|
1381
|
-
} catch (
|
|
1382
|
-
|
|
1383
|
-
error:
|
|
1398
|
+
} catch (e_8_1) {
|
|
1399
|
+
e_8 = {
|
|
1400
|
+
error: e_8_1
|
|
1384
1401
|
};
|
|
1385
1402
|
} finally {
|
|
1386
1403
|
try {
|
|
1387
1404
|
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
1388
1405
|
} finally {
|
|
1389
|
-
if (
|
|
1406
|
+
if (e_8) throw e_8.error;
|
|
1390
1407
|
}
|
|
1391
1408
|
}
|
|
1392
1409
|
}
|
|
@@ -1481,7 +1498,7 @@ function () {
|
|
|
1481
1498
|
};
|
|
1482
1499
|
|
|
1483
1500
|
StateNode.prototype.formatTransitions = function () {
|
|
1484
|
-
var
|
|
1501
|
+
var e_10, _a;
|
|
1485
1502
|
|
|
1486
1503
|
var _this = this;
|
|
1487
1504
|
|
|
@@ -1545,15 +1562,15 @@ function () {
|
|
|
1545
1562
|
var delayedTransition = delayedTransitions_1_1.value;
|
|
1546
1563
|
formattedTransitions.push(delayedTransition);
|
|
1547
1564
|
}
|
|
1548
|
-
} catch (
|
|
1549
|
-
|
|
1550
|
-
error:
|
|
1565
|
+
} catch (e_10_1) {
|
|
1566
|
+
e_10 = {
|
|
1567
|
+
error: e_10_1
|
|
1551
1568
|
};
|
|
1552
1569
|
} finally {
|
|
1553
1570
|
try {
|
|
1554
1571
|
if (delayedTransitions_1_1 && !delayedTransitions_1_1.done && (_a = delayedTransitions_1.return)) _a.call(delayedTransitions_1);
|
|
1555
1572
|
} finally {
|
|
1556
|
-
if (
|
|
1573
|
+
if (e_10) throw e_10.error;
|
|
1557
1574
|
}
|
|
1558
1575
|
}
|
|
1559
1576
|
|
package/lib/actions.d.ts
CHANGED
|
@@ -150,5 +150,5 @@ export declare function forwardTo<TContext, TEvent extends EventObject>(target:
|
|
|
150
150
|
*/
|
|
151
151
|
export declare function escalate<TContext, TEvent extends EventObject, TErrorData = any>(errorData: TErrorData | ExprWithMeta<TContext, TEvent, TErrorData>, options?: SendActionOptions<TContext, TEvent>): SendAction<TContext, TEvent, AnyEventObject>;
|
|
152
152
|
export declare function choose<TContext, TEvent extends EventObject>(conds: Array<ChooseCondition<TContext, TEvent>>): ChooseAction<TContext, TEvent>;
|
|
153
|
-
export declare function resolveActions<TContext, TEvent extends EventObject>(machine: StateNode<TContext, any, TEvent, any, any, any>, currentState: State<TContext, TEvent, any, any, any> | undefined, currentContext: TContext, _event: SCXML.Event<TEvent>,
|
|
153
|
+
export declare function resolveActions<TContext, TEvent extends EventObject>(machine: StateNode<TContext, any, TEvent, any, any, any>, currentState: State<TContext, TEvent, any, any, any> | undefined, currentContext: TContext, _event: SCXML.Event<TEvent>, actionBlocks: Array<Array<ActionObject<TContext, TEvent>>>, predictableExec?: PredictableActionArgumentsExec, preserveActionOrder?: boolean): [Array<ActionObject<TContext, TEvent>>, TContext];
|
|
154
154
|
//# sourceMappingURL=actions.d.ts.map
|
package/lib/actions.js
CHANGED
|
@@ -428,20 +428,53 @@ function choose(conds) {
|
|
|
428
428
|
conds: conds
|
|
429
429
|
};
|
|
430
430
|
}
|
|
431
|
-
|
|
431
|
+
|
|
432
|
+
var pluckAssigns = function (actionBlocks) {
|
|
433
|
+
var e_1, _a;
|
|
434
|
+
|
|
435
|
+
var assignActions = [];
|
|
436
|
+
|
|
437
|
+
try {
|
|
438
|
+
for (var actionBlocks_1 = _tslib.__values(actionBlocks), actionBlocks_1_1 = actionBlocks_1.next(); !actionBlocks_1_1.done; actionBlocks_1_1 = actionBlocks_1.next()) {
|
|
439
|
+
var block = actionBlocks_1_1.value;
|
|
440
|
+
var i = 0;
|
|
441
|
+
|
|
442
|
+
while (i < block.length) {
|
|
443
|
+
if (block[i].type === actionTypes.assign) {
|
|
444
|
+
assignActions.push(block[i]);
|
|
445
|
+
block.splice(i, 1);
|
|
446
|
+
continue;
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
i++;
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
} catch (e_1_1) {
|
|
453
|
+
e_1 = {
|
|
454
|
+
error: e_1_1
|
|
455
|
+
};
|
|
456
|
+
} finally {
|
|
457
|
+
try {
|
|
458
|
+
if (actionBlocks_1_1 && !actionBlocks_1_1.done && (_a = actionBlocks_1.return)) _a.call(actionBlocks_1);
|
|
459
|
+
} finally {
|
|
460
|
+
if (e_1) throw e_1.error;
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
return assignActions;
|
|
465
|
+
};
|
|
466
|
+
|
|
467
|
+
function resolveActions(machine, currentState, currentContext, _event, actionBlocks, predictableExec, preserveActionOrder) {
|
|
432
468
|
if (preserveActionOrder === void 0) {
|
|
433
469
|
preserveActionOrder = false;
|
|
434
470
|
}
|
|
435
471
|
|
|
436
|
-
var
|
|
437
|
-
return action.type === actionTypes.assign;
|
|
438
|
-
}), 2),
|
|
439
|
-
assignActions = _a[0],
|
|
440
|
-
otherActions = _a[1];
|
|
441
|
-
|
|
472
|
+
var assignActions = preserveActionOrder ? [] : pluckAssigns(actionBlocks);
|
|
442
473
|
var updatedContext = assignActions.length ? utils.updateContext(currentContext, _event, assignActions, currentState) : currentContext;
|
|
443
474
|
var preservedContexts = preserveActionOrder ? [currentContext] : undefined;
|
|
444
|
-
var
|
|
475
|
+
var deferredToBlockEnd = [];
|
|
476
|
+
|
|
477
|
+
function handleAction(actionObject) {
|
|
445
478
|
var _a;
|
|
446
479
|
|
|
447
480
|
switch (actionObject.type) {
|
|
@@ -459,8 +492,8 @@ function resolveActions(machine, currentState, currentContext, _event, actions,
|
|
|
459
492
|
"No delay reference for delay expression '".concat(actionObject.delay, "' was found on machine '").concat(machine.id, "'"));
|
|
460
493
|
}
|
|
461
494
|
|
|
462
|
-
if (sendAction.to !== types.SpecialTargets.Internal) {
|
|
463
|
-
|
|
495
|
+
if (predictableExec && sendAction.to !== types.SpecialTargets.Internal) {
|
|
496
|
+
deferredToBlockEnd.push(sendAction);
|
|
464
497
|
}
|
|
465
498
|
|
|
466
499
|
return sendAction;
|
|
@@ -484,7 +517,7 @@ function resolveActions(machine, currentState, currentContext, _event, actions,
|
|
|
484
517
|
return [];
|
|
485
518
|
}
|
|
486
519
|
|
|
487
|
-
var _b = _tslib.__read(resolveActions(machine, currentState, updatedContext, _event, toActionObjects(utils.toArray(matchedActions), machine.options.actions), predictableExec, preserveActionOrder), 2),
|
|
520
|
+
var _b = _tslib.__read(resolveActions(machine, currentState, updatedContext, _event, [toActionObjects(utils.toArray(matchedActions), machine.options.actions)], predictableExec, preserveActionOrder), 2),
|
|
488
521
|
resolvedActionsFromChoose = _b[0],
|
|
489
522
|
resolvedContextFromChoose = _b[1];
|
|
490
523
|
|
|
@@ -501,7 +534,7 @@ function resolveActions(machine, currentState, currentContext, _event, actions,
|
|
|
501
534
|
return [];
|
|
502
535
|
}
|
|
503
536
|
|
|
504
|
-
var _c = _tslib.__read(resolveActions(machine, currentState, updatedContext, _event, toActionObjects(utils.toArray(matchedActions), machine.options.actions), predictableExec, preserveActionOrder), 2),
|
|
537
|
+
var _c = _tslib.__read(resolveActions(machine, currentState, updatedContext, _event, [toActionObjects(utils.toArray(matchedActions), machine.options.actions)], predictableExec, preserveActionOrder), 2),
|
|
505
538
|
resolvedActionsFromPure = _c[0],
|
|
506
539
|
resolvedContext = _c[1];
|
|
507
540
|
|
|
@@ -513,7 +546,7 @@ function resolveActions(machine, currentState, currentContext, _event, actions,
|
|
|
513
546
|
case actionTypes.stop:
|
|
514
547
|
{
|
|
515
548
|
var resolved = resolveStop(actionObject, updatedContext, _event);
|
|
516
|
-
predictableExec === null || predictableExec === void 0 ? void 0 : predictableExec(resolved,
|
|
549
|
+
predictableExec === null || predictableExec === void 0 ? void 0 : predictableExec(resolved, currentContext, _event);
|
|
517
550
|
return resolved;
|
|
518
551
|
}
|
|
519
552
|
|
|
@@ -547,9 +580,42 @@ function resolveActions(machine, currentState, currentContext, _event, actions,
|
|
|
547
580
|
|
|
548
581
|
return resolvedActionObject;
|
|
549
582
|
}
|
|
550
|
-
}
|
|
551
|
-
|
|
552
|
-
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
function processBlock(block) {
|
|
586
|
+
var e_2, _a;
|
|
587
|
+
|
|
588
|
+
var resolvedActions = [];
|
|
589
|
+
|
|
590
|
+
try {
|
|
591
|
+
for (var block_1 = _tslib.__values(block), block_1_1 = block_1.next(); !block_1_1.done; block_1_1 = block_1.next()) {
|
|
592
|
+
var action = block_1_1.value;
|
|
593
|
+
var resolved = handleAction(action);
|
|
594
|
+
|
|
595
|
+
if (resolved) {
|
|
596
|
+
resolvedActions = resolvedActions.concat(resolved);
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
} catch (e_2_1) {
|
|
600
|
+
e_2 = {
|
|
601
|
+
error: e_2_1
|
|
602
|
+
};
|
|
603
|
+
} finally {
|
|
604
|
+
try {
|
|
605
|
+
if (block_1_1 && !block_1_1.done && (_a = block_1.return)) _a.call(block_1);
|
|
606
|
+
} finally {
|
|
607
|
+
if (e_2) throw e_2.error;
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
deferredToBlockEnd.forEach(function (action) {
|
|
612
|
+
predictableExec(action, updatedContext, _event);
|
|
613
|
+
});
|
|
614
|
+
deferredToBlockEnd.length = 0;
|
|
615
|
+
return resolvedActions;
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
var resolvedActions = utils.flatten(actionBlocks.map(processBlock));
|
|
553
619
|
return [resolvedActions, updatedContext];
|
|
554
620
|
}
|
|
555
621
|
|
package/lib/interpreter.d.ts
CHANGED
|
@@ -73,6 +73,7 @@ export declare class Interpreter<TContext, TStateSchema extends StateSchema = an
|
|
|
73
73
|
sessionId: string;
|
|
74
74
|
children: Map<string | number, ActorRef<any>>;
|
|
75
75
|
private forwardTo;
|
|
76
|
+
private _outgoingQueue;
|
|
76
77
|
private devTools?;
|
|
77
78
|
/**
|
|
78
79
|
* Creates a new Interpreter instance (i.e., service) for the given machine with the provided options, if any.
|
|
@@ -134,6 +135,7 @@ export declare class Interpreter<TContext, TStateSchema extends StateSchema = an
|
|
|
134
135
|
* @param initialState The state to start the statechart from
|
|
135
136
|
*/
|
|
136
137
|
start(initialState?: State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta> | StateConfig<TContext, TEvent> | StateValue): this;
|
|
138
|
+
private _stopChildren;
|
|
137
139
|
private _stop;
|
|
138
140
|
/**
|
|
139
141
|
* Stops the interpreter and unsubscribe all listeners.
|