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
|
@@ -535,6 +535,9 @@ function send$1(eventOrExpr, options) {
|
|
|
535
535
|
var delaysMap = state.machine.options.delays;
|
|
536
536
|
|
|
537
537
|
// TODO: helper function for resolving Expr
|
|
538
|
+
if (typeof eventOrExpr === 'string') {
|
|
539
|
+
throw new Error("Only event objects may be used with sendTo; use sendTo({ type: \"".concat(eventOrExpr, "\" }) instead"));
|
|
540
|
+
}
|
|
538
541
|
var resolvedEvent = toSCXMLEvent(isFunction(eventOrExpr) ? eventOrExpr(args) : eventOrExpr);
|
|
539
542
|
var resolvedDelay;
|
|
540
543
|
if (isString(params.delay)) {
|
|
@@ -832,25 +835,28 @@ promiseCreator) {
|
|
|
832
835
|
var behavior = {
|
|
833
836
|
transition: function transition(state, event) {
|
|
834
837
|
var _event = toSCXMLEvent(event);
|
|
835
|
-
if (state.
|
|
838
|
+
if (state.status !== 'active') {
|
|
836
839
|
return state;
|
|
837
840
|
}
|
|
838
841
|
var eventObject = _event.data;
|
|
839
842
|
switch (_event.name) {
|
|
840
843
|
case resolveEventType:
|
|
841
|
-
state
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
844
|
+
return _objectSpread2(_objectSpread2({}, state), {}, {
|
|
845
|
+
status: 'done',
|
|
846
|
+
data: eventObject.data,
|
|
847
|
+
input: undefined
|
|
848
|
+
});
|
|
845
849
|
case rejectEventType:
|
|
846
|
-
state
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
+
return _objectSpread2(_objectSpread2({}, state), {}, {
|
|
851
|
+
status: 'error',
|
|
852
|
+
data: eventObject.data,
|
|
853
|
+
input: undefined
|
|
854
|
+
});
|
|
850
855
|
case stopSignalType:
|
|
851
|
-
state
|
|
852
|
-
|
|
853
|
-
|
|
856
|
+
return _objectSpread2(_objectSpread2({}, state), {}, {
|
|
857
|
+
status: 'canceled',
|
|
858
|
+
input: undefined
|
|
859
|
+
});
|
|
854
860
|
default:
|
|
855
861
|
return state;
|
|
856
862
|
}
|
|
@@ -879,7 +885,6 @@ promiseCreator) {
|
|
|
879
885
|
},
|
|
880
886
|
getInitialState: function getInitialState(_, input) {
|
|
881
887
|
return {
|
|
882
|
-
canceled: false,
|
|
883
888
|
status: 'active',
|
|
884
889
|
data: undefined,
|
|
885
890
|
input: input
|
|
@@ -914,12 +919,11 @@ function fromObservable(observableCreator) {
|
|
|
914
919
|
id = _ref.id,
|
|
915
920
|
defer = _ref.defer;
|
|
916
921
|
var _event = toSCXMLEvent(event);
|
|
917
|
-
if (state.
|
|
922
|
+
if (state.status !== 'active') {
|
|
918
923
|
return state;
|
|
919
924
|
}
|
|
920
925
|
switch (_event.name) {
|
|
921
926
|
case nextEventType:
|
|
922
|
-
state.data = event.data.data;
|
|
923
927
|
// match the exact timing of events sent by machines
|
|
924
928
|
// send actions are not executed immediately
|
|
925
929
|
defer(function () {
|
|
@@ -931,21 +935,29 @@ function fromObservable(observableCreator) {
|
|
|
931
935
|
origin: self
|
|
932
936
|
}));
|
|
933
937
|
});
|
|
934
|
-
return state
|
|
938
|
+
return _objectSpread2(_objectSpread2({}, state), {}, {
|
|
939
|
+
data: event.data.data
|
|
940
|
+
});
|
|
935
941
|
case errorEventType:
|
|
936
|
-
state
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
942
|
+
return _objectSpread2(_objectSpread2({}, state), {}, {
|
|
943
|
+
status: 'error',
|
|
944
|
+
input: undefined,
|
|
945
|
+
data: _event.data.data,
|
|
946
|
+
subscription: undefined
|
|
947
|
+
});
|
|
940
948
|
case completeEventType:
|
|
941
|
-
state
|
|
942
|
-
|
|
943
|
-
|
|
949
|
+
return _objectSpread2(_objectSpread2({}, state), {}, {
|
|
950
|
+
status: 'done',
|
|
951
|
+
input: undefined,
|
|
952
|
+
subscription: undefined
|
|
953
|
+
});
|
|
944
954
|
case stopSignalType:
|
|
945
|
-
state.canceled = true;
|
|
946
|
-
delete state.input;
|
|
947
955
|
state.subscription.unsubscribe();
|
|
948
|
-
return state
|
|
956
|
+
return _objectSpread2(_objectSpread2({}, state), {}, {
|
|
957
|
+
status: 'canceled',
|
|
958
|
+
input: undefined,
|
|
959
|
+
subscription: undefined
|
|
960
|
+
});
|
|
949
961
|
default:
|
|
950
962
|
return state;
|
|
951
963
|
}
|
|
@@ -953,7 +965,6 @@ function fromObservable(observableCreator) {
|
|
|
953
965
|
getInitialState: function getInitialState(_, input) {
|
|
954
966
|
return {
|
|
955
967
|
subscription: undefined,
|
|
956
|
-
canceled: false,
|
|
957
968
|
status: 'active',
|
|
958
969
|
data: undefined,
|
|
959
970
|
input: input
|
|
@@ -991,12 +1002,10 @@ function fromObservable(observableCreator) {
|
|
|
991
1002
|
return state.data;
|
|
992
1003
|
},
|
|
993
1004
|
getPersistedState: function getPersistedState(_ref3) {
|
|
994
|
-
var
|
|
995
|
-
status = _ref3.status,
|
|
1005
|
+
var status = _ref3.status,
|
|
996
1006
|
data = _ref3.data,
|
|
997
1007
|
input = _ref3.input;
|
|
998
1008
|
return {
|
|
999
|
-
canceled: canceled,
|
|
1000
1009
|
status: status,
|
|
1001
1010
|
data: data,
|
|
1002
1011
|
input: input
|
|
@@ -1031,24 +1040,30 @@ function fromEventObservable(lazyObservable) {
|
|
|
1031
1040
|
var behavior = {
|
|
1032
1041
|
transition: function transition(state, event) {
|
|
1033
1042
|
var _event = toSCXMLEvent(event);
|
|
1034
|
-
if (state.
|
|
1043
|
+
if (state.status !== 'active') {
|
|
1035
1044
|
return state;
|
|
1036
1045
|
}
|
|
1037
1046
|
switch (_event.name) {
|
|
1038
1047
|
case errorEventType:
|
|
1039
|
-
state
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1048
|
+
return _objectSpread2(_objectSpread2({}, state), {}, {
|
|
1049
|
+
status: 'error',
|
|
1050
|
+
input: undefined,
|
|
1051
|
+
data: _event.data.data,
|
|
1052
|
+
subscription: undefined
|
|
1053
|
+
});
|
|
1043
1054
|
case completeEventType:
|
|
1044
|
-
state
|
|
1045
|
-
|
|
1046
|
-
|
|
1055
|
+
return _objectSpread2(_objectSpread2({}, state), {}, {
|
|
1056
|
+
status: 'done',
|
|
1057
|
+
input: undefined,
|
|
1058
|
+
subscription: undefined
|
|
1059
|
+
});
|
|
1047
1060
|
case stopSignalType:
|
|
1048
|
-
state.canceled = true;
|
|
1049
|
-
delete state.input;
|
|
1050
1061
|
state.subscription.unsubscribe();
|
|
1051
|
-
return state
|
|
1062
|
+
return _objectSpread2(_objectSpread2({}, state), {}, {
|
|
1063
|
+
status: 'canceled',
|
|
1064
|
+
input: undefined,
|
|
1065
|
+
subscription: undefined
|
|
1066
|
+
});
|
|
1052
1067
|
default:
|
|
1053
1068
|
return state;
|
|
1054
1069
|
}
|
|
@@ -1056,7 +1071,6 @@ function fromEventObservable(lazyObservable) {
|
|
|
1056
1071
|
getInitialState: function getInitialState() {
|
|
1057
1072
|
return {
|
|
1058
1073
|
subscription: undefined,
|
|
1059
|
-
canceled: false,
|
|
1060
1074
|
status: 'active',
|
|
1061
1075
|
data: undefined
|
|
1062
1076
|
};
|
|
@@ -1093,12 +1107,10 @@ function fromEventObservable(lazyObservable) {
|
|
|
1093
1107
|
return undefined;
|
|
1094
1108
|
},
|
|
1095
1109
|
getPersistedState: function getPersistedState(_ref5) {
|
|
1096
|
-
var
|
|
1097
|
-
status = _ref5.status,
|
|
1110
|
+
var status = _ref5.status,
|
|
1098
1111
|
data = _ref5.data,
|
|
1099
1112
|
input = _ref5.input;
|
|
1100
1113
|
return {
|
|
1101
|
-
canceled: canceled,
|
|
1102
1114
|
status: status,
|
|
1103
1115
|
data: data,
|
|
1104
1116
|
input: input
|
|
@@ -1132,7 +1144,7 @@ function fromCallback(invokeCallback) {
|
|
|
1132
1144
|
var sender = function sender(eventForParent) {
|
|
1133
1145
|
var _self$_parent;
|
|
1134
1146
|
if (state.canceled) {
|
|
1135
|
-
return
|
|
1147
|
+
return;
|
|
1136
1148
|
}
|
|
1137
1149
|
(_self$_parent = self._parent) === null || _self$_parent === void 0 ? void 0 : _self$_parent.send(toSCXMLEvent(eventForParent, {
|
|
1138
1150
|
origin: self
|
|
@@ -1247,6 +1259,12 @@ function toActorRef(actorRefLike) {
|
|
|
1247
1259
|
return void 0;
|
|
1248
1260
|
}), _objectSpread2$1), actorRefLike);
|
|
1249
1261
|
}
|
|
1262
|
+
var emptyBehavior = fromTransition(function (_) {
|
|
1263
|
+
return undefined;
|
|
1264
|
+
}, undefined);
|
|
1265
|
+
function createEmptyActor() {
|
|
1266
|
+
return interpret(emptyBehavior);
|
|
1267
|
+
}
|
|
1250
1268
|
|
|
1251
1269
|
function createSystem() {
|
|
1252
1270
|
var sessionIdCounter = 0;
|
|
@@ -1650,6 +1668,9 @@ var Interpreter = /*#__PURE__*/function () {
|
|
|
1650
1668
|
}, {
|
|
1651
1669
|
key: "send",
|
|
1652
1670
|
value: function send(event) {
|
|
1671
|
+
if (typeof event === 'string') {
|
|
1672
|
+
throw new Error("Only event objects may be sent to actors; use .send({ type: \"".concat(event, "\" }) instead"));
|
|
1673
|
+
}
|
|
1653
1674
|
var _event = toSCXMLEvent(event);
|
|
1654
1675
|
if (this.status === exports.ActorStatus.Stopped) {
|
|
1655
1676
|
// do nothing
|
|
@@ -2256,7 +2277,7 @@ function getDelayedTransitions(stateNode) {
|
|
|
2256
2277
|
var mutateEntryExit = function mutateEntryExit(delay, i) {
|
|
2257
2278
|
var delayRef = isFunction(delay) ? "".concat(stateNode.id, ":delay[").concat(i, "]") : delay;
|
|
2258
2279
|
var eventType = after$1(delayRef, stateNode.id);
|
|
2259
|
-
stateNode.entry.push(
|
|
2280
|
+
stateNode.entry.push(raise$1({
|
|
2260
2281
|
type: eventType
|
|
2261
2282
|
}, {
|
|
2262
2283
|
delay: delay
|
|
@@ -4048,6 +4069,9 @@ function raise$1(eventOrExpr, options) {
|
|
|
4048
4069
|
var delaysMap = state.machine.options.delays;
|
|
4049
4070
|
|
|
4050
4071
|
// TODO: helper function for resolving Expr
|
|
4072
|
+
if (typeof eventOrExpr === 'string') {
|
|
4073
|
+
throw new Error("Only event objects may be used with raise; use raise({ type: \"".concat(eventOrExpr, "\" }) instead"));
|
|
4074
|
+
}
|
|
4051
4075
|
var resolvedEvent = toSCXMLEvent(typeof eventOrExpr === 'function' ? eventOrExpr(args) : eventOrExpr);
|
|
4052
4076
|
var resolvedDelay;
|
|
4053
4077
|
if (typeof params.delay === 'string') {
|
|
@@ -4098,6 +4122,27 @@ function choose$1(guards) {
|
|
|
4098
4122
|
});
|
|
4099
4123
|
}
|
|
4100
4124
|
|
|
4125
|
+
function pure$1(getActions) {
|
|
4126
|
+
return createDynamicAction({
|
|
4127
|
+
type: pure,
|
|
4128
|
+
params: {
|
|
4129
|
+
get: getActions
|
|
4130
|
+
}
|
|
4131
|
+
}, function (_event, _ref) {
|
|
4132
|
+
var _toArray;
|
|
4133
|
+
var state = _ref.state;
|
|
4134
|
+
return [state, {
|
|
4135
|
+
type: pure,
|
|
4136
|
+
params: {
|
|
4137
|
+
actions: (_toArray = toArray(toActionObjects(getActions({
|
|
4138
|
+
context: state.context,
|
|
4139
|
+
event: _event.data
|
|
4140
|
+
})))) !== null && _toArray !== void 0 ? _toArray : []
|
|
4141
|
+
}
|
|
4142
|
+
}];
|
|
4143
|
+
});
|
|
4144
|
+
}
|
|
4145
|
+
|
|
4101
4146
|
var initEvent = toSCXMLEvent({
|
|
4102
4147
|
type: init
|
|
4103
4148
|
});
|
|
@@ -4270,7 +4315,7 @@ exports.and = and;
|
|
|
4270
4315
|
exports.assign = assign$1;
|
|
4271
4316
|
exports.cancel = cancel$1;
|
|
4272
4317
|
exports.choose = choose$1;
|
|
4273
|
-
exports.
|
|
4318
|
+
exports.createEmptyActor = createEmptyActor;
|
|
4274
4319
|
exports.createInitEvent = createInitEvent;
|
|
4275
4320
|
exports.createInvokeId = createInvokeId;
|
|
4276
4321
|
exports.createSpawner = createSpawner;
|
|
@@ -4314,7 +4359,7 @@ exports.microstep = microstep;
|
|
|
4314
4359
|
exports.not = not;
|
|
4315
4360
|
exports.or = or;
|
|
4316
4361
|
exports.pathToStateValue = pathToStateValue;
|
|
4317
|
-
exports.pure = pure;
|
|
4362
|
+
exports.pure = pure$1;
|
|
4318
4363
|
exports.raise = raise$1;
|
|
4319
4364
|
exports.resolveActionObject = resolveActionObject;
|
|
4320
4365
|
exports.resolveActionsAndContext = resolveActionsAndContext;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { State } from './State.ts';
|
|
2
2
|
import { StateNode } from './StateNode.ts';
|
|
3
3
|
import type { AreAllImplementationsAssumedToBeProvided, MarkAllImplementationsAsProvided, ResolveTypegenMeta, TypegenDisabled } from './typegenTypes.ts';
|
|
4
|
-
import type { ActorContext, ActorMap, ActorBehavior, EventObject, InternalMachineImplementations, MachineConfig, MachineContext, MachineImplementationsSimplified,
|
|
4
|
+
import type { ActorContext, ActorMap, ActorBehavior, EventObject, InternalMachineImplementations, MachineConfig, MachineContext, MachineImplementationsSimplified, MachineTypes, NoInfer, SCXML, StateConfig, StateMachineDefinition, StateValue, TransitionDefinition, PersistedMachineState, ParameterizedObject, AnyActorContext } from './types.ts';
|
|
5
5
|
export declare const NULL_EVENT = "";
|
|
6
6
|
export declare const STATE_IDENTIFIER = "#";
|
|
7
7
|
export declare const WILDCARD = "*";
|
|
@@ -21,7 +21,7 @@ export declare class StateMachine<TContext extends MachineContext, TEvent extend
|
|
|
21
21
|
*/
|
|
22
22
|
delimiter: string;
|
|
23
23
|
options: MachineImplementationsSimplified<TContext, TEvent>;
|
|
24
|
-
|
|
24
|
+
types: MachineTypes<TContext, TEvent>;
|
|
25
25
|
__xstatenode: true;
|
|
26
26
|
idMap: Map<string, StateNode<TContext, TEvent>>;
|
|
27
27
|
root: StateNode<TContext, TEvent>;
|
|
@@ -7,6 +7,7 @@ export { cancel } from './actions/cancel.ts';
|
|
|
7
7
|
export { assign } from './actions/assign.ts';
|
|
8
8
|
export { raise } from './actions/raise.ts';
|
|
9
9
|
export { choose } from './actions/choose.ts';
|
|
10
|
+
export { pure } from './actions/pure.ts';
|
|
10
11
|
export { actionTypes };
|
|
11
12
|
export declare const initEvent: SCXML.Event<{
|
|
12
13
|
type: ActionTypes;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { EventObject, ActorRef, BaseActorRef } from '../types.ts';
|
|
1
|
+
import type { EventObject, ActorRef, BaseActorRef, AnyEventObject } from '../types.ts';
|
|
2
2
|
export { fromTransition } from './transition.ts';
|
|
3
3
|
export { fromPromise } from './promise.ts';
|
|
4
4
|
export { fromObservable, fromEventObservable } from './observable.ts';
|
|
@@ -25,3 +25,4 @@ export type LifecycleSignalType = typeof startSignalType | typeof stopSignalType
|
|
|
25
25
|
export declare function isSignal(eventType: string): eventType is LifecycleSignalType;
|
|
26
26
|
export declare function isActorRef(item: any): item is ActorRef<any>;
|
|
27
27
|
export declare function toActorRef<TEvent extends EventObject, TSnapshot = any, TActorRefLike extends BaseActorRef<TEvent> = BaseActorRef<TEvent>>(actorRefLike: TActorRefLike): ActorRef<TEvent, TSnapshot> & Omit<TActorRefLike, keyof ActorRef<any, any>>;
|
|
28
|
+
export declare function createEmptyActor(): ActorRef<AnyEventObject, undefined>;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { Subscribable, ActorBehavior, EventObject, Subscription } from '../types';
|
|
2
2
|
export interface ObservableInternalState<T> {
|
|
3
3
|
subscription: Subscription | undefined;
|
|
4
|
-
|
|
5
|
-
status: 'active' | 'done' | 'error';
|
|
4
|
+
status: 'active' | 'done' | 'error' | 'canceled';
|
|
6
5
|
data: T | undefined;
|
|
7
6
|
input?: any;
|
|
8
7
|
}
|
|
@@ -1,42 +1,26 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
import { stop } from './actions/stop.ts';
|
|
1
|
+
import { doneInvoke, forwardTo, sendParent, sendTo } from './actions.ts';
|
|
2
|
+
export { assign } from './actions/assign.ts';
|
|
3
|
+
export { cancel } from './actions/cancel.ts';
|
|
4
|
+
export { choose } from './actions/choose.ts';
|
|
5
|
+
export { log } from './actions/log.ts';
|
|
6
|
+
export { pure } from './actions/pure.ts';
|
|
7
|
+
export { raise } from './actions/raise.ts';
|
|
8
|
+
export { stop } from './actions/stop.ts';
|
|
10
9
|
import { interpret, Interpreter, ActorStatus } from './interpreter.ts';
|
|
11
10
|
import { createMachine } from './Machine.ts';
|
|
12
11
|
import { mapState } from './mapState.ts';
|
|
13
12
|
import { State } from './State.ts';
|
|
14
13
|
import { StateNode } from './StateNode.ts';
|
|
15
|
-
export { createSchema, t } from './schema.ts';
|
|
16
14
|
export { SimulatedClock } from './SimulatedClock.ts';
|
|
17
15
|
export { StateMachine } from './StateMachine.ts';
|
|
18
16
|
export { getStateNodes } from './stateUtils.ts';
|
|
17
|
+
export { waitFor } from './waitFor.ts';
|
|
19
18
|
export * from './typegenTypes.ts';
|
|
20
19
|
export * from './types.ts';
|
|
21
20
|
export { matchesState, pathToStateValue, toObserver, toSCXMLEvent } from './utils.ts';
|
|
22
|
-
export { StateNode, State, mapState,
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
send: typeof send;
|
|
26
|
-
sendParent: typeof sendParent;
|
|
27
|
-
sendTo: typeof sendTo;
|
|
28
|
-
log: typeof log;
|
|
29
|
-
cancel: typeof cancel;
|
|
30
|
-
stop: typeof stop;
|
|
31
|
-
assign: typeof assign;
|
|
32
|
-
after: typeof after;
|
|
33
|
-
done: typeof done;
|
|
34
|
-
respond: typeof respond;
|
|
35
|
-
forwardTo: typeof forwardTo;
|
|
36
|
-
escalate: typeof escalate;
|
|
37
|
-
choose: typeof choose;
|
|
38
|
-
pure: typeof pure;
|
|
39
|
-
};
|
|
21
|
+
export { StateNode, State, mapState, sendTo, sendParent, forwardTo, interpret, Interpreter, ActorStatus as InterpreterStatus, doneInvoke, createMachine };
|
|
22
|
+
export { fromPromise, fromObservable, fromCallback, fromEventObservable, fromTransition } from './actors/index.ts';
|
|
23
|
+
export { stateIn, not, and, or } from './guards.ts';
|
|
40
24
|
declare global {
|
|
41
25
|
interface SymbolConstructor {
|
|
42
26
|
readonly observable: symbol;
|
|
@@ -490,13 +490,12 @@ export interface MachineConfig<TContext extends MachineContext, TEvent extends E
|
|
|
490
490
|
* If `true`, will use SCXML semantics, such as event token matching.
|
|
491
491
|
*/
|
|
492
492
|
scxml?: boolean;
|
|
493
|
-
|
|
494
|
-
tsTypes?: TTypesMeta;
|
|
493
|
+
types?: MachineTypes<TContext, TEvent, TActorMap, TTypesMeta>;
|
|
495
494
|
}
|
|
496
495
|
export type ActorMap = Record<string, {
|
|
497
496
|
output: any;
|
|
498
497
|
}>;
|
|
499
|
-
export interface
|
|
498
|
+
export interface MachineTypes<TContext extends MachineContext, TEvent extends EventObject, TActorMap extends ActorMap = ActorMap, TTypesMeta = TypegenDisabled> {
|
|
500
499
|
context?: TContext;
|
|
501
500
|
actions?: {
|
|
502
501
|
type: string;
|
|
@@ -508,6 +507,7 @@ export interface MachineSchema<TContext extends MachineContext, TEvent extends E
|
|
|
508
507
|
type: string;
|
|
509
508
|
[key: string]: any;
|
|
510
509
|
};
|
|
510
|
+
typegen?: TTypesMeta;
|
|
511
511
|
}
|
|
512
512
|
export interface HistoryStateNode<TContext extends MachineContext> extends StateNode<TContext> {
|
|
513
513
|
history: 'shallow' | 'deep';
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { ActorRef, SnapshotFrom } from '.';
|
|
2
|
+
interface WaitForOptions {
|
|
3
|
+
/**
|
|
4
|
+
* How long to wait before rejecting, if no emitted
|
|
5
|
+
* state satisfies the predicate.
|
|
6
|
+
*
|
|
7
|
+
* @default 10_000 (10 seconds)
|
|
8
|
+
*/
|
|
9
|
+
timeout: number;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Subscribes to an actor ref and waits for its emitted value to satisfy
|
|
13
|
+
* a predicate, and then resolves with that value.
|
|
14
|
+
* Will throw if the desired state is not reached after a timeout
|
|
15
|
+
* (defaults to 10 seconds).
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```js
|
|
19
|
+
* const state = await waitFor(someService, state => {
|
|
20
|
+
* return state.hasTag('loaded');
|
|
21
|
+
* });
|
|
22
|
+
*
|
|
23
|
+
* state.hasTag('loaded'); // true
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @param actorRef The actor ref to subscribe to
|
|
27
|
+
* @param predicate Determines if a value matches the condition to wait for
|
|
28
|
+
* @param options
|
|
29
|
+
* @returns A promise that eventually resolves to the emitted value
|
|
30
|
+
* that matches the condition
|
|
31
|
+
*/
|
|
32
|
+
export declare function waitFor<TActorRef extends ActorRef<any, any>>(actorRef: TActorRef, predicate: (emitted: SnapshotFrom<TActorRef>) => boolean, options?: Partial<WaitForOptions>): Promise<SnapshotFrom<TActorRef>>;
|
|
33
|
+
export {};
|
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 () {
|
|
@@ -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;
|