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/lib/interpreter.js
CHANGED
|
@@ -62,6 +62,7 @@ function () {
|
|
|
62
62
|
this.status = exports.InterpreterStatus.NotStarted;
|
|
63
63
|
this.children = new Map();
|
|
64
64
|
this.forwardTo = new Set();
|
|
65
|
+
this._outgoingQueue = [];
|
|
65
66
|
/**
|
|
66
67
|
* Alias for Interpreter.prototype.start
|
|
67
68
|
*/
|
|
@@ -104,7 +105,7 @@ function () {
|
|
|
104
105
|
// Forward copy of event to child actors
|
|
105
106
|
_this.forward(_event);
|
|
106
107
|
|
|
107
|
-
var nextState = _this.
|
|
108
|
+
var nextState = _this._nextState(_event);
|
|
108
109
|
|
|
109
110
|
_this.update(nextState, _event);
|
|
110
111
|
});
|
|
@@ -136,14 +137,24 @@ function () {
|
|
|
136
137
|
if (_this.status !== exports.InterpreterStatus.Stopped || _this.parent !== target || // we need to send events to the parent from exit handlers of a machine that reached its final state
|
|
137
138
|
_this.state.done) {
|
|
138
139
|
// Send SCXML events to machines
|
|
139
|
-
|
|
140
|
+
var scxmlEvent = _tslib.__assign(_tslib.__assign({}, event), {
|
|
140
141
|
name: event.name === actionTypes.error ? "".concat(actions.error(_this.id)) : event.name,
|
|
141
142
|
origin: _this.sessionId
|
|
142
|
-
})
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
if (_this.machine.config.predictableActionArguments) {
|
|
146
|
+
_this._outgoingQueue.push([target, scxmlEvent]);
|
|
147
|
+
} else {
|
|
148
|
+
target.send(scxmlEvent);
|
|
149
|
+
}
|
|
143
150
|
}
|
|
144
151
|
} else {
|
|
145
152
|
// Send normal events to other targets
|
|
146
|
-
|
|
153
|
+
if (_this.machine.config.predictableActionArguments) {
|
|
154
|
+
_this._outgoingQueue.push([target, event.data]);
|
|
155
|
+
} else {
|
|
156
|
+
target.send(event.data);
|
|
157
|
+
}
|
|
147
158
|
}
|
|
148
159
|
};
|
|
149
160
|
|
|
@@ -388,6 +399,12 @@ function () {
|
|
|
388
399
|
// we can't just recompute it (and execute actions while doing so) because we try to preserve identity of actors created within initial assigns
|
|
389
400
|
_event === actions.initEvent) && this.options.execute) {
|
|
390
401
|
this.execute(this.state);
|
|
402
|
+
} else {
|
|
403
|
+
var item = void 0;
|
|
404
|
+
|
|
405
|
+
while (item = this._outgoingQueue.shift()) {
|
|
406
|
+
item[0].send(item[1]);
|
|
407
|
+
}
|
|
391
408
|
} // Update children
|
|
392
409
|
|
|
393
410
|
|
|
@@ -478,6 +495,8 @@ function () {
|
|
|
478
495
|
}
|
|
479
496
|
|
|
480
497
|
this._stop();
|
|
498
|
+
|
|
499
|
+
this._stopChildren();
|
|
481
500
|
}
|
|
482
501
|
};
|
|
483
502
|
/*
|
|
@@ -636,6 +655,16 @@ function () {
|
|
|
636
655
|
return this;
|
|
637
656
|
};
|
|
638
657
|
|
|
658
|
+
Interpreter.prototype._stopChildren = function () {
|
|
659
|
+
// TODO: think about converting those to actions
|
|
660
|
+
this.children.forEach(function (child) {
|
|
661
|
+
if (utils.isFunction(child.stop)) {
|
|
662
|
+
child.stop();
|
|
663
|
+
}
|
|
664
|
+
});
|
|
665
|
+
this.children.clear();
|
|
666
|
+
};
|
|
667
|
+
|
|
639
668
|
Interpreter.prototype._stop = function () {
|
|
640
669
|
var e_6, _a, e_7, _b, e_8, _c, e_9, _d, e_10, _e;
|
|
641
670
|
|
|
@@ -773,7 +802,7 @@ function () {
|
|
|
773
802
|
return actions.toActionObjects(stateNode.onExit, _this.machine.options.actions);
|
|
774
803
|
}));
|
|
775
804
|
|
|
776
|
-
var _a = _tslib.__read(actions.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),
|
|
805
|
+
var _a = _tslib.__read(actions.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),
|
|
777
806
|
resolvedActions = _a[0],
|
|
778
807
|
updatedContext = _a[1];
|
|
779
808
|
|
|
@@ -800,17 +829,9 @@ function () {
|
|
|
800
829
|
return newState;
|
|
801
830
|
});
|
|
802
831
|
|
|
803
|
-
_this.update(nextState, _event);
|
|
804
|
-
// Stop all children
|
|
805
|
-
|
|
832
|
+
_this.update(nextState, _event);
|
|
806
833
|
|
|
807
|
-
_this.
|
|
808
|
-
if (utils.isFunction(child.stop)) {
|
|
809
|
-
child.stop();
|
|
810
|
-
}
|
|
811
|
-
});
|
|
812
|
-
|
|
813
|
-
_this.children.clear();
|
|
834
|
+
_this._stopChildren();
|
|
814
835
|
|
|
815
836
|
registry.registry.free(_this.sessionId);
|
|
816
837
|
});
|
|
@@ -886,9 +907,13 @@ function () {
|
|
|
886
907
|
return this.send.bind(this, event);
|
|
887
908
|
};
|
|
888
909
|
|
|
889
|
-
Interpreter.prototype._nextState = function (event) {
|
|
910
|
+
Interpreter.prototype._nextState = function (event, exec) {
|
|
890
911
|
var _this = this;
|
|
891
912
|
|
|
913
|
+
if (exec === void 0) {
|
|
914
|
+
exec = !!this.machine.config.predictableActionArguments && this._exec;
|
|
915
|
+
}
|
|
916
|
+
|
|
892
917
|
var _event = utils.toSCXMLEvent(event);
|
|
893
918
|
|
|
894
919
|
if (_event.name.indexOf(actionTypes.errorPlatform) === 0 && !this.state.nextEvents.some(function (nextEvent) {
|
|
@@ -898,7 +923,7 @@ function () {
|
|
|
898
923
|
}
|
|
899
924
|
|
|
900
925
|
var nextState = serviceScope.provide(this, function () {
|
|
901
|
-
return _this.machine.transition(_this.state, _event, undefined,
|
|
926
|
+
return _this.machine.transition(_this.state, _event, undefined, exec || undefined);
|
|
902
927
|
});
|
|
903
928
|
return nextState;
|
|
904
929
|
};
|
|
@@ -912,7 +937,7 @@ function () {
|
|
|
912
937
|
|
|
913
938
|
|
|
914
939
|
Interpreter.prototype.nextState = function (event) {
|
|
915
|
-
return this._nextState(event);
|
|
940
|
+
return this._nextState(event, false);
|
|
916
941
|
};
|
|
917
942
|
|
|
918
943
|
Interpreter.prototype.forward = function (event) {
|