xstate 4.28.1 → 4.30.2
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 +218 -91
- 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 +2 -3
- package/es/Actor.js +15 -6
- package/es/Machine.d.ts +5 -4
- package/es/State.d.ts +19 -15
- package/es/State.js +4 -9
- package/es/StateNode.d.ts +22 -17
- package/es/StateNode.js +14 -13
- package/es/actions.d.ts +3 -4
- package/es/actions.js +8 -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 +6 -23
- package/es/index.js +12 -23
- package/es/interpreter.d.ts +35 -27
- package/es/interpreter.js +31 -21
- 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 +128 -64
- package/es/utils.d.ts +5 -5
- package/es/utils.js +5 -2
- package/lib/Actor.d.ts +2 -3
- package/lib/Actor.js +14 -5
- package/lib/Machine.d.ts +5 -4
- package/lib/State.d.ts +19 -15
- package/lib/State.js +4 -9
- package/lib/StateNode.d.ts +22 -17
- package/lib/StateNode.js +14 -13
- package/lib/actions.d.ts +3 -4
- package/lib/actions.js +5 -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 +6 -23
- package/lib/index.js +17 -27
- package/lib/interpreter.d.ts +35 -27
- package/lib/interpreter.js +29 -19
- 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 +128 -64
- package/lib/utils.d.ts +5 -5
- package/lib/utils.js +5 -2
- package/package.json +5 -5
package/es/StateNode.js
CHANGED
|
@@ -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;
|
|
@@ -437,9 +437,10 @@ function () {
|
|
|
437
437
|
|
|
438
438
|
|
|
439
439
|
StateNode.prototype.resolveState = function (state) {
|
|
440
|
-
var
|
|
441
|
-
|
|
442
|
-
|
|
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),
|
|
443
444
|
configuration: configuration,
|
|
444
445
|
done: isInFinalState(configuration, this),
|
|
445
446
|
tags: getTagsFromConfiguration(configuration)
|
|
@@ -1141,6 +1142,9 @@ function () {
|
|
|
1141
1142
|
});
|
|
1142
1143
|
|
|
1143
1144
|
StateNode.prototype.getInitialState = function (stateValue, context) {
|
|
1145
|
+
this._init(); // TODO: this should be in the constructor (see note in constructor)
|
|
1146
|
+
|
|
1147
|
+
|
|
1144
1148
|
var configuration = this.getStateNodes(stateValue);
|
|
1145
1149
|
return this.resolveTransition({
|
|
1146
1150
|
configuration: configuration,
|
|
@@ -1158,9 +1162,6 @@ function () {
|
|
|
1158
1162
|
* entering the initial state.
|
|
1159
1163
|
*/
|
|
1160
1164
|
get: function () {
|
|
1161
|
-
this._init(); // TODO: this should be in the constructor (see note in constructor)
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
1165
|
var initialStateValue = this.initialStateValue;
|
|
1165
1166
|
|
|
1166
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
|
|
@@ -288,6 +290,9 @@ var assign = function (assignment) {
|
|
|
288
290
|
assignment: assignment
|
|
289
291
|
};
|
|
290
292
|
};
|
|
293
|
+
function isActionObject(action) {
|
|
294
|
+
return typeof action === 'object' && 'type' in action;
|
|
295
|
+
}
|
|
291
296
|
/**
|
|
292
297
|
* Returns an event type that represents an implicit event that
|
|
293
298
|
* is sent after the specified `delay`.
|
|
@@ -512,4 +517,4 @@ function resolveActions(machine, currentState, currentContext, _event, actions,
|
|
|
512
517
|
return [resolvedActions, updatedContext];
|
|
513
518
|
}
|
|
514
519
|
|
|
515
|
-
export { after, assign, cancel, choose, done, doneInvoke, error, escalate, forwardTo, getActionFunction, initEvent, log, pure, raise, resolveActions, resolveLog, resolveRaise, resolveSend, resolveStop, respond, send, sendParent, sendTo, 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
|
@@ -3,32 +3,15 @@ import { mapState } from './mapState';
|
|
|
3
3
|
import { StateNode } from './StateNode';
|
|
4
4
|
import { State } from './State';
|
|
5
5
|
import { Machine, createMachine } from './Machine';
|
|
6
|
-
import { Actor } from './Actor';
|
|
7
|
-
import
|
|
6
|
+
import { Actor, toActorRef } from './Actor';
|
|
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
|
-
sendTo: typeof sendTo;
|
|
16
|
-
sendUpdate: typeof sendUpdate;
|
|
17
|
-
log: typeof log;
|
|
18
|
-
cancel: (sendId: string | number) => import("./types").CancelAction;
|
|
19
|
-
start: typeof start;
|
|
20
|
-
stop: typeof stop;
|
|
21
|
-
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>;
|
|
22
|
-
after: typeof after;
|
|
23
|
-
done: typeof done;
|
|
24
|
-
respond: typeof respond;
|
|
25
|
-
forwardTo: typeof forwardTo;
|
|
26
|
-
escalate: typeof escalate;
|
|
27
|
-
choose: typeof choose;
|
|
28
|
-
pure: typeof pure;
|
|
29
|
-
};
|
|
30
|
-
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, toActorRef, Machine, StateNode, State, matchesState, mapState, actions, assign, send, sendParent, sendUpdate, forwardTo, interpret, Interpreter, InterpreterStatus, matchState, spawn, doneInvoke, createMachine, createSchema, t };
|
|
31
13
|
export * from './types';
|
|
14
|
+
export * from './typegenTypes';
|
|
32
15
|
declare global {
|
|
33
16
|
interface SymbolConstructor {
|
|
34
17
|
readonly observable: symbol;
|
package/es/index.js
CHANGED
|
@@ -1,33 +1,22 @@
|
|
|
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';
|
|
8
|
+
export { toActorRef } from './Actor.js';
|
|
7
9
|
export { StateNode } from './StateNode.js';
|
|
8
10
|
export { Machine, createMachine } from './Machine.js';
|
|
9
11
|
export { Interpreter, InterpreterStatus, interpret, spawn } from './interpreter.js';
|
|
10
12
|
export { matchState } from './match.js';
|
|
11
|
-
export { createSchema } from './schema.js';
|
|
13
|
+
export { createSchema, t } from './schema.js';
|
|
12
14
|
|
|
13
|
-
var
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
log: log,
|
|
20
|
-
cancel: cancel,
|
|
21
|
-
start: start,
|
|
22
|
-
stop: stop,
|
|
23
|
-
assign: assign,
|
|
24
|
-
after: after,
|
|
25
|
-
done: done,
|
|
26
|
-
respond: respond,
|
|
27
|
-
forwardTo: forwardTo,
|
|
28
|
-
escalate: escalate,
|
|
29
|
-
choose: choose,
|
|
30
|
-
pure: pure
|
|
31
|
-
};
|
|
15
|
+
var assign = assign$1,
|
|
16
|
+
send = send$1,
|
|
17
|
+
sendParent = sendParent$1,
|
|
18
|
+
sendUpdate = sendUpdate$1,
|
|
19
|
+
forwardTo = forwardTo$1,
|
|
20
|
+
doneInvoke = doneInvoke$1;
|
|
32
21
|
|
|
33
|
-
export {
|
|
22
|
+
export { assign, doneInvoke, forwardTo, send, sendParent, sendUpdate };
|
package/es/interpreter.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { StateMachine, Event, EventObject, DefaultContext, StateSchema, StateValue, InterpreterOptions, SingleOrArray,
|
|
1
|
+
import { StateMachine, Event, EventObject, DefaultContext, StateSchema, StateValue, InterpreterOptions, SingleOrArray, DoneEvent, MachineOptions, SCXML, EventData, Observer, Spawnable, Typestate, ActorRef, ActorRefFrom, Behavior, Subscription, StateConfig, InteropSubscribable } from './types';
|
|
2
2
|
import { State } from './State';
|
|
3
|
+
import { symbolObservable } from './utils';
|
|
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;
|
|
@@ -24,15 +26,21 @@ export declare enum InterpreterStatus {
|
|
|
24
26
|
export declare class Interpreter<TContext, TStateSchema extends StateSchema = any, TEvent extends EventObject = EventObject, TTypestate extends Typestate<TContext> = {
|
|
25
27
|
value: any;
|
|
26
28
|
context: TContext;
|
|
27
|
-
}> implements ActorRef<TEvent, State<TContext, TEvent, TStateSchema, TTypestate>> {
|
|
28
|
-
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>;
|
|
29
31
|
/**
|
|
30
32
|
* The default interpreter options:
|
|
31
33
|
*
|
|
32
34
|
* - `clock` uses the global `setTimeout` and `clearTimeout` functions
|
|
33
35
|
* - `logger` uses the global `console.log()` method
|
|
34
36
|
*/
|
|
35
|
-
static defaultOptions:
|
|
37
|
+
static defaultOptions: {
|
|
38
|
+
execute: boolean;
|
|
39
|
+
deferEvents: boolean;
|
|
40
|
+
clock: Clock;
|
|
41
|
+
logger: any;
|
|
42
|
+
devTools: boolean;
|
|
43
|
+
};
|
|
36
44
|
/**
|
|
37
45
|
* The current state of the interpreted machine.
|
|
38
46
|
*/
|
|
@@ -72,9 +80,9 @@ export declare class Interpreter<TContext, TStateSchema extends StateSchema = an
|
|
|
72
80
|
* @param machine The machine to be interpreted
|
|
73
81
|
* @param options Interpreter options
|
|
74
82
|
*/
|
|
75
|
-
constructor(machine: StateMachine<TContext, TStateSchema, TEvent, TTypestate>, options?:
|
|
76
|
-
get initialState(): State<TContext, TEvent, TStateSchema, TTypestate>;
|
|
77
|
-
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>;
|
|
78
86
|
static interpret: typeof interpret;
|
|
79
87
|
/**
|
|
80
88
|
* Executes the actions of the given state, with that state's `context` and `event`.
|
|
@@ -82,56 +90,56 @@ export declare class Interpreter<TContext, TStateSchema extends StateSchema = an
|
|
|
82
90
|
* @param state The state whose actions will be executed
|
|
83
91
|
* @param actionsConfig The action implementations to use
|
|
84
92
|
*/
|
|
85
|
-
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;
|
|
86
94
|
private update;
|
|
87
|
-
onTransition(listener: StateListener<TContext, TEvent, TStateSchema, TTypestate>): this;
|
|
88
|
-
subscribe(
|
|
89
|
-
subscribe(
|
|
95
|
+
onTransition(listener: StateListener<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>): this;
|
|
96
|
+
subscribe(observer: Observer<State<TContext, TEvent, any, TTypestate, TResolvedTypesMeta>>): Subscription;
|
|
97
|
+
subscribe(nextListener?: (state: State<TContext, TEvent, any, TTypestate, TResolvedTypesMeta>) => void, errorListener?: (error: any) => void, completeListener?: () => void): Subscription;
|
|
90
98
|
/**
|
|
91
99
|
* Adds an event listener that is notified whenever an event is sent to the running interpreter.
|
|
92
100
|
* @param listener The event listener
|
|
93
101
|
*/
|
|
94
|
-
onEvent(listener: EventListener):
|
|
102
|
+
onEvent(listener: EventListener): this;
|
|
95
103
|
/**
|
|
96
104
|
* Adds an event listener that is notified whenever a `send` event occurs.
|
|
97
105
|
* @param listener The event listener
|
|
98
106
|
*/
|
|
99
|
-
onSend(listener: EventListener):
|
|
107
|
+
onSend(listener: EventListener): this;
|
|
100
108
|
/**
|
|
101
109
|
* Adds a context listener that is notified whenever the state context changes.
|
|
102
110
|
* @param listener The context listener
|
|
103
111
|
*/
|
|
104
|
-
onChange(listener: ContextListener<TContext>):
|
|
112
|
+
onChange(listener: ContextListener<TContext>): this;
|
|
105
113
|
/**
|
|
106
114
|
* Adds a listener that is notified when the machine is stopped.
|
|
107
115
|
* @param listener The listener
|
|
108
116
|
*/
|
|
109
|
-
onStop(listener: Listener):
|
|
117
|
+
onStop(listener: Listener): this;
|
|
110
118
|
/**
|
|
111
119
|
* Adds a state listener that is notified when the statechart has reached its final state.
|
|
112
120
|
* @param listener The state listener
|
|
113
121
|
*/
|
|
114
|
-
onDone(listener: EventListener<DoneEvent>):
|
|
122
|
+
onDone(listener: EventListener<DoneEvent>): this;
|
|
115
123
|
/**
|
|
116
124
|
* Removes a listener.
|
|
117
125
|
* @param listener The listener to remove
|
|
118
126
|
*/
|
|
119
|
-
off(listener: (...args: any[]) => void):
|
|
127
|
+
off(listener: (...args: any[]) => void): this;
|
|
120
128
|
/**
|
|
121
129
|
* Alias for Interpreter.prototype.start
|
|
122
130
|
*/
|
|
123
|
-
init: (initialState?: StateValue | State<TContext, TEvent, TStateSchema, TTypestate> |
|
|
131
|
+
init: (initialState?: StateValue | State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta> | StateConfig<TContext, TEvent> | undefined) => this;
|
|
124
132
|
/**
|
|
125
133
|
* Starts the interpreter from the given state, or the initial state.
|
|
126
134
|
* @param initialState The state to start the statechart from
|
|
127
135
|
*/
|
|
128
|
-
start(initialState?: State<TContext, TEvent, TStateSchema, TTypestate> |
|
|
136
|
+
start(initialState?: State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta> | StateConfig<TContext, TEvent> | StateValue): this;
|
|
129
137
|
/**
|
|
130
138
|
* Stops the interpreter and unsubscribe all listeners.
|
|
131
139
|
*
|
|
132
140
|
* This will also notify the `onStop` listeners.
|
|
133
141
|
*/
|
|
134
|
-
stop():
|
|
142
|
+
stop(): this;
|
|
135
143
|
/**
|
|
136
144
|
* Sends an event to the running interpreter to trigger a transition.
|
|
137
145
|
*
|
|
@@ -141,7 +149,7 @@ export declare class Interpreter<TContext, TStateSchema extends StateSchema = an
|
|
|
141
149
|
*
|
|
142
150
|
* @param event The event(s) to send
|
|
143
151
|
*/
|
|
144
|
-
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>;
|
|
145
153
|
private batch;
|
|
146
154
|
/**
|
|
147
155
|
* Returns a send function bound to this interpreter instance.
|
|
@@ -157,7 +165,7 @@ export declare class Interpreter<TContext, TStateSchema extends StateSchema = an
|
|
|
157
165
|
*
|
|
158
166
|
* @param event The event to determine the next state
|
|
159
167
|
*/
|
|
160
|
-
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>;
|
|
161
169
|
private forward;
|
|
162
170
|
private defer;
|
|
163
171
|
private cancel;
|
|
@@ -181,11 +189,11 @@ export declare class Interpreter<TContext, TStateSchema extends StateSchema = an
|
|
|
181
189
|
toJSON(): {
|
|
182
190
|
id: string;
|
|
183
191
|
};
|
|
184
|
-
[
|
|
185
|
-
getSnapshot(): State<TContext, TEvent, TStateSchema, TTypestate>;
|
|
192
|
+
[symbolObservable](): InteropSubscribable<State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>>;
|
|
193
|
+
getSnapshot(): State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>;
|
|
186
194
|
}
|
|
187
195
|
export declare function spawn<T extends Behavior<any, any>>(entity: T, nameOrOptions?: string | SpawnOptions): ActorRefFrom<T>;
|
|
188
|
-
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>>;
|
|
189
197
|
export declare function spawn(entity: Spawnable, nameOrOptions?: string | SpawnOptions): ActorRef<any>;
|
|
190
198
|
/**
|
|
191
199
|
* Creates a new Interpreter instance for the given machine with the provided options, if any.
|
|
@@ -196,6 +204,6 @@ export declare function spawn(entity: Spawnable, nameOrOptions?: string | SpawnO
|
|
|
196
204
|
export declare function interpret<TContext = DefaultContext, TStateSchema extends StateSchema = any, TEvent extends EventObject = EventObject, TTypestate extends Typestate<TContext> = {
|
|
197
205
|
value: any;
|
|
198
206
|
context: TContext;
|
|
199
|
-
}>(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>;
|
|
200
208
|
export {};
|
|
201
209
|
//# sourceMappingURL=interpreter.d.ts.map
|
package/es/interpreter.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { __values, __spreadArray, __read, __assign } from './_virtual/_tslib.js';
|
|
2
2
|
import { IS_PRODUCTION } from './environment.js';
|
|
3
|
-
import { warn, mapContext, isFunction, keys, toSCXMLEvent, toInvokeSource, isMachine, isPromiseLike, isObservable, isBehavior, reportUnhandledExceptionOnInvocation,
|
|
3
|
+
import { warn, mapContext, isFunction, keys, toSCXMLEvent, toInvokeSource, isMachine, isPromiseLike, isObservable, isBehavior, reportUnhandledExceptionOnInvocation, symbolObservable, isArray, toEventObject, isString, isActor, uniqueId, toObserver } from './utils.js';
|
|
4
4
|
import { ActionTypes, SpecialTargets } from './types.js';
|
|
5
5
|
import { isInFinalState } from './stateUtils.js';
|
|
6
6
|
import { errorPlatform, log, stop, start, cancel, send, update, error as error$1 } from './actionTypes.js';
|
|
7
7
|
import { doneInvoke, initEvent, getActionFunction, error } from './actions.js';
|
|
8
|
-
import {
|
|
8
|
+
import { isStateConfig, State, bindActionToState } from './State.js';
|
|
9
9
|
import { provide, consume } from './serviceScope.js';
|
|
10
10
|
import { isSpawnedActor, createDeferredActor } from './Actor.js';
|
|
11
11
|
import { Scheduler } from './scheduler.js';
|
|
@@ -459,7 +459,7 @@ function () {
|
|
|
459
459
|
this.initialized = true;
|
|
460
460
|
this.status = InterpreterStatus.Running;
|
|
461
461
|
var resolvedState = initialState === undefined ? this.initialState : provide(this, function () {
|
|
462
|
-
return
|
|
462
|
+
return isStateConfig(initialState) ? _this.machine.resolveState(initialState) : _this.machine.resolveState(State.from(initialState, _this.machine.context));
|
|
463
463
|
});
|
|
464
464
|
|
|
465
465
|
if (this.options.devTools) {
|
|
@@ -997,6 +997,8 @@ function () {
|
|
|
997
997
|
};
|
|
998
998
|
|
|
999
999
|
Interpreter.prototype.spawnPromise = function (promise, id) {
|
|
1000
|
+
var _a;
|
|
1001
|
+
|
|
1000
1002
|
var _this = this;
|
|
1001
1003
|
|
|
1002
1004
|
var canceled = false;
|
|
@@ -1039,8 +1041,7 @@ function () {
|
|
|
1039
1041
|
}
|
|
1040
1042
|
}
|
|
1041
1043
|
});
|
|
1042
|
-
|
|
1043
|
-
var actor = __assign({
|
|
1044
|
+
var actor = (_a = {
|
|
1044
1045
|
id: id,
|
|
1045
1046
|
send: function () {
|
|
1046
1047
|
return void 0;
|
|
@@ -1084,13 +1085,16 @@ function () {
|
|
|
1084
1085
|
getSnapshot: function () {
|
|
1085
1086
|
return resolvedData;
|
|
1086
1087
|
}
|
|
1087
|
-
},
|
|
1088
|
-
|
|
1088
|
+
}, _a[symbolObservable] = function () {
|
|
1089
|
+
return this;
|
|
1090
|
+
}, _a);
|
|
1089
1091
|
this.children.set(id, actor);
|
|
1090
1092
|
return actor;
|
|
1091
1093
|
};
|
|
1092
1094
|
|
|
1093
1095
|
Interpreter.prototype.spawnCallback = function (callback, id) {
|
|
1096
|
+
var _a;
|
|
1097
|
+
|
|
1094
1098
|
var _this = this;
|
|
1095
1099
|
|
|
1096
1100
|
var canceled = false;
|
|
@@ -1129,7 +1133,7 @@ function () {
|
|
|
1129
1133
|
return this.spawnPromise(callbackStop, id);
|
|
1130
1134
|
}
|
|
1131
1135
|
|
|
1132
|
-
var actor =
|
|
1136
|
+
var actor = (_a = {
|
|
1133
1137
|
id: id,
|
|
1134
1138
|
send: function (event) {
|
|
1135
1139
|
return receivers.forEach(function (receiver) {
|
|
@@ -1137,10 +1141,11 @@ function () {
|
|
|
1137
1141
|
});
|
|
1138
1142
|
},
|
|
1139
1143
|
subscribe: function (next) {
|
|
1140
|
-
|
|
1144
|
+
var observer = toObserver(next);
|
|
1145
|
+
listeners.add(observer.next);
|
|
1141
1146
|
return {
|
|
1142
1147
|
unsubscribe: function () {
|
|
1143
|
-
listeners.delete(next);
|
|
1148
|
+
listeners.delete(observer.next);
|
|
1144
1149
|
}
|
|
1145
1150
|
};
|
|
1146
1151
|
},
|
|
@@ -1159,13 +1164,16 @@ function () {
|
|
|
1159
1164
|
getSnapshot: function () {
|
|
1160
1165
|
return emitted;
|
|
1161
1166
|
}
|
|
1162
|
-
},
|
|
1163
|
-
|
|
1167
|
+
}, _a[symbolObservable] = function () {
|
|
1168
|
+
return this;
|
|
1169
|
+
}, _a);
|
|
1164
1170
|
this.children.set(id, actor);
|
|
1165
1171
|
return actor;
|
|
1166
1172
|
};
|
|
1167
1173
|
|
|
1168
1174
|
Interpreter.prototype.spawnObservable = function (source, id) {
|
|
1175
|
+
var _a;
|
|
1176
|
+
|
|
1169
1177
|
var _this = this;
|
|
1170
1178
|
|
|
1171
1179
|
var emitted;
|
|
@@ -1188,8 +1196,7 @@ function () {
|
|
|
1188
1196
|
origin: id
|
|
1189
1197
|
}));
|
|
1190
1198
|
});
|
|
1191
|
-
|
|
1192
|
-
var actor = __assign({
|
|
1199
|
+
var actor = (_a = {
|
|
1193
1200
|
id: id,
|
|
1194
1201
|
send: function () {
|
|
1195
1202
|
return void 0;
|
|
@@ -1208,8 +1215,9 @@ function () {
|
|
|
1208
1215
|
id: id
|
|
1209
1216
|
};
|
|
1210
1217
|
}
|
|
1211
|
-
},
|
|
1212
|
-
|
|
1218
|
+
}, _a[symbolObservable] = function () {
|
|
1219
|
+
return this;
|
|
1220
|
+
}, _a);
|
|
1213
1221
|
this.children.set(id, actor);
|
|
1214
1222
|
return actor;
|
|
1215
1223
|
};
|
|
@@ -1237,7 +1245,9 @@ function () {
|
|
|
1237
1245
|
};
|
|
1238
1246
|
|
|
1239
1247
|
Interpreter.prototype.spawnEffect = function (id, dispose) {
|
|
1240
|
-
|
|
1248
|
+
var _a;
|
|
1249
|
+
|
|
1250
|
+
this.children.set(id, (_a = {
|
|
1241
1251
|
id: id,
|
|
1242
1252
|
send: function () {
|
|
1243
1253
|
return void 0;
|
|
@@ -1258,7 +1268,9 @@ function () {
|
|
|
1258
1268
|
id: id
|
|
1259
1269
|
};
|
|
1260
1270
|
}
|
|
1261
|
-
},
|
|
1271
|
+
}, _a[symbolObservable] = function () {
|
|
1272
|
+
return this;
|
|
1273
|
+
}, _a));
|
|
1262
1274
|
};
|
|
1263
1275
|
|
|
1264
1276
|
Interpreter.prototype.attachDev = function () {
|
|
@@ -1299,9 +1311,7 @@ function () {
|
|
|
1299
1311
|
|
|
1300
1312
|
Interpreter.prototype[symbolObservable] = function () {
|
|
1301
1313
|
return this;
|
|
1302
|
-
};
|
|
1303
|
-
// it has to be here to be included in the generated .d.ts
|
|
1304
|
-
|
|
1314
|
+
};
|
|
1305
1315
|
|
|
1306
1316
|
Interpreter.prototype.getSnapshot = function () {
|
|
1307
1317
|
if (this.status === InterpreterStatus.NotStarted) {
|
package/es/model.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { EventObject, BaseActionObject } from './types';
|
|
2
|
-
import {
|
|
1
|
+
import type { Cast, EventObject, BaseActionObject, Prop, IsNever } from './types';
|
|
2
|
+
import { UnionFromCreatorsReturnTypes, FinalModelCreators, Model, ModelCreators } from './model.types';
|
|
3
3
|
export declare function createModel<TContext, TEvent extends EventObject, TAction extends BaseActionObject = BaseActionObject>(initialContext: TContext): Model<TContext, TEvent, TAction, void>;
|
|
4
4
|
export declare function createModel<TContext, TModelCreators extends ModelCreators<TModelCreators>, TFinalModelCreators = FinalModelCreators<TModelCreators>, TComputedEvent = UnionFromCreatorsReturnTypes<Prop<TFinalModelCreators, 'events'>>, TComputedAction = UnionFromCreatorsReturnTypes<Prop<TFinalModelCreators, 'actions'>>>(initialContext: TContext, creators: TModelCreators): Model<TContext, Cast<TComputedEvent, EventObject>, IsNever<TComputedAction> extends true ? BaseActionObject : Cast<TComputedAction, BaseActionObject>, TFinalModelCreators>;
|
|
5
5
|
//# sourceMappingURL=model.d.ts.map
|
package/es/model.types.d.ts
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
export declare type IsNever<T> = [T] extends [never] ? true : false;
|
|
4
|
-
export declare type Cast<T extends any, TCastType extends any> = T extends TCastType ? T : TCastType;
|
|
5
|
-
export declare type Compute<A extends any> = {
|
|
6
|
-
[K in keyof A]: A[K];
|
|
7
|
-
} & unknown;
|
|
8
|
-
export declare type Prop<T, K> = K extends keyof T ? T[K] : never;
|
|
1
|
+
import { AnyFunction, AssignAction, Assigner, BaseActionObject, Compute, EventObject, ExtractEvent, MachineConfig, Prop, PropertyAssigner, StateMachine, InternalMachineOptions, ServiceMap } from './types';
|
|
2
|
+
import { ResolveTypegenMeta, TypegenConstraint, TypegenDisabled } from './typegenTypes';
|
|
9
3
|
export interface Model<TContext, TEvent extends EventObject, TAction extends BaseActionObject = BaseActionObject, TModelCreators = void> {
|
|
10
4
|
initialContext: TContext;
|
|
11
5
|
assign: <TEventType extends TEvent['type'] = TEvent['type']>(assigner: Assigner<TContext, ExtractEvent<TEvent, TEventType>> | PropertyAssigner<TContext, ExtractEvent<TEvent, TEventType>>, eventType?: TEventType) => AssignAction<TContext, ExtractEvent<TEvent, TEventType>>;
|
|
12
6
|
events: Prop<TModelCreators, 'events'>;
|
|
13
7
|
actions: Prop<TModelCreators, 'actions'>;
|
|
14
8
|
reset: () => AssignAction<TContext, any>;
|
|
15
|
-
createMachine:
|
|
9
|
+
createMachine: {
|
|
10
|
+
<TServiceMap extends ServiceMap = ServiceMap, TTypesMeta extends TypegenConstraint = TypegenDisabled>(config: MachineConfig<TContext, any, TEvent, TAction, TServiceMap, TTypesMeta>, implementations?: InternalMachineOptions<TContext, TEvent, ResolveTypegenMeta<TTypesMeta, TEvent, TAction, TServiceMap>>): StateMachine<TContext, any, TEvent, {
|
|
11
|
+
value: any;
|
|
12
|
+
context: TContext;
|
|
13
|
+
}, TAction, TServiceMap, ResolveTypegenMeta<TTypesMeta, TEvent, TAction, TServiceMap>>;
|
|
14
|
+
};
|
|
16
15
|
}
|
|
17
16
|
export declare type ModelContextFrom<TModel extends Model<any, any, any, any>> = TModel extends Model<infer TContext, any, any, any> ? TContext : never;
|
|
18
17
|
export declare type ModelEventsFrom<TModel extends Model<any, any, any, any> | undefined> = TModel extends Model<any, infer TEvent, any, any> ? TEvent : EventObject;
|
package/es/schema.d.ts
CHANGED
package/es/schema.js
CHANGED
package/es/scxml.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AnyStateMachine } from './index';
|
|
2
2
|
export interface ScxmlToMachineOptions {
|
|
3
3
|
delimiter?: string;
|
|
4
4
|
}
|
|
5
|
-
export declare function toMachine(xml: string, options: ScxmlToMachineOptions):
|
|
5
|
+
export declare function toMachine(xml: string, options: ScxmlToMachineOptions): AnyStateMachine;
|
|
6
6
|
//# sourceMappingURL=scxml.d.ts.map
|