xstate 5.0.0-beta.7 → 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-a1a641d3.cjs.prod.js → actions-900f9761.cjs.prod.js} +94 -49
- package/dist/{actions-b334e916.esm.js → actions-c8d7df32.esm.js} +93 -48
- package/dist/{actions-0fcf4fd9.cjs.dev.js → actions-d06ca158.cjs.dev.js} +94 -49
- 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 +3 -3
- package/dist/declarations/src/waitFor.d.ts +33 -0
- package/dist/xstate.cjs.dev.js +85 -50
- package/dist/xstate.cjs.prod.js +82 -50
- package/dist/xstate.esm.js +71 -48
- 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.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 () {
|
|
@@ -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 () {
|
|
@@ -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 };
|