xstate 5.0.0-alpha.6 → 5.0.0-beta.8
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.dev.js +2 -1
- package/actions/dist/xstate-actions.cjs.prod.js +2 -1
- 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.dev.js +2 -1
- package/actors/dist/xstate-actors.cjs.prod.js +2 -1
- 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/dist/{actions-c46e4911.cjs.prod.js → actions-900f9761.cjs.prod.js} +100 -55
- package/dist/{actions-41b74cdc.esm.js → actions-c8d7df32.esm.js} +99 -54
- package/dist/{actions-bf7bb1c5.cjs.dev.js → actions-d06ca158.cjs.dev.js} +100 -55
- package/dist/declarations/src/StateMachine.d.ts +2 -2
- package/dist/declarations/src/actions.d.ts +1 -0
- 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/index.d.ts +12 -28
- package/dist/declarations/src/types.d.ts +5 -5
- package/dist/declarations/src/waitFor.d.ts +33 -0
- package/dist/xstate.cjs.dev.js +87 -52
- package/dist/xstate.cjs.prod.js +84 -52
- package/dist/xstate.esm.js +73 -50
- package/dist/xstate.umd.min.js +1 -1
- package/dist/xstate.umd.min.js.map +1 -1
- package/guards/dist/xstate-guards.cjs.dev.js +1 -1
- package/guards/dist/xstate-guards.cjs.prod.js +1 -1
- package/guards/dist/xstate-guards.esm.js +1 -1
- package/guards/dist/xstate-guards.umd.min.js.map +1 -1
- package/package.json +1 -1
- package/dist/declarations/src/schema.d.ts +0 -2
package/dist/xstate.cjs.dev.js
CHANGED
|
@@ -2,30 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var actors_dist_xstateActors = require('./actions-
|
|
5
|
+
var actors_dist_xstateActors = require('./actions-d06ca158.cjs.dev.js');
|
|
6
6
|
require('./index-ebaab3c9.cjs.dev.js');
|
|
7
7
|
|
|
8
|
-
function pure(getActions) {
|
|
9
|
-
return actors_dist_xstateActors.createDynamicAction({
|
|
10
|
-
type: actors_dist_xstateActors.pure,
|
|
11
|
-
params: {
|
|
12
|
-
get: getActions
|
|
13
|
-
}
|
|
14
|
-
}, function (_event, _ref) {
|
|
15
|
-
var _toArray;
|
|
16
|
-
var state = _ref.state;
|
|
17
|
-
return [state, {
|
|
18
|
-
type: actors_dist_xstateActors.pure,
|
|
19
|
-
params: {
|
|
20
|
-
actions: (_toArray = actors_dist_xstateActors.toArray(actors_dist_xstateActors.toActionObjects(getActions({
|
|
21
|
-
context: state.context,
|
|
22
|
-
event: _event.data
|
|
23
|
-
})))) !== null && _toArray !== void 0 ? _toArray : []
|
|
24
|
-
}
|
|
25
|
-
}];
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
|
|
29
8
|
var _excluded = ["onDone", "onError"];
|
|
30
9
|
var EMPTY_OBJECT = {};
|
|
31
10
|
var StateNode = /*#__PURE__*/function () {
|
|
@@ -176,7 +155,7 @@ var StateNode = /*#__PURE__*/function () {
|
|
|
176
155
|
source: this,
|
|
177
156
|
actions: this.initial.actions,
|
|
178
157
|
eventType: null,
|
|
179
|
-
|
|
158
|
+
reenter: false,
|
|
180
159
|
toJSON: function toJSON() {
|
|
181
160
|
return {
|
|
182
161
|
target: _this3.initial.target.map(function (t) {
|
|
@@ -400,7 +379,7 @@ var StateNode = /*#__PURE__*/function () {
|
|
|
400
379
|
key: "ownEvents",
|
|
401
380
|
get: function get() {
|
|
402
381
|
var events = new Set(this.transitions.filter(function (transition) {
|
|
403
|
-
return !(!transition.target && !transition.actions.length && !transition.
|
|
382
|
+
return !(!transition.target && !transition.actions.length && !transition.reenter);
|
|
404
383
|
}).map(function (transition) {
|
|
405
384
|
return transition.eventType;
|
|
406
385
|
}));
|
|
@@ -426,13 +405,13 @@ var StateMachine = /*#__PURE__*/function () {
|
|
|
426
405
|
* The raw config used to create the machine.
|
|
427
406
|
*/
|
|
428
407
|
config, options) {
|
|
429
|
-
var _this$config$
|
|
408
|
+
var _this$config$types;
|
|
430
409
|
actors_dist_xstateActors._classCallCheck(this, StateMachine);
|
|
431
410
|
this.config = config;
|
|
432
411
|
actors_dist_xstateActors._defineProperty(this, "version", void 0);
|
|
433
412
|
actors_dist_xstateActors._defineProperty(this, "delimiter", void 0);
|
|
434
413
|
actors_dist_xstateActors._defineProperty(this, "options", void 0);
|
|
435
|
-
actors_dist_xstateActors._defineProperty(this, "
|
|
414
|
+
actors_dist_xstateActors._defineProperty(this, "types", void 0);
|
|
436
415
|
actors_dist_xstateActors._defineProperty(this, "__xstatenode", true);
|
|
437
416
|
actors_dist_xstateActors._defineProperty(this, "idMap", new Map());
|
|
438
417
|
actors_dist_xstateActors._defineProperty(this, "root", void 0);
|
|
@@ -448,7 +427,7 @@ var StateMachine = /*#__PURE__*/function () {
|
|
|
448
427
|
this.options = Object.assign(createDefaultOptions(), options);
|
|
449
428
|
this.delimiter = this.config.delimiter || actors_dist_xstateActors.STATE_DELIMITER;
|
|
450
429
|
this.version = this.config.version;
|
|
451
|
-
this.
|
|
430
|
+
this.types = (_this$config$types = this.config.types) !== null && _this$config$types !== void 0 ? _this$config$types : {};
|
|
452
431
|
this.transition = this.transition.bind(this);
|
|
453
432
|
this.root = new StateNode(config, {
|
|
454
433
|
_key: this.id,
|
|
@@ -780,11 +759,6 @@ function mapState(stateMap, stateId) {
|
|
|
780
759
|
return stateMap[foundStateId];
|
|
781
760
|
}
|
|
782
761
|
|
|
783
|
-
function createSchema(schema) {
|
|
784
|
-
return schema;
|
|
785
|
-
}
|
|
786
|
-
var t = createSchema;
|
|
787
|
-
|
|
788
762
|
var SimulatedClock = /*#__PURE__*/function () {
|
|
789
763
|
function SimulatedClock() {
|
|
790
764
|
actors_dist_xstateActors._classCallCheck(this, SimulatedClock);
|
|
@@ -861,24 +835,73 @@ var SimulatedClock = /*#__PURE__*/function () {
|
|
|
861
835
|
return SimulatedClock;
|
|
862
836
|
}();
|
|
863
837
|
|
|
864
|
-
var
|
|
865
|
-
|
|
866
|
-
send: actors_dist_xstateActors.send,
|
|
867
|
-
sendParent: actors_dist_xstateActors.sendParent,
|
|
868
|
-
sendTo: actors_dist_xstateActors.sendTo,
|
|
869
|
-
log: actors_dist_xstateActors.log,
|
|
870
|
-
cancel: actors_dist_xstateActors.cancel,
|
|
871
|
-
stop: actors_dist_xstateActors.stop,
|
|
872
|
-
assign: actors_dist_xstateActors.assign,
|
|
873
|
-
after: actors_dist_xstateActors.after,
|
|
874
|
-
done: actors_dist_xstateActors.done,
|
|
875
|
-
respond: actors_dist_xstateActors.respond,
|
|
876
|
-
forwardTo: actors_dist_xstateActors.forwardTo,
|
|
877
|
-
escalate: actors_dist_xstateActors.escalate,
|
|
878
|
-
choose: actors_dist_xstateActors.choose,
|
|
879
|
-
pure: pure
|
|
838
|
+
var defaultWaitForOptions = {
|
|
839
|
+
timeout: 10000 // 10 seconds
|
|
880
840
|
};
|
|
881
841
|
|
|
842
|
+
/**
|
|
843
|
+
* Subscribes to an actor ref and waits for its emitted value to satisfy
|
|
844
|
+
* a predicate, and then resolves with that value.
|
|
845
|
+
* Will throw if the desired state is not reached after a timeout
|
|
846
|
+
* (defaults to 10 seconds).
|
|
847
|
+
*
|
|
848
|
+
* @example
|
|
849
|
+
* ```js
|
|
850
|
+
* const state = await waitFor(someService, state => {
|
|
851
|
+
* return state.hasTag('loaded');
|
|
852
|
+
* });
|
|
853
|
+
*
|
|
854
|
+
* state.hasTag('loaded'); // true
|
|
855
|
+
* ```
|
|
856
|
+
*
|
|
857
|
+
* @param actorRef The actor ref to subscribe to
|
|
858
|
+
* @param predicate Determines if a value matches the condition to wait for
|
|
859
|
+
* @param options
|
|
860
|
+
* @returns A promise that eventually resolves to the emitted value
|
|
861
|
+
* that matches the condition
|
|
862
|
+
*/
|
|
863
|
+
function waitFor(actorRef, predicate, options) {
|
|
864
|
+
var resolvedOptions = actors_dist_xstateActors._objectSpread2(actors_dist_xstateActors._objectSpread2({}, defaultWaitForOptions), options);
|
|
865
|
+
return new Promise(function (res, rej) {
|
|
866
|
+
var done = false;
|
|
867
|
+
if (process.env.NODE_ENV !== 'production' && resolvedOptions.timeout < 0) {
|
|
868
|
+
console.error('`timeout` passed to `waitFor` is negative and it will reject its internal promise immediately.');
|
|
869
|
+
}
|
|
870
|
+
var handle = resolvedOptions.timeout === Infinity ? undefined : setTimeout(function () {
|
|
871
|
+
sub.unsubscribe();
|
|
872
|
+
rej(new Error("Timeout of ".concat(resolvedOptions.timeout, " ms exceeded")));
|
|
873
|
+
}, resolvedOptions.timeout);
|
|
874
|
+
var dispose = function dispose() {
|
|
875
|
+
clearTimeout(handle);
|
|
876
|
+
done = true;
|
|
877
|
+
sub === null || sub === void 0 ? void 0 : sub.unsubscribe();
|
|
878
|
+
};
|
|
879
|
+
function checkEmitted(emitted) {
|
|
880
|
+
if (predicate(emitted)) {
|
|
881
|
+
dispose();
|
|
882
|
+
res(emitted);
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
|
|
886
|
+
// See if the current snapshot already matches the predicate
|
|
887
|
+
checkEmitted(actorRef.getSnapshot());
|
|
888
|
+
var sub = actorRef.subscribe({
|
|
889
|
+
next: checkEmitted,
|
|
890
|
+
error: function error(err) {
|
|
891
|
+
dispose();
|
|
892
|
+
rej(err);
|
|
893
|
+
},
|
|
894
|
+
complete: function complete() {
|
|
895
|
+
dispose();
|
|
896
|
+
rej(new Error("Actor terminated without satisfying predicate"));
|
|
897
|
+
}
|
|
898
|
+
});
|
|
899
|
+
if (done) {
|
|
900
|
+
sub.unsubscribe();
|
|
901
|
+
}
|
|
902
|
+
});
|
|
903
|
+
}
|
|
904
|
+
|
|
882
905
|
Object.defineProperty(exports, 'ActionTypes', {
|
|
883
906
|
enumerable: true,
|
|
884
907
|
get: function () {
|
|
@@ -899,23 +922,35 @@ Object.defineProperty(exports, 'SpecialTargets', {
|
|
|
899
922
|
}
|
|
900
923
|
});
|
|
901
924
|
exports.State = actors_dist_xstateActors.State;
|
|
925
|
+
exports.and = actors_dist_xstateActors.and;
|
|
902
926
|
exports.assign = actors_dist_xstateActors.assign;
|
|
927
|
+
exports.cancel = actors_dist_xstateActors.cancel;
|
|
928
|
+
exports.choose = actors_dist_xstateActors.choose;
|
|
903
929
|
exports.doneInvoke = actors_dist_xstateActors.doneInvoke;
|
|
904
930
|
exports.forwardTo = actors_dist_xstateActors.forwardTo;
|
|
931
|
+
exports.fromCallback = actors_dist_xstateActors.fromCallback;
|
|
932
|
+
exports.fromEventObservable = actors_dist_xstateActors.fromEventObservable;
|
|
933
|
+
exports.fromObservable = actors_dist_xstateActors.fromObservable;
|
|
934
|
+
exports.fromPromise = actors_dist_xstateActors.fromPromise;
|
|
935
|
+
exports.fromTransition = actors_dist_xstateActors.fromTransition;
|
|
905
936
|
exports.getStateNodes = actors_dist_xstateActors.getStateNodes;
|
|
906
937
|
exports.interpret = actors_dist_xstateActors.interpret;
|
|
938
|
+
exports.log = actors_dist_xstateActors.log;
|
|
907
939
|
exports.matchesState = actors_dist_xstateActors.matchesState;
|
|
940
|
+
exports.not = actors_dist_xstateActors.not;
|
|
941
|
+
exports.or = actors_dist_xstateActors.or;
|
|
908
942
|
exports.pathToStateValue = actors_dist_xstateActors.pathToStateValue;
|
|
909
|
-
exports.
|
|
943
|
+
exports.pure = actors_dist_xstateActors.pure;
|
|
944
|
+
exports.raise = actors_dist_xstateActors.raise;
|
|
910
945
|
exports.sendParent = actors_dist_xstateActors.sendParent;
|
|
911
946
|
exports.sendTo = actors_dist_xstateActors.sendTo;
|
|
947
|
+
exports.stateIn = actors_dist_xstateActors.stateIn;
|
|
948
|
+
exports.stop = actors_dist_xstateActors.stop;
|
|
912
949
|
exports.toObserver = actors_dist_xstateActors.toObserver;
|
|
913
950
|
exports.toSCXMLEvent = actors_dist_xstateActors.toSCXMLEvent;
|
|
914
951
|
exports.SimulatedClock = SimulatedClock;
|
|
915
952
|
exports.StateMachine = StateMachine;
|
|
916
953
|
exports.StateNode = StateNode;
|
|
917
|
-
exports.actions = actions;
|
|
918
954
|
exports.createMachine = createMachine;
|
|
919
|
-
exports.createSchema = createSchema;
|
|
920
955
|
exports.mapState = mapState;
|
|
921
|
-
exports.
|
|
956
|
+
exports.waitFor = waitFor;
|
package/dist/xstate.cjs.prod.js
CHANGED
|
@@ -2,30 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var actors_dist_xstateActors = require('./actions-
|
|
5
|
+
var actors_dist_xstateActors = require('./actions-900f9761.cjs.prod.js');
|
|
6
6
|
require('../dev/dist/xstate-dev.cjs.prod.js');
|
|
7
7
|
|
|
8
|
-
function pure(getActions) {
|
|
9
|
-
return actors_dist_xstateActors.createDynamicAction({
|
|
10
|
-
type: actors_dist_xstateActors.pure,
|
|
11
|
-
params: {
|
|
12
|
-
get: getActions
|
|
13
|
-
}
|
|
14
|
-
}, function (_event, _ref) {
|
|
15
|
-
var _toArray;
|
|
16
|
-
var state = _ref.state;
|
|
17
|
-
return [state, {
|
|
18
|
-
type: actors_dist_xstateActors.pure,
|
|
19
|
-
params: {
|
|
20
|
-
actions: (_toArray = actors_dist_xstateActors.toArray(actors_dist_xstateActors.toActionObjects(getActions({
|
|
21
|
-
context: state.context,
|
|
22
|
-
event: _event.data
|
|
23
|
-
})))) !== null && _toArray !== void 0 ? _toArray : []
|
|
24
|
-
}
|
|
25
|
-
}];
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
|
|
29
8
|
var _excluded = ["onDone", "onError"];
|
|
30
9
|
var EMPTY_OBJECT = {};
|
|
31
10
|
var StateNode = /*#__PURE__*/function () {
|
|
@@ -176,7 +155,7 @@ var StateNode = /*#__PURE__*/function () {
|
|
|
176
155
|
source: this,
|
|
177
156
|
actions: this.initial.actions,
|
|
178
157
|
eventType: null,
|
|
179
|
-
|
|
158
|
+
reenter: false,
|
|
180
159
|
toJSON: function toJSON() {
|
|
181
160
|
return {
|
|
182
161
|
target: _this3.initial.target.map(function (t) {
|
|
@@ -400,7 +379,7 @@ var StateNode = /*#__PURE__*/function () {
|
|
|
400
379
|
key: "ownEvents",
|
|
401
380
|
get: function get() {
|
|
402
381
|
var events = new Set(this.transitions.filter(function (transition) {
|
|
403
|
-
return !(!transition.target && !transition.actions.length && !transition.
|
|
382
|
+
return !(!transition.target && !transition.actions.length && !transition.reenter);
|
|
404
383
|
}).map(function (transition) {
|
|
405
384
|
return transition.eventType;
|
|
406
385
|
}));
|
|
@@ -426,13 +405,13 @@ var StateMachine = /*#__PURE__*/function () {
|
|
|
426
405
|
* The raw config used to create the machine.
|
|
427
406
|
*/
|
|
428
407
|
config, options) {
|
|
429
|
-
var _this$config$
|
|
408
|
+
var _this$config$types;
|
|
430
409
|
actors_dist_xstateActors._classCallCheck(this, StateMachine);
|
|
431
410
|
this.config = config;
|
|
432
411
|
actors_dist_xstateActors._defineProperty(this, "version", void 0);
|
|
433
412
|
actors_dist_xstateActors._defineProperty(this, "delimiter", void 0);
|
|
434
413
|
actors_dist_xstateActors._defineProperty(this, "options", void 0);
|
|
435
|
-
actors_dist_xstateActors._defineProperty(this, "
|
|
414
|
+
actors_dist_xstateActors._defineProperty(this, "types", void 0);
|
|
436
415
|
actors_dist_xstateActors._defineProperty(this, "__xstatenode", true);
|
|
437
416
|
actors_dist_xstateActors._defineProperty(this, "idMap", new Map());
|
|
438
417
|
actors_dist_xstateActors._defineProperty(this, "root", void 0);
|
|
@@ -448,7 +427,7 @@ var StateMachine = /*#__PURE__*/function () {
|
|
|
448
427
|
this.options = Object.assign(createDefaultOptions(), options);
|
|
449
428
|
this.delimiter = this.config.delimiter || actors_dist_xstateActors.STATE_DELIMITER;
|
|
450
429
|
this.version = this.config.version;
|
|
451
|
-
this.
|
|
430
|
+
this.types = (_this$config$types = this.config.types) !== null && _this$config$types !== void 0 ? _this$config$types : {};
|
|
452
431
|
this.transition = this.transition.bind(this);
|
|
453
432
|
this.root = new StateNode(config, {
|
|
454
433
|
_key: this.id,
|
|
@@ -780,11 +759,6 @@ function mapState(stateMap, stateId) {
|
|
|
780
759
|
return stateMap[foundStateId];
|
|
781
760
|
}
|
|
782
761
|
|
|
783
|
-
function createSchema(schema) {
|
|
784
|
-
return schema;
|
|
785
|
-
}
|
|
786
|
-
var t = createSchema;
|
|
787
|
-
|
|
788
762
|
var SimulatedClock = /*#__PURE__*/function () {
|
|
789
763
|
function SimulatedClock() {
|
|
790
764
|
actors_dist_xstateActors._classCallCheck(this, SimulatedClock);
|
|
@@ -861,24 +835,70 @@ var SimulatedClock = /*#__PURE__*/function () {
|
|
|
861
835
|
return SimulatedClock;
|
|
862
836
|
}();
|
|
863
837
|
|
|
864
|
-
var
|
|
865
|
-
|
|
866
|
-
send: actors_dist_xstateActors.send,
|
|
867
|
-
sendParent: actors_dist_xstateActors.sendParent,
|
|
868
|
-
sendTo: actors_dist_xstateActors.sendTo,
|
|
869
|
-
log: actors_dist_xstateActors.log,
|
|
870
|
-
cancel: actors_dist_xstateActors.cancel,
|
|
871
|
-
stop: actors_dist_xstateActors.stop,
|
|
872
|
-
assign: actors_dist_xstateActors.assign,
|
|
873
|
-
after: actors_dist_xstateActors.after,
|
|
874
|
-
done: actors_dist_xstateActors.done,
|
|
875
|
-
respond: actors_dist_xstateActors.respond,
|
|
876
|
-
forwardTo: actors_dist_xstateActors.forwardTo,
|
|
877
|
-
escalate: actors_dist_xstateActors.escalate,
|
|
878
|
-
choose: actors_dist_xstateActors.choose,
|
|
879
|
-
pure: pure
|
|
838
|
+
var defaultWaitForOptions = {
|
|
839
|
+
timeout: 10000 // 10 seconds
|
|
880
840
|
};
|
|
881
841
|
|
|
842
|
+
/**
|
|
843
|
+
* Subscribes to an actor ref and waits for its emitted value to satisfy
|
|
844
|
+
* a predicate, and then resolves with that value.
|
|
845
|
+
* Will throw if the desired state is not reached after a timeout
|
|
846
|
+
* (defaults to 10 seconds).
|
|
847
|
+
*
|
|
848
|
+
* @example
|
|
849
|
+
* ```js
|
|
850
|
+
* const state = await waitFor(someService, state => {
|
|
851
|
+
* return state.hasTag('loaded');
|
|
852
|
+
* });
|
|
853
|
+
*
|
|
854
|
+
* state.hasTag('loaded'); // true
|
|
855
|
+
* ```
|
|
856
|
+
*
|
|
857
|
+
* @param actorRef The actor ref to subscribe to
|
|
858
|
+
* @param predicate Determines if a value matches the condition to wait for
|
|
859
|
+
* @param options
|
|
860
|
+
* @returns A promise that eventually resolves to the emitted value
|
|
861
|
+
* that matches the condition
|
|
862
|
+
*/
|
|
863
|
+
function waitFor(actorRef, predicate, options) {
|
|
864
|
+
var resolvedOptions = actors_dist_xstateActors._objectSpread2(actors_dist_xstateActors._objectSpread2({}, defaultWaitForOptions), options);
|
|
865
|
+
return new Promise(function (res, rej) {
|
|
866
|
+
var done = false;
|
|
867
|
+
var handle = resolvedOptions.timeout === Infinity ? undefined : setTimeout(function () {
|
|
868
|
+
sub.unsubscribe();
|
|
869
|
+
rej(new Error("Timeout of ".concat(resolvedOptions.timeout, " ms exceeded")));
|
|
870
|
+
}, resolvedOptions.timeout);
|
|
871
|
+
var dispose = function dispose() {
|
|
872
|
+
clearTimeout(handle);
|
|
873
|
+
done = true;
|
|
874
|
+
sub === null || sub === void 0 ? void 0 : sub.unsubscribe();
|
|
875
|
+
};
|
|
876
|
+
function checkEmitted(emitted) {
|
|
877
|
+
if (predicate(emitted)) {
|
|
878
|
+
dispose();
|
|
879
|
+
res(emitted);
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
|
|
883
|
+
// See if the current snapshot already matches the predicate
|
|
884
|
+
checkEmitted(actorRef.getSnapshot());
|
|
885
|
+
var sub = actorRef.subscribe({
|
|
886
|
+
next: checkEmitted,
|
|
887
|
+
error: function error(err) {
|
|
888
|
+
dispose();
|
|
889
|
+
rej(err);
|
|
890
|
+
},
|
|
891
|
+
complete: function complete() {
|
|
892
|
+
dispose();
|
|
893
|
+
rej(new Error("Actor terminated without satisfying predicate"));
|
|
894
|
+
}
|
|
895
|
+
});
|
|
896
|
+
if (done) {
|
|
897
|
+
sub.unsubscribe();
|
|
898
|
+
}
|
|
899
|
+
});
|
|
900
|
+
}
|
|
901
|
+
|
|
882
902
|
Object.defineProperty(exports, 'ActionTypes', {
|
|
883
903
|
enumerable: true,
|
|
884
904
|
get: function () {
|
|
@@ -899,23 +919,35 @@ Object.defineProperty(exports, 'SpecialTargets', {
|
|
|
899
919
|
}
|
|
900
920
|
});
|
|
901
921
|
exports.State = actors_dist_xstateActors.State;
|
|
922
|
+
exports.and = actors_dist_xstateActors.and;
|
|
902
923
|
exports.assign = actors_dist_xstateActors.assign;
|
|
924
|
+
exports.cancel = actors_dist_xstateActors.cancel;
|
|
925
|
+
exports.choose = actors_dist_xstateActors.choose;
|
|
903
926
|
exports.doneInvoke = actors_dist_xstateActors.doneInvoke;
|
|
904
927
|
exports.forwardTo = actors_dist_xstateActors.forwardTo;
|
|
928
|
+
exports.fromCallback = actors_dist_xstateActors.fromCallback;
|
|
929
|
+
exports.fromEventObservable = actors_dist_xstateActors.fromEventObservable;
|
|
930
|
+
exports.fromObservable = actors_dist_xstateActors.fromObservable;
|
|
931
|
+
exports.fromPromise = actors_dist_xstateActors.fromPromise;
|
|
932
|
+
exports.fromTransition = actors_dist_xstateActors.fromTransition;
|
|
905
933
|
exports.getStateNodes = actors_dist_xstateActors.getStateNodes;
|
|
906
934
|
exports.interpret = actors_dist_xstateActors.interpret;
|
|
935
|
+
exports.log = actors_dist_xstateActors.log;
|
|
907
936
|
exports.matchesState = actors_dist_xstateActors.matchesState;
|
|
937
|
+
exports.not = actors_dist_xstateActors.not;
|
|
938
|
+
exports.or = actors_dist_xstateActors.or;
|
|
908
939
|
exports.pathToStateValue = actors_dist_xstateActors.pathToStateValue;
|
|
909
|
-
exports.
|
|
940
|
+
exports.pure = actors_dist_xstateActors.pure;
|
|
941
|
+
exports.raise = actors_dist_xstateActors.raise;
|
|
910
942
|
exports.sendParent = actors_dist_xstateActors.sendParent;
|
|
911
943
|
exports.sendTo = actors_dist_xstateActors.sendTo;
|
|
944
|
+
exports.stateIn = actors_dist_xstateActors.stateIn;
|
|
945
|
+
exports.stop = actors_dist_xstateActors.stop;
|
|
912
946
|
exports.toObserver = actors_dist_xstateActors.toObserver;
|
|
913
947
|
exports.toSCXMLEvent = actors_dist_xstateActors.toSCXMLEvent;
|
|
914
948
|
exports.SimulatedClock = SimulatedClock;
|
|
915
949
|
exports.StateMachine = StateMachine;
|
|
916
950
|
exports.StateNode = StateNode;
|
|
917
|
-
exports.actions = actions;
|
|
918
951
|
exports.createMachine = createMachine;
|
|
919
|
-
exports.createSchema = createSchema;
|
|
920
952
|
exports.mapState = mapState;
|
|
921
|
-
exports.
|
|
953
|
+
exports.waitFor = waitFor;
|
package/dist/xstate.esm.js
CHANGED
|
@@ -1,28 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
1
|
+
import { _ as _createClass, f as formatTransitions, t as toTransitionConfigArray, N as NULL_EVENT, a as formatTransition, m as mapValues, b as memo, c as _createForOfIteratorHelper, e as evaluateGuard, d as _toConsumableArray, g as flatten, h as _classCallCheck, i as _defineProperty, j as toActionObjects, k as toArray, l as createInvokeId, n as toInvokeConfig, o as _objectSpread2, p as invoke, q as _objectWithoutProperties, r as getDelayedTransitions, s as formatInitialTransition, u as getCandidates, v as isString, w as createSpawner, x as createInitEvent, y as getConfiguration, z as getStateNodes, A as resolveStateValue, B as isInFinalState, S as State, C as toSCXMLEvent, D as isSCXMLErrorEvent, E as macrostep, F as transitionNode, G as _slicedToArray, H as getInitialConfiguration, I as resolveActionsAndContext, J as microstep, K as error, L as isStateId, M as getStateNodeByPath, O as getPersistedState, P as resolveReferencedActor, Q as interpret, R as STATE_DELIMITER, T as initEvent, U as matchesState } from './actions-c8d7df32.esm.js';
|
|
2
|
+
export { ai as ActionTypes, Y as Interpreter, Z as InterpreterStatus, aj as SpecialTargets, S as State, ag as and, a0 as assign, a1 as cancel, a2 as choose, $ as doneInvoke, X as forwardTo, ab as fromCallback, ac as fromEventObservable, aa as fromObservable, a9 as fromPromise, ad as fromTransition, z as getStateNodes, Q as interpret, a3 as log, U as matchesState, af as not, ah as or, a7 as pathToStateValue, a4 as pure, a5 as raise, W as sendParent, V as sendTo, ae as stateIn, a6 as stop, a8 as toObserver, C as toSCXMLEvent } from './actions-c8d7df32.esm.js';
|
|
3
3
|
import './index-50bd0aff.esm.js';
|
|
4
4
|
|
|
5
|
-
function pure(getActions) {
|
|
6
|
-
return createDynamicAction({
|
|
7
|
-
type: pure$1,
|
|
8
|
-
params: {
|
|
9
|
-
get: getActions
|
|
10
|
-
}
|
|
11
|
-
}, function (_event, _ref) {
|
|
12
|
-
var _toArray;
|
|
13
|
-
var state = _ref.state;
|
|
14
|
-
return [state, {
|
|
15
|
-
type: pure$1,
|
|
16
|
-
params: {
|
|
17
|
-
actions: (_toArray = toArray(toActionObjects(getActions({
|
|
18
|
-
context: state.context,
|
|
19
|
-
event: _event.data
|
|
20
|
-
})))) !== null && _toArray !== void 0 ? _toArray : []
|
|
21
|
-
}
|
|
22
|
-
}];
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
|
|
26
5
|
var _excluded = ["onDone", "onError"];
|
|
27
6
|
var EMPTY_OBJECT = {};
|
|
28
7
|
var StateNode = /*#__PURE__*/function () {
|
|
@@ -173,7 +152,7 @@ var StateNode = /*#__PURE__*/function () {
|
|
|
173
152
|
source: this,
|
|
174
153
|
actions: this.initial.actions,
|
|
175
154
|
eventType: null,
|
|
176
|
-
|
|
155
|
+
reenter: false,
|
|
177
156
|
toJSON: function toJSON() {
|
|
178
157
|
return {
|
|
179
158
|
target: _this3.initial.target.map(function (t) {
|
|
@@ -397,7 +376,7 @@ var StateNode = /*#__PURE__*/function () {
|
|
|
397
376
|
key: "ownEvents",
|
|
398
377
|
get: function get() {
|
|
399
378
|
var events = new Set(this.transitions.filter(function (transition) {
|
|
400
|
-
return !(!transition.target && !transition.actions.length && !transition.
|
|
379
|
+
return !(!transition.target && !transition.actions.length && !transition.reenter);
|
|
401
380
|
}).map(function (transition) {
|
|
402
381
|
return transition.eventType;
|
|
403
382
|
}));
|
|
@@ -423,13 +402,13 @@ var StateMachine = /*#__PURE__*/function () {
|
|
|
423
402
|
* The raw config used to create the machine.
|
|
424
403
|
*/
|
|
425
404
|
config, options) {
|
|
426
|
-
var _this$config$
|
|
405
|
+
var _this$config$types;
|
|
427
406
|
_classCallCheck(this, StateMachine);
|
|
428
407
|
this.config = config;
|
|
429
408
|
_defineProperty(this, "version", void 0);
|
|
430
409
|
_defineProperty(this, "delimiter", void 0);
|
|
431
410
|
_defineProperty(this, "options", void 0);
|
|
432
|
-
_defineProperty(this, "
|
|
411
|
+
_defineProperty(this, "types", void 0);
|
|
433
412
|
_defineProperty(this, "__xstatenode", true);
|
|
434
413
|
_defineProperty(this, "idMap", new Map());
|
|
435
414
|
_defineProperty(this, "root", void 0);
|
|
@@ -445,7 +424,7 @@ var StateMachine = /*#__PURE__*/function () {
|
|
|
445
424
|
this.options = Object.assign(createDefaultOptions(), options);
|
|
446
425
|
this.delimiter = this.config.delimiter || STATE_DELIMITER;
|
|
447
426
|
this.version = this.config.version;
|
|
448
|
-
this.
|
|
427
|
+
this.types = (_this$config$types = this.config.types) !== null && _this$config$types !== void 0 ? _this$config$types : {};
|
|
449
428
|
this.transition = this.transition.bind(this);
|
|
450
429
|
this.root = new StateNode(config, {
|
|
451
430
|
_key: this.id,
|
|
@@ -777,11 +756,6 @@ function mapState(stateMap, stateId) {
|
|
|
777
756
|
return stateMap[foundStateId];
|
|
778
757
|
}
|
|
779
758
|
|
|
780
|
-
function createSchema(schema) {
|
|
781
|
-
return schema;
|
|
782
|
-
}
|
|
783
|
-
var t = createSchema;
|
|
784
|
-
|
|
785
759
|
var SimulatedClock = /*#__PURE__*/function () {
|
|
786
760
|
function SimulatedClock() {
|
|
787
761
|
_classCallCheck(this, SimulatedClock);
|
|
@@ -858,22 +832,71 @@ var SimulatedClock = /*#__PURE__*/function () {
|
|
|
858
832
|
return SimulatedClock;
|
|
859
833
|
}();
|
|
860
834
|
|
|
861
|
-
var
|
|
862
|
-
|
|
863
|
-
send: send,
|
|
864
|
-
sendParent: sendParent,
|
|
865
|
-
sendTo: sendTo,
|
|
866
|
-
log: log,
|
|
867
|
-
cancel: cancel,
|
|
868
|
-
stop: stop,
|
|
869
|
-
assign: assign,
|
|
870
|
-
after: after,
|
|
871
|
-
done: done,
|
|
872
|
-
respond: respond,
|
|
873
|
-
forwardTo: forwardTo,
|
|
874
|
-
escalate: escalate,
|
|
875
|
-
choose: choose,
|
|
876
|
-
pure: pure
|
|
835
|
+
var defaultWaitForOptions = {
|
|
836
|
+
timeout: 10000 // 10 seconds
|
|
877
837
|
};
|
|
878
838
|
|
|
879
|
-
|
|
839
|
+
/**
|
|
840
|
+
* Subscribes to an actor ref and waits for its emitted value to satisfy
|
|
841
|
+
* a predicate, and then resolves with that value.
|
|
842
|
+
* Will throw if the desired state is not reached after a timeout
|
|
843
|
+
* (defaults to 10 seconds).
|
|
844
|
+
*
|
|
845
|
+
* @example
|
|
846
|
+
* ```js
|
|
847
|
+
* const state = await waitFor(someService, state => {
|
|
848
|
+
* return state.hasTag('loaded');
|
|
849
|
+
* });
|
|
850
|
+
*
|
|
851
|
+
* state.hasTag('loaded'); // true
|
|
852
|
+
* ```
|
|
853
|
+
*
|
|
854
|
+
* @param actorRef The actor ref to subscribe to
|
|
855
|
+
* @param predicate Determines if a value matches the condition to wait for
|
|
856
|
+
* @param options
|
|
857
|
+
* @returns A promise that eventually resolves to the emitted value
|
|
858
|
+
* that matches the condition
|
|
859
|
+
*/
|
|
860
|
+
function waitFor(actorRef, predicate, options) {
|
|
861
|
+
var resolvedOptions = _objectSpread2(_objectSpread2({}, defaultWaitForOptions), options);
|
|
862
|
+
return new Promise(function (res, rej) {
|
|
863
|
+
var done = false;
|
|
864
|
+
if (process.env.NODE_ENV !== 'production' && resolvedOptions.timeout < 0) {
|
|
865
|
+
console.error('`timeout` passed to `waitFor` is negative and it will reject its internal promise immediately.');
|
|
866
|
+
}
|
|
867
|
+
var handle = resolvedOptions.timeout === Infinity ? undefined : setTimeout(function () {
|
|
868
|
+
sub.unsubscribe();
|
|
869
|
+
rej(new Error("Timeout of ".concat(resolvedOptions.timeout, " ms exceeded")));
|
|
870
|
+
}, resolvedOptions.timeout);
|
|
871
|
+
var dispose = function dispose() {
|
|
872
|
+
clearTimeout(handle);
|
|
873
|
+
done = true;
|
|
874
|
+
sub === null || sub === void 0 ? void 0 : sub.unsubscribe();
|
|
875
|
+
};
|
|
876
|
+
function checkEmitted(emitted) {
|
|
877
|
+
if (predicate(emitted)) {
|
|
878
|
+
dispose();
|
|
879
|
+
res(emitted);
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
|
|
883
|
+
// See if the current snapshot already matches the predicate
|
|
884
|
+
checkEmitted(actorRef.getSnapshot());
|
|
885
|
+
var sub = actorRef.subscribe({
|
|
886
|
+
next: checkEmitted,
|
|
887
|
+
error: function error(err) {
|
|
888
|
+
dispose();
|
|
889
|
+
rej(err);
|
|
890
|
+
},
|
|
891
|
+
complete: function complete() {
|
|
892
|
+
dispose();
|
|
893
|
+
rej(new Error("Actor terminated without satisfying predicate"));
|
|
894
|
+
}
|
|
895
|
+
});
|
|
896
|
+
if (done) {
|
|
897
|
+
sub.unsubscribe();
|
|
898
|
+
}
|
|
899
|
+
});
|
|
900
|
+
}
|
|
901
|
+
|
|
902
|
+
export { SimulatedClock, StateMachine, StateNode, createMachine, mapState, waitFor };
|