xstate 4.26.0-pr2674-202191175724 → 4.26.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 +29 -10
- 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 -1
- package/es/Machine.d.ts +4 -5
- package/es/State.d.ts +9 -11
- package/es/StateNode.d.ts +14 -15
- package/es/StateNode.js +6 -6
- package/es/actions.d.ts +5 -4
- package/es/behaviors.d.ts +1 -1
- package/es/devTools.d.ts +1 -1
- package/es/each.d.ts +1 -1
- package/es/index.d.ts +0 -1
- package/es/interpreter.d.ts +25 -35
- package/es/interpreter.js +2 -1
- package/es/model.d.ts +2 -2
- package/es/model.types.d.ts +9 -8
- package/es/scxml.d.ts +2 -2
- package/es/stateUtils.d.ts +6 -6
- package/es/stateUtils.js +7 -2
- package/es/types.d.ts +51 -58
- package/es/utils.d.ts +1 -1
- package/es/utils.js +1 -1
- package/lib/Actor.d.ts +2 -1
- package/lib/Machine.d.ts +4 -5
- package/lib/State.d.ts +9 -11
- package/lib/StateNode.d.ts +14 -15
- package/lib/StateNode.js +5 -5
- package/lib/actions.d.ts +5 -4
- package/lib/behaviors.d.ts +1 -1
- package/lib/devTools.d.ts +1 -1
- package/lib/each.d.ts +1 -1
- package/lib/index.d.ts +0 -1
- package/lib/interpreter.d.ts +25 -35
- package/lib/interpreter.js +2 -1
- package/lib/model.d.ts +2 -2
- package/lib/model.types.d.ts +9 -8
- package/lib/scxml.d.ts +2 -2
- package/lib/stateUtils.d.ts +6 -6
- package/lib/stateUtils.js +6 -0
- package/lib/types.d.ts +51 -58
- package/lib/utils.d.ts +1 -1
- package/lib/utils.js +1 -1
- package/package.json +2 -6
- package/dist/xstate.cjs.d.ts +0 -11
- package/dist/xstate.cjs.js +0 -16
- package/es/typegenTypes.d.ts +0 -78
- package/lib/typegenTypes.d.ts +0 -78
- package/lib/typegenTypes.js +0 -2
package/lib/State.d.ts
CHANGED
|
@@ -1,21 +1,19 @@
|
|
|
1
1
|
import { StateValue, ActivityMap, EventObject, HistoryValue, ActionObject, EventType, StateConfig, SCXML, StateSchema, TransitionDefinition, Typestate, ActorRef, StateMachine, SimpleEventsOf } from './types';
|
|
2
2
|
import { StateNode } from './StateNode';
|
|
3
|
-
import { TypegenDisabled, TypegenEnabled } from './typegenTypes';
|
|
4
|
-
import { BaseActionObject, Prop } from './types';
|
|
5
3
|
export declare function stateValuesEqual(a: StateValue | undefined, b: StateValue | undefined): boolean;
|
|
6
4
|
export declare function isState<TContext, TEvent extends EventObject, TStateSchema extends StateSchema<TContext> = any, TTypestate extends Typestate<TContext> = {
|
|
7
5
|
value: any;
|
|
8
6
|
context: TContext;
|
|
9
|
-
}
|
|
10
|
-
export declare function bindActionToState<TC, TE extends EventObject>(action: ActionObject<TC, TE>, state: State<TC, TE, any, any
|
|
7
|
+
}>(state: object | string): state is State<TContext, TEvent, TStateSchema, TTypestate>;
|
|
8
|
+
export declare function bindActionToState<TC, TE extends EventObject>(action: ActionObject<TC, TE>, state: State<TC, TE, any, any>): ActionObject<TC, TE>;
|
|
11
9
|
export declare class State<TContext, TEvent extends EventObject = EventObject, TStateSchema extends StateSchema<TContext> = any, TTypestate extends Typestate<TContext> = {
|
|
12
10
|
value: any;
|
|
13
11
|
context: TContext;
|
|
14
|
-
}
|
|
12
|
+
}> {
|
|
15
13
|
value: StateValue;
|
|
16
14
|
context: TContext;
|
|
17
15
|
historyValue?: HistoryValue | undefined;
|
|
18
|
-
history?: State<TContext, TEvent, TStateSchema, TTypestate
|
|
16
|
+
history?: State<TContext, TEvent, TStateSchema, TTypestate>;
|
|
19
17
|
actions: Array<ActionObject<TContext, TEvent>>;
|
|
20
18
|
activities: ActivityMap;
|
|
21
19
|
meta: any;
|
|
@@ -53,13 +51,13 @@ export declare class State<TContext, TEvent extends EventObject = EventObject, T
|
|
|
53
51
|
*/
|
|
54
52
|
children: Record<string, ActorRef<any>>;
|
|
55
53
|
tags: Set<string>;
|
|
56
|
-
machine: StateMachine<TContext, any, TEvent, TTypestate
|
|
54
|
+
machine: StateMachine<TContext, any, TEvent, TTypestate> | undefined;
|
|
57
55
|
/**
|
|
58
56
|
* Creates a new State instance for the given `stateValue` and `context`.
|
|
59
57
|
* @param stateValue
|
|
60
58
|
* @param context
|
|
61
59
|
*/
|
|
62
|
-
static from<TC, TE extends EventObject = EventObject>(stateValue: State<TC, TE, any, any
|
|
60
|
+
static from<TC, TE extends EventObject = EventObject>(stateValue: State<TC, TE, any, any> | StateValue, context?: TC | undefined): State<TC, TE, any, any>;
|
|
63
61
|
/**
|
|
64
62
|
* Creates a new State instance for the given `config`.
|
|
65
63
|
* @param config The state config
|
|
@@ -97,17 +95,17 @@ export declare class State<TContext, TEvent extends EventObject = EventObject, T
|
|
|
97
95
|
* Whether the current state value is a subset of the given parent state value.
|
|
98
96
|
* @param parentStateValue
|
|
99
97
|
*/
|
|
100
|
-
matches<TSV extends TTypestate['value']>(parentStateValue:
|
|
98
|
+
matches<TSV extends TTypestate['value']>(parentStateValue: TSV): this is State<(TTypestate extends any ? {
|
|
101
99
|
value: TSV;
|
|
102
100
|
context: any;
|
|
103
|
-
} extends TTypestate ? TTypestate : never : never)['context'], TEvent, TStateSchema, TTypestate
|
|
101
|
+
} extends TTypestate ? TTypestate : never : never)['context'], TEvent, TStateSchema, TTypestate> & {
|
|
104
102
|
value: TSV;
|
|
105
103
|
};
|
|
106
104
|
/**
|
|
107
105
|
* Whether the current state configuration has a state node with the specified `tag`.
|
|
108
106
|
* @param tag
|
|
109
107
|
*/
|
|
110
|
-
hasTag(tag:
|
|
108
|
+
hasTag(tag: string): boolean;
|
|
111
109
|
/**
|
|
112
110
|
* Determines whether sending the `event` will cause a transition.
|
|
113
111
|
* @param event The event to test
|
package/lib/StateNode.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { Event, StateValue, MachineOptions, EventObject, HistoryValue, StateNodeDefinition, TransitionDefinition, DelayedTransitionDefinition, ActivityDefinition, StateNodeConfig, StateSchema, StateNodesConfig, InvokeDefinition, ActionObject, Mapper, PropertyMapper, SCXML, Typestate, TransitionDefinitionMap, MachineSchema
|
|
1
|
+
import { Event, StateValue, MachineOptions, EventObject, HistoryValue, StateNodeDefinition, TransitionDefinition, DelayedTransitionDefinition, ActivityDefinition, StateNodeConfig, StateSchema, StateNodesConfig, InvokeDefinition, ActionObject, Mapper, PropertyMapper, SCXML, Typestate, TransitionDefinitionMap, MachineSchema } from './types';
|
|
2
2
|
import { State } from './State';
|
|
3
|
-
import { MaybeTypegenMachineOptions, TypegenDisabled } from './typegenTypes';
|
|
4
3
|
declare class StateNode<TContext = any, TStateSchema extends StateSchema = any, TEvent extends EventObject = EventObject, TTypestate extends Typestate<TContext> = {
|
|
5
4
|
value: any;
|
|
6
5
|
context: TContext;
|
|
7
|
-
}
|
|
6
|
+
}> {
|
|
8
7
|
/**
|
|
9
8
|
* The raw config used to create the machine.
|
|
10
9
|
*/
|
|
@@ -120,7 +119,7 @@ declare class StateNode<TContext = any, TStateSchema extends StateSchema = any,
|
|
|
120
119
|
/**
|
|
121
120
|
* The raw config used to create the machine.
|
|
122
121
|
*/
|
|
123
|
-
config: StateNodeConfig<TContext, TStateSchema, TEvent>, options?: MachineOptions<TContext, TEvent
|
|
122
|
+
config: StateNodeConfig<TContext, TStateSchema, TEvent>, options?: Partial<MachineOptions<TContext, TEvent>>,
|
|
124
123
|
/**
|
|
125
124
|
* The initial extended state
|
|
126
125
|
*/
|
|
@@ -132,7 +131,7 @@ declare class StateNode<TContext = any, TStateSchema extends StateSchema = any,
|
|
|
132
131
|
* @param options Options (actions, guards, activities, services) to recursively merge with the existing options.
|
|
133
132
|
* @param context Custom context (will override predefined context)
|
|
134
133
|
*/
|
|
135
|
-
withConfig(options:
|
|
134
|
+
withConfig(options: Partial<MachineOptions<TContext, TEvent>>, context?: TContext | (() => TContext)): StateNode<TContext, TStateSchema, TEvent, TTypestate>;
|
|
136
135
|
/**
|
|
137
136
|
* Clones this state machine with custom context.
|
|
138
137
|
*
|
|
@@ -164,7 +163,7 @@ declare class StateNode<TContext = any, TStateSchema extends StateSchema = any,
|
|
|
164
163
|
*
|
|
165
164
|
* @param state The state value or State instance
|
|
166
165
|
*/
|
|
167
|
-
getStateNodes(state: StateValue | State<TContext, TEvent, any, TTypestate
|
|
166
|
+
getStateNodes(state: StateValue | State<TContext, TEvent, any, TTypestate>): Array<StateNode<TContext, any, TEvent, TTypestate>>;
|
|
168
167
|
/**
|
|
169
168
|
* Returns `true` if this state node explicitly handles the given event.
|
|
170
169
|
*
|
|
@@ -178,7 +177,7 @@ declare class StateNode<TContext = any, TStateSchema extends StateSchema = any,
|
|
|
178
177
|
*
|
|
179
178
|
* @param state The state to resolve
|
|
180
179
|
*/
|
|
181
|
-
resolveState(state: State<TContext, TEvent, any, any
|
|
180
|
+
resolveState(state: State<TContext, TEvent, any, any>): State<TContext, TEvent, TStateSchema, TTypestate>;
|
|
182
181
|
private transitionLeafNode;
|
|
183
182
|
private transitionCompoundNode;
|
|
184
183
|
private transitionParallelNode;
|
|
@@ -198,25 +197,25 @@ declare class StateNode<TContext = any, TStateSchema extends StateSchema = any,
|
|
|
198
197
|
* @param event The event that was sent at the current state
|
|
199
198
|
* @param context The current context (extended state) of the current state
|
|
200
199
|
*/
|
|
201
|
-
transition(state: StateValue | State<TContext, TEvent, any, TTypestate
|
|
200
|
+
transition(state: StateValue | State<TContext, TEvent, any, TTypestate> | undefined, event: Event<TEvent> | SCXML.Event<TEvent>, context?: TContext): State<TContext, TEvent, TStateSchema, TTypestate>;
|
|
202
201
|
private resolveRaisedTransition;
|
|
203
202
|
private resolveTransition;
|
|
204
203
|
/**
|
|
205
204
|
* Returns the child state node from its relative `stateKey`, or throws.
|
|
206
205
|
*/
|
|
207
|
-
getStateNode(stateKey: string): StateNode<TContext, any, TEvent, TTypestate
|
|
206
|
+
getStateNode(stateKey: string): StateNode<TContext, any, TEvent, TTypestate>;
|
|
208
207
|
/**
|
|
209
208
|
* Returns the state node with the given `stateId`, or throws.
|
|
210
209
|
*
|
|
211
210
|
* @param stateId The state ID. The prefix "#" is removed.
|
|
212
211
|
*/
|
|
213
|
-
getStateNodeById(stateId: string): StateNode<TContext, any, TEvent, any
|
|
212
|
+
getStateNodeById(stateId: string): StateNode<TContext, any, TEvent, any>;
|
|
214
213
|
/**
|
|
215
214
|
* Returns the relative state node from the given `statePath`, or throws.
|
|
216
215
|
*
|
|
217
216
|
* @param statePath The string or string array relative path to the state node.
|
|
218
217
|
*/
|
|
219
|
-
getStateNodeByPath(statePath: string | string[]): StateNode<TContext, any, TEvent, any
|
|
218
|
+
getStateNodeByPath(statePath: string | string[]): StateNode<TContext, any, TEvent, any>;
|
|
220
219
|
/**
|
|
221
220
|
* Resolves a partial state value with its full representation in this machine.
|
|
222
221
|
*
|
|
@@ -225,12 +224,12 @@ declare class StateNode<TContext = any, TStateSchema extends StateSchema = any,
|
|
|
225
224
|
resolve(stateValue: StateValue): StateValue;
|
|
226
225
|
private getResolvedPath;
|
|
227
226
|
private get initialStateValue();
|
|
228
|
-
getInitialState(stateValue: StateValue, context?: TContext): State<TContext, TEvent, TStateSchema, TTypestate
|
|
227
|
+
getInitialState(stateValue: StateValue, context?: TContext): State<TContext, TEvent, TStateSchema, TTypestate>;
|
|
229
228
|
/**
|
|
230
229
|
* The initial State instance, which includes all actions to be executed from
|
|
231
230
|
* entering the initial state.
|
|
232
231
|
*/
|
|
233
|
-
get initialState(): State<TContext, TEvent, TStateSchema, TTypestate
|
|
232
|
+
get initialState(): State<TContext, TEvent, TStateSchema, TTypestate>;
|
|
234
233
|
/**
|
|
235
234
|
* The target state value of the history state node, if it exists. This represents the
|
|
236
235
|
* default state value to transition to if no history value exists yet.
|
|
@@ -244,14 +243,14 @@ declare class StateNode<TContext = any, TStateSchema extends StateSchema = any,
|
|
|
244
243
|
* @param resolve Whether state nodes should resolve to initial child state nodes
|
|
245
244
|
*/
|
|
246
245
|
getRelativeStateNodes(relativeStateId: StateNode<TContext, any, TEvent>, historyValue?: HistoryValue, resolve?: boolean): Array<StateNode<TContext, any, TEvent>>;
|
|
247
|
-
get initialStateNodes(): Array<StateNode<TContext, any, TEvent, any
|
|
246
|
+
get initialStateNodes(): Array<StateNode<TContext, any, TEvent, any>>;
|
|
248
247
|
/**
|
|
249
248
|
* Retrieves state nodes from a relative path to this state node.
|
|
250
249
|
*
|
|
251
250
|
* @param relativePath The relative path from this state node
|
|
252
251
|
* @param historyValue
|
|
253
252
|
*/
|
|
254
|
-
getFromRelativePath(relativePath: string[]): Array<StateNode<TContext, any, TEvent, any
|
|
253
|
+
getFromRelativePath(relativePath: string[]): Array<StateNode<TContext, any, TEvent, any>>;
|
|
255
254
|
private historyValue;
|
|
256
255
|
/**
|
|
257
256
|
* Resolves to the historical value(s) of the parent state node,
|
package/lib/StateNode.js
CHANGED
|
@@ -273,7 +273,8 @@ function () {
|
|
|
273
273
|
order: this.order || -1,
|
|
274
274
|
data: this.doneData,
|
|
275
275
|
invoke: this.invoke,
|
|
276
|
-
description: this.description
|
|
276
|
+
description: this.description,
|
|
277
|
+
tags: this.tags
|
|
277
278
|
};
|
|
278
279
|
},
|
|
279
280
|
enumerable: false,
|
|
@@ -447,7 +448,8 @@ function () {
|
|
|
447
448
|
return new State.State(_tslib.__assign(_tslib.__assign({}, state), {
|
|
448
449
|
value: this.resolve(state.value),
|
|
449
450
|
configuration: configuration,
|
|
450
|
-
done: stateUtils.isInFinalState(configuration, this)
|
|
451
|
+
done: stateUtils.isInFinalState(configuration, this),
|
|
452
|
+
tags: stateUtils.getTagsFromConfiguration(configuration)
|
|
451
453
|
}));
|
|
452
454
|
};
|
|
453
455
|
|
|
@@ -980,9 +982,7 @@ function () {
|
|
|
980
982
|
maybeNextState.changed = changed; // Preserve original history after raised events
|
|
981
983
|
|
|
982
984
|
maybeNextState.history = history;
|
|
983
|
-
maybeNextState.tags =
|
|
984
|
-
return sn.tags;
|
|
985
|
-
})));
|
|
985
|
+
maybeNextState.tags = stateUtils.getTagsFromConfiguration(maybeNextState.configuration);
|
|
986
986
|
return maybeNextState;
|
|
987
987
|
};
|
|
988
988
|
/**
|
package/lib/actions.d.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
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,
|
|
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 } from './types';
|
|
2
2
|
import * as actionTypes from './actionTypes';
|
|
3
3
|
import { State } from './State';
|
|
4
4
|
import { StateNode } from './StateNode';
|
|
5
|
+
import { StopAction, StopActionObject } from '.';
|
|
5
6
|
export { actionTypes };
|
|
6
7
|
export declare const initEvent: SCXML.Event<{
|
|
7
8
|
type: ActionTypes;
|
|
8
9
|
}>;
|
|
9
10
|
export declare function getActionFunction<TContext, TEvent extends EventObject>(actionType: ActionType, actionFunctionMap?: ActionFunctionMap<TContext, TEvent>): ActionObject<TContext, TEvent> | ActionFunction<TContext, TEvent> | undefined;
|
|
10
11
|
export declare function toActionObject<TContext, TEvent extends EventObject>(action: Action<TContext, TEvent>, actionFunctionMap?: ActionFunctionMap<TContext, TEvent>): ActionObject<TContext, TEvent>;
|
|
11
|
-
export declare const toActionObjects: <TContext, TEvent extends EventObject>(action?: SingleOrArray<Action<TContext, TEvent>> | undefined, actionFunctionMap?: ActionFunctionMap<TContext, TEvent,
|
|
12
|
+
export declare const toActionObjects: <TContext, TEvent extends EventObject>(action?: SingleOrArray<Action<TContext, TEvent>> | undefined, actionFunctionMap?: ActionFunctionMap<TContext, TEvent, ActionObject<TContext, TEvent>> | undefined) => ActionObject<TContext, TEvent>[];
|
|
12
13
|
export declare function toActivityDefinition<TContext, TEvent extends EventObject>(action: string | ActivityDefinition<TContext, TEvent>): ActivityDefinition<TContext, TEvent>;
|
|
13
14
|
/**
|
|
14
15
|
* Raises an event. This places the event in the internal event queue, so that
|
|
@@ -133,6 +134,6 @@ export declare function forwardTo<TContext, TEvent extends EventObject>(target:
|
|
|
133
134
|
* @param options Options to pass into the send action creator.
|
|
134
135
|
*/
|
|
135
136
|
export declare function escalate<TContext, TEvent extends EventObject, TErrorData = any>(errorData: TErrorData | ExprWithMeta<TContext, TEvent, TErrorData>, options?: SendActionOptions<TContext, TEvent>): SendAction<TContext, TEvent, AnyEventObject>;
|
|
136
|
-
export declare function choose<TContext, TEvent extends EventObject>(conds: Array<
|
|
137
|
-
export declare function resolveActions<TContext, TEvent extends EventObject>(machine: StateNode<TContext, any, TEvent, any
|
|
137
|
+
export declare function choose<TContext, TEvent extends EventObject>(conds: Array<ChooseCondition<TContext, TEvent>>): ChooseAction<TContext, TEvent>;
|
|
138
|
+
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];
|
|
138
139
|
//# sourceMappingURL=actions.d.ts.map
|
package/lib/behaviors.d.ts
CHANGED
package/lib/devTools.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
+
import { Interpreter } from '.';
|
|
2
3
|
import { AnyInterpreter } from './types';
|
|
3
|
-
import { Interpreter } from './interpreter';
|
|
4
4
|
declare type ServiceListener = (service: AnyInterpreter) => void;
|
|
5
5
|
export interface XStateDevInterface {
|
|
6
6
|
register: (service: Interpreter<any>) => void;
|
package/lib/each.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EventObject, SingleOrArray, ActionObject } from '
|
|
1
|
+
import { EventObject, SingleOrArray, ActionObject } from '.';
|
|
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/lib/index.d.ts
CHANGED
|
@@ -28,5 +28,4 @@ declare const actions: {
|
|
|
28
28
|
};
|
|
29
29
|
export { Actor, Machine, StateNode, State, matchesState, mapState, actions, assign, send, sendParent, sendUpdate, forwardTo, interpret, Interpreter, InterpreterStatus, matchState, spawn, doneInvoke, createMachine, createSchema };
|
|
30
30
|
export * from './types';
|
|
31
|
-
export * from './typegenTypes';
|
|
32
31
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/interpreter.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
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 { AreAllImplementationsAssumedToBeProvided, TypegenDisabled } from './typegenTypes';
|
|
4
3
|
export declare type StateListener<TContext, TEvent extends EventObject, TStateSchema extends StateSchema<TContext> = any, TTypestate extends Typestate<TContext> = {
|
|
5
4
|
value: any;
|
|
6
5
|
context: TContext;
|
|
7
|
-
}
|
|
6
|
+
}> = (state: State<TContext, TEvent, TStateSchema, TTypestate>, event: TEvent) => void;
|
|
8
7
|
export declare type ContextListener<TContext = DefaultContext> = (context: TContext, prevContext: TContext | undefined) => void;
|
|
9
8
|
export declare type EventListener<TEvent extends EventObject = EventObject> = (event: TEvent) => void;
|
|
10
9
|
export declare type Listener = () => void;
|
|
@@ -30,24 +29,15 @@ declare global {
|
|
|
30
29
|
export declare class Interpreter<TContext, TStateSchema extends StateSchema = any, TEvent extends EventObject = EventObject, TTypestate extends Typestate<TContext> = {
|
|
31
30
|
value: any;
|
|
32
31
|
context: TContext;
|
|
33
|
-
}
|
|
34
|
-
machine: StateMachine<TContext, TStateSchema, TEvent, TTypestate
|
|
32
|
+
}> implements ActorRef<TEvent, State<TContext, TEvent, TStateSchema, TTypestate>> {
|
|
33
|
+
machine: StateMachine<TContext, TStateSchema, TEvent, TTypestate>;
|
|
35
34
|
/**
|
|
36
35
|
* The default interpreter options:
|
|
37
36
|
*
|
|
38
37
|
* - `clock` uses the global `setTimeout` and `clearTimeout` functions
|
|
39
38
|
* - `logger` uses the global `console.log()` method
|
|
40
39
|
*/
|
|
41
|
-
static defaultOptions:
|
|
42
|
-
execute: boolean;
|
|
43
|
-
deferEvents: boolean;
|
|
44
|
-
clock: {
|
|
45
|
-
setTimeout: (fn: any, ms: any) => number;
|
|
46
|
-
clearTimeout: (id: any) => void;
|
|
47
|
-
};
|
|
48
|
-
logger: any;
|
|
49
|
-
devTools: boolean;
|
|
50
|
-
};
|
|
40
|
+
static defaultOptions: InterpreterOptions;
|
|
51
41
|
/**
|
|
52
42
|
* The current state of the interpreted machine.
|
|
53
43
|
*/
|
|
@@ -87,9 +77,9 @@ export declare class Interpreter<TContext, TStateSchema extends StateSchema = an
|
|
|
87
77
|
* @param machine The machine to be interpreted
|
|
88
78
|
* @param options Interpreter options
|
|
89
79
|
*/
|
|
90
|
-
constructor(machine: StateMachine<TContext, TStateSchema, TEvent, TTypestate
|
|
91
|
-
get initialState(): State<TContext, TEvent, TStateSchema, TTypestate
|
|
92
|
-
get state(): State<TContext, TEvent, TStateSchema, TTypestate
|
|
80
|
+
constructor(machine: StateMachine<TContext, TStateSchema, TEvent, TTypestate>, options?: Partial<InterpreterOptions>);
|
|
81
|
+
get initialState(): State<TContext, TEvent, TStateSchema, TTypestate>;
|
|
82
|
+
get state(): State<TContext, TEvent, TStateSchema, TTypestate>;
|
|
93
83
|
static interpret: typeof interpret;
|
|
94
84
|
/**
|
|
95
85
|
* Executes the actions of the given state, with that state's `context` and `event`.
|
|
@@ -97,56 +87,56 @@ export declare class Interpreter<TContext, TStateSchema extends StateSchema = an
|
|
|
97
87
|
* @param state The state whose actions will be executed
|
|
98
88
|
* @param actionsConfig The action implementations to use
|
|
99
89
|
*/
|
|
100
|
-
execute(state: State<TContext, TEvent, TStateSchema, TTypestate
|
|
90
|
+
execute(state: State<TContext, TEvent, TStateSchema, TTypestate>, actionsConfig?: MachineOptions<TContext, TEvent>['actions']): void;
|
|
101
91
|
private update;
|
|
102
|
-
onTransition(listener: StateListener<TContext, TEvent, TStateSchema, TTypestate
|
|
103
|
-
subscribe(nextListener?: (state: State<TContext, TEvent, any, TTypestate
|
|
104
|
-
subscribe(observer: Observer<State<TContext, TEvent, any, TTypestate
|
|
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;
|
|
105
95
|
/**
|
|
106
96
|
* Adds an event listener that is notified whenever an event is sent to the running interpreter.
|
|
107
97
|
* @param listener The event listener
|
|
108
98
|
*/
|
|
109
|
-
onEvent(listener: EventListener):
|
|
99
|
+
onEvent(listener: EventListener): Interpreter<TContext, TStateSchema, TEvent, TTypestate>;
|
|
110
100
|
/**
|
|
111
101
|
* Adds an event listener that is notified whenever a `send` event occurs.
|
|
112
102
|
* @param listener The event listener
|
|
113
103
|
*/
|
|
114
|
-
onSend(listener: EventListener):
|
|
104
|
+
onSend(listener: EventListener): Interpreter<TContext, TStateSchema, TEvent, TTypestate>;
|
|
115
105
|
/**
|
|
116
106
|
* Adds a context listener that is notified whenever the state context changes.
|
|
117
107
|
* @param listener The context listener
|
|
118
108
|
*/
|
|
119
|
-
onChange(listener: ContextListener<TContext>):
|
|
109
|
+
onChange(listener: ContextListener<TContext>): Interpreter<TContext, TStateSchema, TEvent, TTypestate>;
|
|
120
110
|
/**
|
|
121
111
|
* Adds a listener that is notified when the machine is stopped.
|
|
122
112
|
* @param listener The listener
|
|
123
113
|
*/
|
|
124
|
-
onStop(listener: Listener):
|
|
114
|
+
onStop(listener: Listener): Interpreter<TContext, TStateSchema, TEvent, TTypestate>;
|
|
125
115
|
/**
|
|
126
116
|
* Adds a state listener that is notified when the statechart has reached its final state.
|
|
127
117
|
* @param listener The state listener
|
|
128
118
|
*/
|
|
129
|
-
onDone(listener: EventListener<DoneEvent>):
|
|
119
|
+
onDone(listener: EventListener<DoneEvent>): Interpreter<TContext, TStateSchema, TEvent, TTypestate>;
|
|
130
120
|
/**
|
|
131
121
|
* Removes a listener.
|
|
132
122
|
* @param listener The listener to remove
|
|
133
123
|
*/
|
|
134
|
-
off(listener: (...args: any[]) => void):
|
|
124
|
+
off(listener: (...args: any[]) => void): Interpreter<TContext, TStateSchema, TEvent, TTypestate>;
|
|
135
125
|
/**
|
|
136
126
|
* Alias for Interpreter.prototype.start
|
|
137
127
|
*/
|
|
138
|
-
init: (initialState?: StateValue | State<TContext, TEvent, TStateSchema, TTypestate
|
|
128
|
+
init: (initialState?: StateValue | State<TContext, TEvent, TStateSchema, TTypestate> | undefined) => Interpreter<TContext, TStateSchema, TEvent, TTypestate>;
|
|
139
129
|
/**
|
|
140
130
|
* Starts the interpreter from the given state, or the initial state.
|
|
141
131
|
* @param initialState The state to start the statechart from
|
|
142
132
|
*/
|
|
143
|
-
start(initialState?: State<TContext, TEvent, TStateSchema, TTypestate
|
|
133
|
+
start(initialState?: State<TContext, TEvent, TStateSchema, TTypestate> | StateValue): Interpreter<TContext, TStateSchema, TEvent, TTypestate>;
|
|
144
134
|
/**
|
|
145
135
|
* Stops the interpreter and unsubscribe all listeners.
|
|
146
136
|
*
|
|
147
137
|
* This will also notify the `onStop` listeners.
|
|
148
138
|
*/
|
|
149
|
-
stop():
|
|
139
|
+
stop(): Interpreter<TContext, TStateSchema, TEvent, TTypestate>;
|
|
150
140
|
/**
|
|
151
141
|
* Sends an event to the running interpreter to trigger a transition.
|
|
152
142
|
*
|
|
@@ -156,7 +146,7 @@ export declare class Interpreter<TContext, TStateSchema extends StateSchema = an
|
|
|
156
146
|
*
|
|
157
147
|
* @param event The event(s) to send
|
|
158
148
|
*/
|
|
159
|
-
send: (event: SingleOrArray<Event<TEvent>> | SCXML.Event<TEvent>, payload?: EventData | undefined) => State<TContext, TEvent, TStateSchema, TTypestate
|
|
149
|
+
send: (event: SingleOrArray<Event<TEvent>> | SCXML.Event<TEvent>, payload?: EventData | undefined) => State<TContext, TEvent, TStateSchema, TTypestate>;
|
|
160
150
|
private batch;
|
|
161
151
|
/**
|
|
162
152
|
* Returns a send function bound to this interpreter instance.
|
|
@@ -172,7 +162,7 @@ export declare class Interpreter<TContext, TStateSchema extends StateSchema = an
|
|
|
172
162
|
*
|
|
173
163
|
* @param event The event to determine the next state
|
|
174
164
|
*/
|
|
175
|
-
nextState(event: Event<TEvent> | SCXML.Event<TEvent>): State<TContext, TEvent, TStateSchema, TTypestate
|
|
165
|
+
nextState(event: Event<TEvent> | SCXML.Event<TEvent>): State<TContext, TEvent, TStateSchema, TTypestate>;
|
|
176
166
|
private forward;
|
|
177
167
|
private defer;
|
|
178
168
|
private cancel;
|
|
@@ -196,8 +186,8 @@ export declare class Interpreter<TContext, TStateSchema extends StateSchema = an
|
|
|
196
186
|
toJSON(): {
|
|
197
187
|
id: string;
|
|
198
188
|
};
|
|
199
|
-
[Symbol.observable](): Subscribable<State<TContext, TEvent, TStateSchema, TTypestate
|
|
200
|
-
getSnapshot(): State<TContext, TEvent, TStateSchema, TTypestate
|
|
189
|
+
[Symbol.observable](): Subscribable<State<TContext, TEvent, TStateSchema, TTypestate>>;
|
|
190
|
+
getSnapshot(): State<TContext, TEvent, TStateSchema, TTypestate>;
|
|
201
191
|
}
|
|
202
192
|
export declare function spawn<T extends Behavior<any, any>>(entity: T, nameOrOptions?: string | SpawnOptions): ActorRefFrom<T>;
|
|
203
193
|
export declare function spawn<TC, TE extends EventObject>(entity: StateMachine<TC, any, TE>, nameOrOptions?: string | SpawnOptions): ActorRefFrom<StateMachine<TC, any, TE>>;
|
|
@@ -211,6 +201,6 @@ export declare function spawn(entity: Spawnable, nameOrOptions?: string | SpawnO
|
|
|
211
201
|
export declare function interpret<TContext = DefaultContext, TStateSchema extends StateSchema = any, TEvent extends EventObject = EventObject, TTypestate extends Typestate<TContext> = {
|
|
212
202
|
value: any;
|
|
213
203
|
context: TContext;
|
|
214
|
-
}
|
|
204
|
+
}>(machine: StateMachine<TContext, TStateSchema, TEvent, TTypestate>, options?: Partial<InterpreterOptions>): Interpreter<TContext, TStateSchema, TEvent, TTypestate>;
|
|
215
205
|
export {};
|
|
216
206
|
//# sourceMappingURL=interpreter.d.ts.map
|
package/lib/interpreter.js
CHANGED
package/lib/model.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import { UnionFromCreatorsReturnTypes, FinalModelCreators, Model, ModelCreators } from './model.types';
|
|
1
|
+
import type { EventObject, BaseActionObject } from './types';
|
|
2
|
+
import { Cast, UnionFromCreatorsReturnTypes, FinalModelCreators, Model, ModelCreators, Prop, IsNever } 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/lib/model.types.d.ts
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { EventObject, Assigner, ExtractEvent, PropertyAssigner, AssignAction, MachineConfig, MachineOptions, StateMachine, BaseActionObject } from './types';
|
|
2
|
+
export declare type AnyFunction = (...args: any[]) => any;
|
|
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;
|
|
3
9
|
export interface Model<TContext, TEvent extends EventObject, TAction extends BaseActionObject = BaseActionObject, TModelCreators = void> {
|
|
4
10
|
initialContext: TContext;
|
|
5
11
|
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>>;
|
|
6
12
|
events: Prop<TModelCreators, 'events'>;
|
|
7
13
|
actions: Prop<TModelCreators, 'actions'>;
|
|
8
14
|
reset: () => AssignAction<TContext, any>;
|
|
9
|
-
createMachine:
|
|
10
|
-
<TTypesMeta extends TypegenConstraint = TypegenDisabled>(config: MachineConfig<TContext, any, TEvent, TAction, TTypesMeta>, implementations?: MaybeTypegenMachineOptions<TContext, TEvent, TAction, ResolveTypegenMeta<TTypesMeta, TEvent, TAction>>): StateMachine<TContext, any, TEvent, {
|
|
11
|
-
value: any;
|
|
12
|
-
context: TContext;
|
|
13
|
-
}, TAction, ResolveTypegenMeta<TTypesMeta, TEvent, TAction>>;
|
|
14
|
-
};
|
|
15
|
+
createMachine: (config: MachineConfig<TContext, any, TEvent, TAction>, implementations?: Partial<MachineOptions<TContext, TEvent, TAction>>) => StateMachine<TContext, any, TEvent>;
|
|
15
16
|
}
|
|
16
17
|
export declare type ModelContextFrom<TModel extends Model<any, any, any, any>> = TModel extends Model<infer TContext, any, any, any> ? TContext : never;
|
|
17
18
|
export declare type ModelEventsFrom<TModel extends Model<any, any, any, any> | undefined> = TModel extends Model<any, infer TEvent, any, any> ? TEvent : EventObject;
|
package/lib/scxml.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { StateNode } 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): StateNode;
|
|
6
6
|
//# sourceMappingURL=scxml.d.ts.map
|
package/lib/stateUtils.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { EventObject, StateValue } from '
|
|
2
|
-
import { StateNode } from './StateNode';
|
|
1
|
+
import { EventObject, StateNode, StateValue } from '.';
|
|
3
2
|
declare type Configuration<TC, TE extends EventObject> = Iterable<StateNode<TC, any, TE>>;
|
|
4
3
|
declare type AdjList<TC, TE extends EventObject> = Map<StateNode<TC, any, TE>, Array<StateNode<TC, any, TE>>>;
|
|
5
|
-
export declare const isLeafNode: (stateNode: StateNode<any, any, any, any
|
|
4
|
+
export declare const isLeafNode: (stateNode: StateNode<any, any, any, any>) => boolean;
|
|
6
5
|
export declare function getChildren<TC, TE extends EventObject>(stateNode: StateNode<TC, any, TE>): Array<StateNode<TC, any, TE>>;
|
|
7
|
-
export declare function getAllStateNodes<TC, TE extends EventObject>(stateNode: StateNode<TC, any, TE, any
|
|
8
|
-
export declare function getConfiguration<TC, TE extends EventObject>(prevStateNodes: Iterable<StateNode<TC, any, TE, any
|
|
6
|
+
export declare function getAllStateNodes<TC, TE extends EventObject>(stateNode: StateNode<TC, any, TE, any>): Array<StateNode<TC, any, TE, any>>;
|
|
7
|
+
export declare function getConfiguration<TC, TE extends EventObject>(prevStateNodes: Iterable<StateNode<TC, any, TE, any>>, stateNodes: Iterable<StateNode<TC, any, TE, any>>): Iterable<StateNode<TC, any, TE, any>>;
|
|
9
8
|
export declare function getAdjList<TC, TE extends EventObject>(configuration: Configuration<TC, TE>): AdjList<TC, TE>;
|
|
10
9
|
export declare function getValue<TC, TE extends EventObject>(rootNode: StateNode<TC, any, TE, any>, configuration: Configuration<TC, TE>): StateValue;
|
|
11
10
|
export declare function has<T>(iterable: Iterable<T>, item: T): boolean;
|
|
12
11
|
export declare function nextEvents<TC, TE extends EventObject>(configuration: Array<StateNode<TC, any, TE>>): Array<TE['type']>;
|
|
13
|
-
export declare function isInFinalState<TC, TE extends EventObject>(configuration: Array<StateNode<TC, any, TE, any
|
|
12
|
+
export declare function isInFinalState<TC, TE extends EventObject>(configuration: Array<StateNode<TC, any, TE, any>>, stateNode: StateNode<TC, any, TE, any>): boolean;
|
|
14
13
|
export declare function getMeta(configuration?: StateNode[]): Record<string, any>;
|
|
14
|
+
export declare function getTagsFromConfiguration(configuration: StateNode<any, any, any, any>[]): Set<string>;
|
|
15
15
|
export {};
|
|
16
16
|
//# sourceMappingURL=stateUtils.d.ts.map
|
package/lib/stateUtils.js
CHANGED
|
@@ -256,12 +256,18 @@ function getMeta(configuration) {
|
|
|
256
256
|
return acc;
|
|
257
257
|
}, {});
|
|
258
258
|
}
|
|
259
|
+
function getTagsFromConfiguration(configuration) {
|
|
260
|
+
return new Set(utils.flatten(configuration.map(function (sn) {
|
|
261
|
+
return sn.tags;
|
|
262
|
+
})));
|
|
263
|
+
}
|
|
259
264
|
|
|
260
265
|
exports.getAdjList = getAdjList;
|
|
261
266
|
exports.getAllStateNodes = getAllStateNodes;
|
|
262
267
|
exports.getChildren = getChildren;
|
|
263
268
|
exports.getConfiguration = getConfiguration;
|
|
264
269
|
exports.getMeta = getMeta;
|
|
270
|
+
exports.getTagsFromConfiguration = getTagsFromConfiguration;
|
|
265
271
|
exports.getValue = getValue;
|
|
266
272
|
exports.has = has;
|
|
267
273
|
exports.isInFinalState = isInFinalState;
|