xstate 4.27.0 → 4.30.0
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/CHANGELOG.md +227 -90
- package/README.md +5 -5
- package/dist/xstate.interpreter.js +1 -1
- package/dist/xstate.js +1 -1
- package/dist/xstate.web.js +2 -2
- package/es/Actor.d.ts +1 -2
- package/es/Actor.js +5 -5
- package/es/Machine.d.ts +5 -4
- package/es/State.d.ts +17 -14
- package/es/State.js +4 -4
- package/es/StateNode.d.ts +22 -17
- package/es/StateNode.js +33 -36
- package/es/actions.d.ts +3 -4
- package/es/actions.js +22 -3
- package/es/behaviors.d.ts +1 -1
- package/es/devTools.d.ts +3 -4
- package/es/each.d.ts +1 -1
- package/es/index.d.ts +10 -21
- package/es/index.js +11 -22
- package/es/interpreter.d.ts +34 -31
- package/es/interpreter.js +21 -13
- package/es/model.d.ts +2 -2
- package/es/model.types.d.ts +8 -9
- package/es/schema.d.ts +1 -0
- package/es/schema.js +2 -1
- package/es/scxml.d.ts +2 -2
- package/es/stateUtils.d.ts +6 -5
- package/es/typegenTypes.d.ts +121 -0
- package/es/types.d.ts +118 -57
- package/es/utils.d.ts +7 -2
- package/es/utils.js +9 -2
- package/lib/Actor.d.ts +1 -2
- package/lib/Actor.js +4 -4
- package/lib/Machine.d.ts +5 -4
- package/lib/State.d.ts +17 -14
- package/lib/State.js +4 -4
- package/lib/StateNode.d.ts +22 -17
- package/lib/StateNode.js +32 -35
- package/lib/actions.d.ts +3 -4
- package/lib/actions.js +20 -0
- package/lib/behaviors.d.ts +1 -1
- package/lib/devTools.d.ts +3 -4
- package/lib/each.d.ts +1 -1
- package/lib/index.d.ts +10 -21
- package/lib/index.js +15 -26
- package/lib/interpreter.d.ts +34 -31
- package/lib/interpreter.js +18 -10
- package/lib/model.d.ts +2 -2
- package/lib/model.types.d.ts +8 -9
- package/lib/schema.d.ts +1 -0
- package/lib/schema.js +2 -0
- package/lib/scxml.d.ts +2 -2
- package/lib/stateUtils.d.ts +6 -5
- package/lib/typegenTypes.d.ts +121 -0
- package/lib/typegenTypes.js +2 -0
- package/lib/types.d.ts +118 -57
- package/lib/utils.d.ts +7 -2
- package/lib/utils.js +10 -1
- package/package.json +5 -5
package/es/StateNode.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { __assign, __spreadArray, __read, __values, __rest } from './_virtual/_tslib.js';
|
|
2
2
|
import { STATE_DELIMITER } from './constants.js';
|
|
3
3
|
import { IS_PRODUCTION } from './environment.js';
|
|
4
|
-
import { isFunction, mapValues, isArray, flatten, keys, toArray, toStateValue, isString, getEventType, toSCXMLEvent, matchesState, path, evaluateGuard, mapContext, pathToStateValue, isBuiltInEvent, partition, updateHistoryValue, toStatePath, mapFilterValues, warn, toStatePaths, nestedPath, normalizeTarget, toGuard, toTransitionConfigArray, isMachine } from './utils.js';
|
|
4
|
+
import { isFunction, mapValues, isArray, flatten, keys, toArray, toStateValue, isString, getEventType, toSCXMLEvent, matchesState, path, evaluateGuard, mapContext, pathToStateValue, isBuiltInEvent, partition, updateHistoryValue, toStatePath, mapFilterValues, warn, toStatePaths, nestedPath, normalizeTarget, toGuard, toTransitionConfigArray, isMachine, createInvokeId } from './utils.js';
|
|
5
5
|
import { SpecialTargets } from './types.js';
|
|
6
6
|
import { getAllStateNodes, getConfiguration, isInFinalState, getTagsFromConfiguration, has, getChildren, getValue, isLeafNode } from './stateUtils.js';
|
|
7
7
|
import { start as start$1, stop as stop$1, invoke, update, nullEvent, raise as raise$1, send as send$1 } from './actionTypes.js';
|
|
@@ -50,8 +50,8 @@ function () {
|
|
|
50
50
|
/**
|
|
51
51
|
* The initial extended state
|
|
52
52
|
*/
|
|
53
|
-
_context // TODO: this is unsafe, but we're removing it in v5 anyway
|
|
54
|
-
) {
|
|
53
|
+
_context, // TODO: this is unsafe, but we're removing it in v5 anyway
|
|
54
|
+
_stateInfo) {
|
|
55
55
|
var _this = this;
|
|
56
56
|
|
|
57
57
|
if (_context === void 0) {
|
|
@@ -81,8 +81,8 @@ function () {
|
|
|
81
81
|
this.idMap = {};
|
|
82
82
|
this.tags = [];
|
|
83
83
|
this.options = Object.assign(createDefaultOptions(), options);
|
|
84
|
-
this.parent =
|
|
85
|
-
this.key = this.config.key ||
|
|
84
|
+
this.parent = _stateInfo === null || _stateInfo === void 0 ? void 0 : _stateInfo.parent;
|
|
85
|
+
this.key = this.config.key || (_stateInfo === null || _stateInfo === void 0 ? void 0 : _stateInfo.key) || this.config.id || '(machine)';
|
|
86
86
|
this.machine = this.parent ? this.parent.machine : this;
|
|
87
87
|
this.path = this.parent ? this.parent.path.concat(this.key) : [];
|
|
88
88
|
this.delimiter = this.config.delimiter || (this.parent ? this.parent.delimiter : STATE_DELIMITER);
|
|
@@ -100,9 +100,9 @@ function () {
|
|
|
100
100
|
this.states = this.config.states ? mapValues(this.config.states, function (stateConfig, key) {
|
|
101
101
|
var _a;
|
|
102
102
|
|
|
103
|
-
var stateNode = new StateNode(stateConfig, {
|
|
104
|
-
|
|
105
|
-
|
|
103
|
+
var stateNode = new StateNode(stateConfig, {}, undefined, {
|
|
104
|
+
parent: _this,
|
|
105
|
+
key: key
|
|
106
106
|
});
|
|
107
107
|
Object.assign(_this.idMap, __assign((_a = {}, _a[stateNode.id] = stateNode, _a), stateNode.idMap));
|
|
108
108
|
return stateNode;
|
|
@@ -155,29 +155,30 @@ function () {
|
|
|
155
155
|
var _a, _b;
|
|
156
156
|
|
|
157
157
|
if (isMachine(invokeConfig)) {
|
|
158
|
-
|
|
158
|
+
var invokeId = createInvokeId(_this.id, i);
|
|
159
|
+
_this.machine.options.services = __assign((_a = {}, _a[invokeId] = invokeConfig, _a), _this.machine.options.services);
|
|
159
160
|
return toInvokeDefinition({
|
|
160
|
-
src:
|
|
161
|
-
id:
|
|
161
|
+
src: invokeId,
|
|
162
|
+
id: invokeId
|
|
162
163
|
});
|
|
163
164
|
} else if (isString(invokeConfig.src)) {
|
|
165
|
+
var invokeId = invokeConfig.id || createInvokeId(_this.id, i);
|
|
164
166
|
return toInvokeDefinition(__assign(__assign({}, invokeConfig), {
|
|
165
|
-
id:
|
|
167
|
+
id: invokeId,
|
|
166
168
|
src: invokeConfig.src
|
|
167
169
|
}));
|
|
168
170
|
} else if (isMachine(invokeConfig.src) || isFunction(invokeConfig.src)) {
|
|
169
|
-
var
|
|
170
|
-
|
|
171
|
-
_this.machine.options.services = __assign((_b = {}, _b[invokeSrc] = invokeConfig.src, _b), _this.machine.options.services);
|
|
171
|
+
var invokeId = invokeConfig.id || createInvokeId(_this.id, i);
|
|
172
|
+
_this.machine.options.services = __assign((_b = {}, _b[invokeId] = invokeConfig.src, _b), _this.machine.options.services);
|
|
172
173
|
return toInvokeDefinition(__assign(__assign({
|
|
173
|
-
id:
|
|
174
|
+
id: invokeId
|
|
174
175
|
}, invokeConfig), {
|
|
175
|
-
src:
|
|
176
|
+
src: invokeId
|
|
176
177
|
}));
|
|
177
178
|
} else {
|
|
178
179
|
var invokeSource = invokeConfig.src;
|
|
179
180
|
return toInvokeDefinition(__assign(__assign({
|
|
180
|
-
id:
|
|
181
|
+
id: createInvokeId(_this.id, i)
|
|
181
182
|
}, invokeConfig), {
|
|
182
183
|
src: invokeSource
|
|
183
184
|
}));
|
|
@@ -436,9 +437,10 @@ function () {
|
|
|
436
437
|
|
|
437
438
|
|
|
438
439
|
StateNode.prototype.resolveState = function (state) {
|
|
439
|
-
var
|
|
440
|
-
|
|
441
|
-
|
|
440
|
+
var stateFromConfig = state instanceof State ? state : State.create(state);
|
|
441
|
+
var configuration = Array.from(getConfiguration([], this.getStateNodes(stateFromConfig.value)));
|
|
442
|
+
return new State(__assign(__assign({}, stateFromConfig), {
|
|
443
|
+
value: this.resolve(stateFromConfig.value),
|
|
442
444
|
configuration: configuration,
|
|
443
445
|
done: isInFinalState(configuration, this),
|
|
444
446
|
tags: getTagsFromConfiguration(configuration)
|
|
@@ -822,7 +824,7 @@ function () {
|
|
|
822
824
|
var prevConfig = getConfiguration([], this.getStateNodes(currentState.value));
|
|
823
825
|
var resolvedConfig = stateTransition.configuration.length ? getConfiguration(prevConfig, stateTransition.configuration) : prevConfig;
|
|
824
826
|
stateTransition.configuration = __spreadArray([], __read(resolvedConfig), false);
|
|
825
|
-
return this.resolveTransition(stateTransition, currentState, _event);
|
|
827
|
+
return this.resolveTransition(stateTransition, currentState, currentState.context, _event);
|
|
826
828
|
};
|
|
827
829
|
|
|
828
830
|
StateNode.prototype.resolveRaisedTransition = function (state, _event, originalEvent) {
|
|
@@ -840,7 +842,7 @@ function () {
|
|
|
840
842
|
return state;
|
|
841
843
|
};
|
|
842
844
|
|
|
843
|
-
StateNode.prototype.resolveTransition = function (stateTransition, currentState,
|
|
845
|
+
StateNode.prototype.resolveTransition = function (stateTransition, currentState, context, _event) {
|
|
844
846
|
var e_6, _a;
|
|
845
847
|
|
|
846
848
|
var _this = this;
|
|
@@ -849,10 +851,6 @@ function () {
|
|
|
849
851
|
_event = initEvent;
|
|
850
852
|
}
|
|
851
853
|
|
|
852
|
-
if (context === void 0) {
|
|
853
|
-
context = this.machine.context;
|
|
854
|
-
}
|
|
855
|
-
|
|
856
854
|
var configuration = stateTransition.configuration; // Transition will "apply" if:
|
|
857
855
|
// - this is the initial state (there is no current state)
|
|
858
856
|
// - OR there are transitions
|
|
@@ -860,8 +858,7 @@ function () {
|
|
|
860
858
|
var willTransition = !currentState || stateTransition.transitions.length > 0;
|
|
861
859
|
var resolvedStateValue = willTransition ? getValue(this.machine, configuration) : undefined;
|
|
862
860
|
var historyValue = currentState ? currentState.historyValue ? currentState.historyValue : stateTransition.source ? this.machine.historyValue(currentState.value) : undefined : undefined;
|
|
863
|
-
var
|
|
864
|
-
var actions = this.getActions(stateTransition, currentContext, _event, currentState);
|
|
861
|
+
var actions = this.getActions(stateTransition, context, _event, currentState);
|
|
865
862
|
var activities = currentState ? __assign({}, currentState.activities) : {};
|
|
866
863
|
|
|
867
864
|
try {
|
|
@@ -886,7 +883,7 @@ function () {
|
|
|
886
883
|
}
|
|
887
884
|
}
|
|
888
885
|
|
|
889
|
-
var _b = __read(resolveActions(this, currentState,
|
|
886
|
+
var _b = __read(resolveActions(this, currentState, context, _event, actions, this.machine.config.preserveActionOrder), 2),
|
|
890
887
|
resolvedActions = _b[0],
|
|
891
888
|
updatedContext = _b[1];
|
|
892
889
|
|
|
@@ -905,7 +902,7 @@ function () {
|
|
|
905
902
|
acc[action.activity.id] = createInvocableActor(action.activity, _this.machine, updatedContext, _event);
|
|
906
903
|
return acc;
|
|
907
904
|
}, currentState ? __assign({}, currentState.children) : {});
|
|
908
|
-
var resolvedConfiguration =
|
|
905
|
+
var resolvedConfiguration = willTransition ? stateTransition.configuration : currentState ? currentState.configuration : [];
|
|
909
906
|
var isDone = isInFinalState(resolvedConfiguration, this);
|
|
910
907
|
var nextState = new State({
|
|
911
908
|
value: resolvedStateValue || currentState.value,
|
|
@@ -925,7 +922,7 @@ function () {
|
|
|
925
922
|
tags: currentState === null || currentState === void 0 ? void 0 : currentState.tags,
|
|
926
923
|
machine: this
|
|
927
924
|
});
|
|
928
|
-
var didUpdateContext =
|
|
925
|
+
var didUpdateContext = context !== updatedContext;
|
|
929
926
|
nextState.changed = _event.name === update || didUpdateContext; // Dispose of penultimate histories to prevent memory leaks
|
|
930
927
|
|
|
931
928
|
var history = nextState.history;
|
|
@@ -1145,6 +1142,9 @@ function () {
|
|
|
1145
1142
|
});
|
|
1146
1143
|
|
|
1147
1144
|
StateNode.prototype.getInitialState = function (stateValue, context) {
|
|
1145
|
+
this._init(); // TODO: this should be in the constructor (see note in constructor)
|
|
1146
|
+
|
|
1147
|
+
|
|
1148
1148
|
var configuration = this.getStateNodes(stateValue);
|
|
1149
1149
|
return this.resolveTransition({
|
|
1150
1150
|
configuration: configuration,
|
|
@@ -1153,7 +1153,7 @@ function () {
|
|
|
1153
1153
|
transitions: [],
|
|
1154
1154
|
source: undefined,
|
|
1155
1155
|
actions: []
|
|
1156
|
-
}, undefined,
|
|
1156
|
+
}, undefined, context !== null && context !== void 0 ? context : this.machine.context, undefined);
|
|
1157
1157
|
};
|
|
1158
1158
|
|
|
1159
1159
|
Object.defineProperty(StateNode.prototype, "initialState", {
|
|
@@ -1162,9 +1162,6 @@ function () {
|
|
|
1162
1162
|
* entering the initial state.
|
|
1163
1163
|
*/
|
|
1164
1164
|
get: function () {
|
|
1165
|
-
this._init(); // TODO: this should be in the constructor (see note in constructor)
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
1165
|
var initialStateValue = this.initialStateValue;
|
|
1169
1166
|
|
|
1170
1167
|
if (!initialStateValue) {
|
package/es/actions.d.ts
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
import { Action, Event, EventObject, SingleOrArray, SendAction, SendActionOptions, CancelAction, ActionObject, ActionType, Assigner, PropertyAssigner, AssignAction, ActionFunction, ActionFunctionMap, ActivityActionObject, ActionTypes, ActivityDefinition, RaiseAction, RaiseActionObject, DoneEvent, ErrorPlatformEvent, DoneEventObject, SendExpr, SendActionObject, PureAction, LogExpr, LogAction, LogActionObject, DelayFunctionMap, SCXML, ExprWithMeta, ChooseCondition, ChooseAction, AnyEventObject, Expr, Cast } from './types';
|
|
1
|
+
import { Action, Event, EventObject, SingleOrArray, SendAction, SendActionOptions, CancelAction, ActionObject, ActionType, Assigner, PropertyAssigner, AssignAction, ActionFunction, ActionFunctionMap, ActivityActionObject, ActionTypes, ActivityDefinition, RaiseAction, RaiseActionObject, DoneEvent, ErrorPlatformEvent, DoneEventObject, SendExpr, SendActionObject, PureAction, LogExpr, LogAction, LogActionObject, DelayFunctionMap, SCXML, ExprWithMeta, ChooseCondition, ChooseAction, AnyEventObject, Expr, StopAction, StopActionObject, Cast, ActorRef, EventFrom } from './types';
|
|
2
2
|
import * as actionTypes from './actionTypes';
|
|
3
3
|
import { State } from './State';
|
|
4
4
|
import { StateNode } from './StateNode';
|
|
5
|
-
import { ActorRef, EventFrom, StopAction, StopActionObject } from '.';
|
|
6
5
|
export { actionTypes };
|
|
7
6
|
export declare const initEvent: SCXML.Event<{
|
|
8
7
|
type: ActionTypes;
|
|
9
8
|
}>;
|
|
10
9
|
export declare function getActionFunction<TContext, TEvent extends EventObject>(actionType: ActionType, actionFunctionMap?: ActionFunctionMap<TContext, TEvent>): ActionObject<TContext, TEvent> | ActionFunction<TContext, TEvent> | undefined;
|
|
11
10
|
export declare function toActionObject<TContext, TEvent extends EventObject>(action: Action<TContext, TEvent>, actionFunctionMap?: ActionFunctionMap<TContext, TEvent>): ActionObject<TContext, TEvent>;
|
|
12
|
-
export declare const toActionObjects: <TContext, TEvent extends EventObject>(action?: SingleOrArray<Action<TContext, TEvent>> | undefined, actionFunctionMap?: ActionFunctionMap<TContext, TEvent,
|
|
11
|
+
export declare const toActionObjects: <TContext, TEvent extends EventObject>(action?: SingleOrArray<Action<TContext, TEvent>> | undefined, actionFunctionMap?: ActionFunctionMap<TContext, TEvent, import("./types").BaseActionObject> | undefined) => ActionObject<TContext, TEvent>[];
|
|
13
12
|
export declare function toActivityDefinition<TContext, TEvent extends EventObject>(action: string | ActivityDefinition<TContext, TEvent>): ActivityDefinition<TContext, TEvent>;
|
|
14
13
|
/**
|
|
15
14
|
* Raises an event. This places the event in the internal event queue, so that
|
|
@@ -151,5 +150,5 @@ export declare function forwardTo<TContext, TEvent extends EventObject>(target:
|
|
|
151
150
|
*/
|
|
152
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>;
|
|
153
152
|
export declare function choose<TContext, TEvent extends EventObject>(conds: Array<ChooseCondition<TContext, TEvent>>): ChooseAction<TContext, TEvent>;
|
|
154
|
-
export declare function resolveActions<TContext, TEvent extends EventObject>(machine: StateNode<TContext, any, TEvent, any>, currentState: State<TContext, TEvent> | undefined, currentContext: TContext, _event: SCXML.Event<TEvent>, actions: Array<ActionObject<TContext, TEvent>>, preserveActionOrder?: boolean): [Array<ActionObject<TContext, TEvent>>, TContext];
|
|
153
|
+
export declare function resolveActions<TContext, TEvent extends EventObject>(machine: StateNode<TContext, any, TEvent, any, any, any>, currentState: State<TContext, TEvent> | undefined, currentContext: TContext, _event: SCXML.Event<TEvent>, actions: Array<ActionObject<TContext, TEvent>>, preserveActionOrder?: boolean): [Array<ActionObject<TContext, TEvent>>, TContext];
|
|
155
154
|
//# sourceMappingURL=actions.d.ts.map
|
package/es/actions.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { __assign, __read, __spreadArray } from './_virtual/_tslib.js';
|
|
2
2
|
import { IS_PRODUCTION } from './environment.js';
|
|
3
|
-
import {
|
|
3
|
+
import { toSCXMLEvent, isString, isFunction, toEventObject, getEventType, partition, updateContext, flatten, toArray, toGuard, evaluateGuard, warn, isArray } from './utils.js';
|
|
4
4
|
import { SpecialTargets, ActionTypes } from './types.js';
|
|
5
|
-
import { send as send$1,
|
|
5
|
+
import { send as send$1, raise as raise$1, update, log as log$1, cancel as cancel$1, assign as assign$1, error as error$1, stop as stop$1, pure as pure$1, choose as choose$1, init } from './actionTypes.js';
|
|
6
|
+
import * as actionTypes from './actionTypes.js';
|
|
7
|
+
export { actionTypes };
|
|
6
8
|
|
|
7
9
|
var initEvent = /*#__PURE__*/toSCXMLEvent({
|
|
8
10
|
type: init
|
|
@@ -152,6 +154,20 @@ function sendParent(event, options) {
|
|
|
152
154
|
to: SpecialTargets.Parent
|
|
153
155
|
}));
|
|
154
156
|
}
|
|
157
|
+
/**
|
|
158
|
+
* Sends an event to an actor.
|
|
159
|
+
*
|
|
160
|
+
* @param actor The `ActorRef` to send the event to.
|
|
161
|
+
* @param event The event to send, or an expression that evaluates to the event to send
|
|
162
|
+
* @param options Send action options
|
|
163
|
+
* @returns An XState send action object
|
|
164
|
+
*/
|
|
165
|
+
|
|
166
|
+
function sendTo(actor, event, options) {
|
|
167
|
+
return send(event, __assign(__assign({}, options), {
|
|
168
|
+
to: actor
|
|
169
|
+
}));
|
|
170
|
+
}
|
|
155
171
|
/**
|
|
156
172
|
* Sends an update event to this machine's parent.
|
|
157
173
|
*/
|
|
@@ -274,6 +290,9 @@ var assign = function (assignment) {
|
|
|
274
290
|
assignment: assignment
|
|
275
291
|
};
|
|
276
292
|
};
|
|
293
|
+
function isActionObject(action) {
|
|
294
|
+
return typeof action === 'object' && 'type' in action;
|
|
295
|
+
}
|
|
277
296
|
/**
|
|
278
297
|
* Returns an event type that represents an implicit event that
|
|
279
298
|
* is sent after the specified `delay`.
|
|
@@ -498,4 +517,4 @@ function resolveActions(machine, currentState, currentContext, _event, actions,
|
|
|
498
517
|
return [resolvedActions, updatedContext];
|
|
499
518
|
}
|
|
500
519
|
|
|
501
|
-
export { after, assign, cancel, choose, done, doneInvoke, error, escalate, forwardTo, getActionFunction, initEvent, log, pure, raise, resolveActions, resolveLog, resolveRaise, resolveSend, resolveStop, respond, send, sendParent, sendUpdate, start, stop, toActionObject, toActionObjects, toActivityDefinition };
|
|
520
|
+
export { after, assign, cancel, choose, done, doneInvoke, error, escalate, forwardTo, getActionFunction, initEvent, isActionObject, log, pure, raise, resolveActions, resolveLog, resolveRaise, resolveSend, resolveStop, respond, send, sendParent, sendTo, sendUpdate, start, stop, toActionObject, toActionObjects, toActivityDefinition };
|
package/es/behaviors.d.ts
CHANGED
package/es/devTools.d.ts
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import { Interpreter } from '.';
|
|
2
1
|
import { AnyInterpreter } from './types';
|
|
3
2
|
declare type ServiceListener = (service: AnyInterpreter) => void;
|
|
4
3
|
export interface XStateDevInterface {
|
|
5
|
-
register: (service:
|
|
6
|
-
unregister: (service:
|
|
4
|
+
register: (service: AnyInterpreter) => void;
|
|
5
|
+
unregister: (service: AnyInterpreter) => void;
|
|
7
6
|
onRegister: (listener: ServiceListener) => {
|
|
8
7
|
unsubscribe: () => void;
|
|
9
8
|
};
|
|
10
|
-
services: Set<
|
|
9
|
+
services: Set<AnyInterpreter>;
|
|
11
10
|
}
|
|
12
11
|
export declare function getGlobal(): typeof globalThis | undefined;
|
|
13
12
|
export declare function registerService(service: AnyInterpreter): void;
|
package/es/each.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EventObject, SingleOrArray, ActionObject } from '
|
|
1
|
+
import { EventObject, SingleOrArray, ActionObject } from './types';
|
|
2
2
|
export declare function each<TContext, TEvent extends EventObject>(collection: keyof TContext, item: keyof TContext, actions: SingleOrArray<ActionObject<TContext, TEvent>>): ActionObject<TContext, TEvent>;
|
|
3
3
|
export declare function each<TContext, TEvent extends EventObject>(collection: keyof TContext, item: keyof TContext, index: keyof TContext, actions: SingleOrArray<ActionObject<TContext, TEvent>>): ActionObject<TContext, TEvent>;
|
|
4
4
|
//# sourceMappingURL=each.d.ts.map
|
package/es/index.d.ts
CHANGED
|
@@ -4,28 +4,17 @@ import { StateNode } from './StateNode';
|
|
|
4
4
|
import { State } from './State';
|
|
5
5
|
import { Machine, createMachine } from './Machine';
|
|
6
6
|
import { Actor } from './Actor';
|
|
7
|
-
import
|
|
7
|
+
import * as actions from './actions';
|
|
8
8
|
import { interpret, Interpreter, spawn, InterpreterStatus } from './interpreter';
|
|
9
9
|
import { matchState } from './match';
|
|
10
|
-
import { createSchema } from './schema';
|
|
11
|
-
declare const actions:
|
|
12
|
-
|
|
13
|
-
send: typeof send;
|
|
14
|
-
sendParent: typeof sendParent;
|
|
15
|
-
sendUpdate: typeof sendUpdate;
|
|
16
|
-
log: typeof log;
|
|
17
|
-
cancel: (sendId: string | number) => import("./types").CancelAction;
|
|
18
|
-
start: typeof start;
|
|
19
|
-
stop: typeof stop;
|
|
20
|
-
assign: <TContext, TEvent extends import("./types").EventObject = import("./types").EventObject>(assignment: import("./types").Assigner<TContext, TEvent> | import("./types").PropertyAssigner<TContext, TEvent>) => import("./types").AssignAction<TContext, TEvent>;
|
|
21
|
-
after: typeof after;
|
|
22
|
-
done: typeof done;
|
|
23
|
-
respond: typeof respond;
|
|
24
|
-
forwardTo: typeof forwardTo;
|
|
25
|
-
escalate: typeof escalate;
|
|
26
|
-
choose: typeof choose;
|
|
27
|
-
pure: typeof pure;
|
|
28
|
-
};
|
|
29
|
-
export { Actor, Machine, StateNode, State, matchesState, mapState, actions, assign, send, sendParent, sendUpdate, forwardTo, interpret, Interpreter, InterpreterStatus, matchState, spawn, doneInvoke, createMachine, createSchema };
|
|
10
|
+
import { createSchema, t } from './schema';
|
|
11
|
+
declare const assign: <TContext, TEvent extends import("./types").EventObject = import("./types").EventObject>(assignment: import("./types").Assigner<TContext, TEvent> | import("./types").PropertyAssigner<TContext, TEvent>) => import("./types").AssignAction<TContext, TEvent>, send: typeof actions.send, sendParent: typeof actions.sendParent, sendUpdate: typeof actions.sendUpdate, forwardTo: typeof actions.forwardTo, doneInvoke: typeof actions.doneInvoke;
|
|
12
|
+
export { Actor, Machine, StateNode, State, matchesState, mapState, actions, assign, send, sendParent, sendUpdate, forwardTo, interpret, Interpreter, InterpreterStatus, matchState, spawn, doneInvoke, createMachine, createSchema, t };
|
|
30
13
|
export * from './types';
|
|
14
|
+
export * from './typegenTypes';
|
|
15
|
+
declare global {
|
|
16
|
+
interface SymbolConstructor {
|
|
17
|
+
readonly observable: symbol;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
31
20
|
//# sourceMappingURL=index.d.ts.map
|
package/es/index.js
CHANGED
|
@@ -1,32 +1,21 @@
|
|
|
1
1
|
export { matchesState } from './utils.js';
|
|
2
2
|
export { mapState } from './mapState.js';
|
|
3
3
|
export { ActionTypes, SpecialTargets } from './types.js';
|
|
4
|
-
import {
|
|
5
|
-
|
|
4
|
+
import { assign as assign$1, send as send$1, sendParent as sendParent$1, sendUpdate as sendUpdate$1, forwardTo as forwardTo$1, doneInvoke as doneInvoke$1 } from './actions.js';
|
|
5
|
+
import * as actions from './actions.js';
|
|
6
|
+
export { actions };
|
|
6
7
|
export { State } from './State.js';
|
|
7
8
|
export { StateNode } from './StateNode.js';
|
|
8
9
|
export { Machine, createMachine } from './Machine.js';
|
|
9
10
|
export { Interpreter, InterpreterStatus, interpret, spawn } from './interpreter.js';
|
|
10
11
|
export { matchState } from './match.js';
|
|
11
|
-
export { createSchema } from './schema.js';
|
|
12
|
+
export { createSchema, t } from './schema.js';
|
|
12
13
|
|
|
13
|
-
var
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
cancel: cancel,
|
|
20
|
-
start: start,
|
|
21
|
-
stop: stop,
|
|
22
|
-
assign: assign,
|
|
23
|
-
after: after,
|
|
24
|
-
done: done,
|
|
25
|
-
respond: respond,
|
|
26
|
-
forwardTo: forwardTo,
|
|
27
|
-
escalate: escalate,
|
|
28
|
-
choose: choose,
|
|
29
|
-
pure: pure
|
|
30
|
-
};
|
|
14
|
+
var assign = assign$1,
|
|
15
|
+
send = send$1,
|
|
16
|
+
sendParent = sendParent$1,
|
|
17
|
+
sendUpdate = sendUpdate$1,
|
|
18
|
+
forwardTo = forwardTo$1,
|
|
19
|
+
doneInvoke = doneInvoke$1;
|
|
31
20
|
|
|
32
|
-
export {
|
|
21
|
+
export { assign, doneInvoke, forwardTo, send, sendParent, sendUpdate };
|
package/es/interpreter.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { StateMachine, Event, EventObject, DefaultContext, StateSchema, StateValue, InterpreterOptions, SingleOrArray, Subscribable, DoneEvent, MachineOptions, SCXML, EventData, Observer, Spawnable, Typestate, ActorRef, ActorRefFrom, Behavior, Subscription } from './types';
|
|
2
2
|
import { State } from './State';
|
|
3
|
+
import { StateConfig } from '.';
|
|
4
|
+
import { AreAllImplementationsAssumedToBeProvided, TypegenDisabled } from './typegenTypes';
|
|
3
5
|
export declare type StateListener<TContext, TEvent extends EventObject, TStateSchema extends StateSchema<TContext> = any, TTypestate extends Typestate<TContext> = {
|
|
4
6
|
value: any;
|
|
5
7
|
context: TContext;
|
|
6
|
-
}> = (state: State<TContext, TEvent, TStateSchema, TTypestate>, event: TEvent) => void;
|
|
8
|
+
}, TResolvedTypesMeta = TypegenDisabled> = (state: State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>, event: TEvent) => void;
|
|
7
9
|
export declare type ContextListener<TContext = DefaultContext> = (context: TContext, prevContext: TContext | undefined) => void;
|
|
8
10
|
export declare type EventListener<TEvent extends EventObject = EventObject> = (event: TEvent) => void;
|
|
9
11
|
export declare type Listener = () => void;
|
|
@@ -21,23 +23,24 @@ export declare enum InterpreterStatus {
|
|
|
21
23
|
Running = 1,
|
|
22
24
|
Stopped = 2
|
|
23
25
|
}
|
|
24
|
-
declare global {
|
|
25
|
-
interface SymbolConstructor {
|
|
26
|
-
readonly observable: symbol;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
26
|
export declare class Interpreter<TContext, TStateSchema extends StateSchema = any, TEvent extends EventObject = EventObject, TTypestate extends Typestate<TContext> = {
|
|
30
27
|
value: any;
|
|
31
28
|
context: TContext;
|
|
32
|
-
}> implements ActorRef<TEvent, State<TContext, TEvent, TStateSchema, TTypestate>> {
|
|
33
|
-
machine: StateMachine<TContext, TStateSchema, TEvent, TTypestate>;
|
|
29
|
+
}, TResolvedTypesMeta = TypegenDisabled> implements ActorRef<TEvent, State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>> {
|
|
30
|
+
machine: StateMachine<TContext, TStateSchema, TEvent, TTypestate, any, any, TResolvedTypesMeta>;
|
|
34
31
|
/**
|
|
35
32
|
* The default interpreter options:
|
|
36
33
|
*
|
|
37
34
|
* - `clock` uses the global `setTimeout` and `clearTimeout` functions
|
|
38
35
|
* - `logger` uses the global `console.log()` method
|
|
39
36
|
*/
|
|
40
|
-
static defaultOptions:
|
|
37
|
+
static defaultOptions: {
|
|
38
|
+
execute: boolean;
|
|
39
|
+
deferEvents: boolean;
|
|
40
|
+
clock: Clock;
|
|
41
|
+
logger: any;
|
|
42
|
+
devTools: boolean;
|
|
43
|
+
};
|
|
41
44
|
/**
|
|
42
45
|
* The current state of the interpreted machine.
|
|
43
46
|
*/
|
|
@@ -77,9 +80,9 @@ export declare class Interpreter<TContext, TStateSchema extends StateSchema = an
|
|
|
77
80
|
* @param machine The machine to be interpreted
|
|
78
81
|
* @param options Interpreter options
|
|
79
82
|
*/
|
|
80
|
-
constructor(machine: StateMachine<TContext, TStateSchema, TEvent, TTypestate>, options?:
|
|
81
|
-
get initialState(): State<TContext, TEvent, TStateSchema, TTypestate>;
|
|
82
|
-
get state(): State<TContext, TEvent, TStateSchema, TTypestate>;
|
|
83
|
+
constructor(machine: StateMachine<TContext, TStateSchema, TEvent, TTypestate, any, any, TResolvedTypesMeta>, options?: InterpreterOptions);
|
|
84
|
+
get initialState(): State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>;
|
|
85
|
+
get state(): State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>;
|
|
83
86
|
static interpret: typeof interpret;
|
|
84
87
|
/**
|
|
85
88
|
* Executes the actions of the given state, with that state's `context` and `event`.
|
|
@@ -87,56 +90,56 @@ export declare class Interpreter<TContext, TStateSchema extends StateSchema = an
|
|
|
87
90
|
* @param state The state whose actions will be executed
|
|
88
91
|
* @param actionsConfig The action implementations to use
|
|
89
92
|
*/
|
|
90
|
-
execute(state: State<TContext, TEvent, TStateSchema, TTypestate>, actionsConfig?: MachineOptions<TContext, TEvent>['actions']): void;
|
|
93
|
+
execute(state: State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>, actionsConfig?: MachineOptions<TContext, TEvent>['actions']): void;
|
|
91
94
|
private update;
|
|
92
|
-
onTransition(listener: StateListener<TContext, TEvent, TStateSchema, TTypestate>): this;
|
|
93
|
-
subscribe(nextListener?: (state: State<TContext, TEvent, any, TTypestate>) => void, errorListener?: (error: any) => void, completeListener?: () => void): Subscription;
|
|
94
|
-
subscribe(observer: Observer<State<TContext, TEvent, any, TTypestate>>): Subscription;
|
|
95
|
+
onTransition(listener: StateListener<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>): this;
|
|
96
|
+
subscribe(nextListener?: (state: State<TContext, TEvent, any, TTypestate, TResolvedTypesMeta>) => void, errorListener?: (error: any) => void, completeListener?: () => void): Subscription;
|
|
97
|
+
subscribe(observer: Observer<State<TContext, TEvent, any, TTypestate, TResolvedTypesMeta>>): Subscription;
|
|
95
98
|
/**
|
|
96
99
|
* Adds an event listener that is notified whenever an event is sent to the running interpreter.
|
|
97
100
|
* @param listener The event listener
|
|
98
101
|
*/
|
|
99
|
-
onEvent(listener: EventListener):
|
|
102
|
+
onEvent(listener: EventListener): this;
|
|
100
103
|
/**
|
|
101
104
|
* Adds an event listener that is notified whenever a `send` event occurs.
|
|
102
105
|
* @param listener The event listener
|
|
103
106
|
*/
|
|
104
|
-
onSend(listener: EventListener):
|
|
107
|
+
onSend(listener: EventListener): this;
|
|
105
108
|
/**
|
|
106
109
|
* Adds a context listener that is notified whenever the state context changes.
|
|
107
110
|
* @param listener The context listener
|
|
108
111
|
*/
|
|
109
|
-
onChange(listener: ContextListener<TContext>):
|
|
112
|
+
onChange(listener: ContextListener<TContext>): this;
|
|
110
113
|
/**
|
|
111
114
|
* Adds a listener that is notified when the machine is stopped.
|
|
112
115
|
* @param listener The listener
|
|
113
116
|
*/
|
|
114
|
-
onStop(listener: Listener):
|
|
117
|
+
onStop(listener: Listener): this;
|
|
115
118
|
/**
|
|
116
119
|
* Adds a state listener that is notified when the statechart has reached its final state.
|
|
117
120
|
* @param listener The state listener
|
|
118
121
|
*/
|
|
119
|
-
onDone(listener: EventListener<DoneEvent>):
|
|
122
|
+
onDone(listener: EventListener<DoneEvent>): this;
|
|
120
123
|
/**
|
|
121
124
|
* Removes a listener.
|
|
122
125
|
* @param listener The listener to remove
|
|
123
126
|
*/
|
|
124
|
-
off(listener: (...args: any[]) => void):
|
|
127
|
+
off(listener: (...args: any[]) => void): this;
|
|
125
128
|
/**
|
|
126
129
|
* Alias for Interpreter.prototype.start
|
|
127
130
|
*/
|
|
128
|
-
init: (initialState?: StateValue | State<TContext, TEvent, TStateSchema, TTypestate> |
|
|
131
|
+
init: (initialState?: StateValue | State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta> | StateConfig<TContext, TEvent> | undefined) => this;
|
|
129
132
|
/**
|
|
130
133
|
* Starts the interpreter from the given state, or the initial state.
|
|
131
134
|
* @param initialState The state to start the statechart from
|
|
132
135
|
*/
|
|
133
|
-
start(initialState?: State<TContext, TEvent, TStateSchema, TTypestate> |
|
|
136
|
+
start(initialState?: State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta> | StateConfig<TContext, TEvent> | StateValue): this;
|
|
134
137
|
/**
|
|
135
138
|
* Stops the interpreter and unsubscribe all listeners.
|
|
136
139
|
*
|
|
137
140
|
* This will also notify the `onStop` listeners.
|
|
138
141
|
*/
|
|
139
|
-
stop():
|
|
142
|
+
stop(): this;
|
|
140
143
|
/**
|
|
141
144
|
* Sends an event to the running interpreter to trigger a transition.
|
|
142
145
|
*
|
|
@@ -146,7 +149,7 @@ export declare class Interpreter<TContext, TStateSchema extends StateSchema = an
|
|
|
146
149
|
*
|
|
147
150
|
* @param event The event(s) to send
|
|
148
151
|
*/
|
|
149
|
-
send: (event: SingleOrArray<Event<TEvent>> | SCXML.Event<TEvent>, payload?: EventData | undefined) => State<TContext, TEvent, TStateSchema, TTypestate>;
|
|
152
|
+
send: (event: SingleOrArray<Event<TEvent>> | SCXML.Event<TEvent>, payload?: EventData | undefined) => State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>;
|
|
150
153
|
private batch;
|
|
151
154
|
/**
|
|
152
155
|
* Returns a send function bound to this interpreter instance.
|
|
@@ -162,7 +165,7 @@ export declare class Interpreter<TContext, TStateSchema extends StateSchema = an
|
|
|
162
165
|
*
|
|
163
166
|
* @param event The event to determine the next state
|
|
164
167
|
*/
|
|
165
|
-
nextState(event: Event<TEvent> | SCXML.Event<TEvent>): State<TContext, TEvent, TStateSchema, TTypestate>;
|
|
168
|
+
nextState(event: Event<TEvent> | SCXML.Event<TEvent>): State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>;
|
|
166
169
|
private forward;
|
|
167
170
|
private defer;
|
|
168
171
|
private cancel;
|
|
@@ -186,11 +189,11 @@ export declare class Interpreter<TContext, TStateSchema extends StateSchema = an
|
|
|
186
189
|
toJSON(): {
|
|
187
190
|
id: string;
|
|
188
191
|
};
|
|
189
|
-
[Symbol.observable](): Subscribable<State<TContext, TEvent, TStateSchema, TTypestate>>;
|
|
190
|
-
getSnapshot(): State<TContext, TEvent, TStateSchema, TTypestate>;
|
|
192
|
+
[Symbol.observable](): Subscribable<State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>>;
|
|
193
|
+
getSnapshot(): State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>;
|
|
191
194
|
}
|
|
192
195
|
export declare function spawn<T extends Behavior<any, any>>(entity: T, nameOrOptions?: string | SpawnOptions): ActorRefFrom<T>;
|
|
193
|
-
export declare function spawn<TC, TE extends EventObject>(entity: StateMachine<TC, any, TE>, nameOrOptions?: string | SpawnOptions): ActorRefFrom<StateMachine<TC, any, TE>>;
|
|
196
|
+
export declare function spawn<TC, TE extends EventObject>(entity: StateMachine<TC, any, TE, any, any, any, any>, nameOrOptions?: string | SpawnOptions): ActorRefFrom<StateMachine<TC, any, TE, any, any, any, any>>;
|
|
194
197
|
export declare function spawn(entity: Spawnable, nameOrOptions?: string | SpawnOptions): ActorRef<any>;
|
|
195
198
|
/**
|
|
196
199
|
* Creates a new Interpreter instance for the given machine with the provided options, if any.
|
|
@@ -201,6 +204,6 @@ export declare function spawn(entity: Spawnable, nameOrOptions?: string | SpawnO
|
|
|
201
204
|
export declare function interpret<TContext = DefaultContext, TStateSchema extends StateSchema = any, TEvent extends EventObject = EventObject, TTypestate extends Typestate<TContext> = {
|
|
202
205
|
value: any;
|
|
203
206
|
context: TContext;
|
|
204
|
-
}>(machine: StateMachine<TContext, TStateSchema, TEvent, TTypestate
|
|
207
|
+
}, TResolvedTypesMeta = TypegenDisabled>(machine: AreAllImplementationsAssumedToBeProvided<TResolvedTypesMeta> extends true ? StateMachine<TContext, TStateSchema, TEvent, TTypestate, any, any, TResolvedTypesMeta> : 'Some implementations missing', options?: InterpreterOptions): Interpreter<TContext, TStateSchema, TEvent, TTypestate, TResolvedTypesMeta>;
|
|
205
208
|
export {};
|
|
206
209
|
//# sourceMappingURL=interpreter.d.ts.map
|