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/lib/Actor.js
CHANGED
|
@@ -7,7 +7,9 @@ var utils = require('./utils.js');
|
|
|
7
7
|
var serviceScope = require('./serviceScope.js');
|
|
8
8
|
|
|
9
9
|
function createNullActor(id) {
|
|
10
|
-
|
|
10
|
+
var _a;
|
|
11
|
+
|
|
12
|
+
return _a = {
|
|
11
13
|
id: id,
|
|
12
14
|
send: function () {
|
|
13
15
|
return void 0;
|
|
@@ -27,7 +29,9 @@ function createNullActor(id) {
|
|
|
27
29
|
id: id
|
|
28
30
|
};
|
|
29
31
|
}
|
|
30
|
-
}, utils.
|
|
32
|
+
}, _a[utils.symbolObservable] = function () {
|
|
33
|
+
return this;
|
|
34
|
+
}, _a;
|
|
31
35
|
}
|
|
32
36
|
/**
|
|
33
37
|
* Creates a deferred actor that is able to be invoked given the provided
|
|
@@ -74,9 +78,12 @@ function isActor(item) {
|
|
|
74
78
|
}
|
|
75
79
|
function isSpawnedActor(item) {
|
|
76
80
|
return isActor(item) && 'id' in item;
|
|
77
|
-
}
|
|
81
|
+
} // TODO: refactor the return type, this could be written in a better way but it's best to avoid unneccessary breaking changes now
|
|
82
|
+
|
|
78
83
|
function toActorRef(actorRefLike) {
|
|
79
|
-
|
|
84
|
+
var _a;
|
|
85
|
+
|
|
86
|
+
return _tslib.__assign((_a = {
|
|
80
87
|
subscribe: function () {
|
|
81
88
|
return {
|
|
82
89
|
unsubscribe: function () {
|
|
@@ -88,7 +95,9 @@ function toActorRef(actorRefLike) {
|
|
|
88
95
|
getSnapshot: function () {
|
|
89
96
|
return undefined;
|
|
90
97
|
}
|
|
91
|
-
}, utils.
|
|
98
|
+
}, _a[utils.symbolObservable] = function () {
|
|
99
|
+
return this;
|
|
100
|
+
}, _a), actorRefLike);
|
|
92
101
|
}
|
|
93
102
|
|
|
94
103
|
exports.createDeferredActor = createDeferredActor;
|
package/lib/Machine.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { Model } from './model.types';
|
|
2
|
-
import { AnyEventObject, DefaultContext, EventObject, MachineConfig,
|
|
2
|
+
import { AnyEventObject, BaseActionObject, DefaultContext, EventObject, MachineConfig, InternalMachineOptions, StateMachine, StateSchema, Typestate, ServiceMap } from './types';
|
|
3
|
+
import { TypegenConstraint, TypegenDisabled, ResolveTypegenMeta } from './typegenTypes';
|
|
3
4
|
/**
|
|
4
5
|
* @deprecated Use `createMachine(...)` instead.
|
|
5
6
|
*/
|
|
6
|
-
export declare function Machine<TContext = any, TEvent extends EventObject = AnyEventObject>(config: MachineConfig<TContext, any, TEvent>, options?:
|
|
7
|
-
export declare function Machine<TContext = DefaultContext, TStateSchema extends StateSchema = any, TEvent extends EventObject = AnyEventObject>(config: MachineConfig<TContext, TStateSchema, TEvent>, options?:
|
|
7
|
+
export declare function Machine<TContext = any, TEvent extends EventObject = AnyEventObject>(config: MachineConfig<TContext, any, TEvent>, options?: InternalMachineOptions<TContext, TEvent, ResolveTypegenMeta<TypegenDisabled, TEvent, BaseActionObject, ServiceMap>>, initialContext?: TContext): StateMachine<TContext, any, TEvent, any, BaseActionObject, ServiceMap, ResolveTypegenMeta<TypegenDisabled, TEvent, BaseActionObject, ServiceMap>>;
|
|
8
|
+
export declare function Machine<TContext = DefaultContext, TStateSchema extends StateSchema = any, TEvent extends EventObject = AnyEventObject>(config: MachineConfig<TContext, TStateSchema, TEvent>, options?: InternalMachineOptions<TContext, TEvent, ResolveTypegenMeta<TypegenDisabled, TEvent, BaseActionObject, ServiceMap>>, initialContext?: TContext): StateMachine<TContext, TStateSchema, TEvent, any, BaseActionObject, ServiceMap, ResolveTypegenMeta<TypegenDisabled, TEvent, BaseActionObject, ServiceMap>>;
|
|
8
9
|
export declare function createMachine<TContext, TEvent extends EventObject = AnyEventObject, TTypestate extends Typestate<TContext> = {
|
|
9
10
|
value: any;
|
|
10
11
|
context: TContext;
|
|
11
|
-
}>(config: TContext extends Model<any, any, any, any> ? 'Model type no longer supported as generic type. Please use `model.createMachine(...)` instead.' : MachineConfig<TContext, any, TEvent>, options?:
|
|
12
|
+
}, TServiceMap extends ServiceMap = ServiceMap, TTypesMeta extends TypegenConstraint = TypegenDisabled>(config: TContext extends Model<any, any, any, any> ? 'Model type no longer supported as generic type. Please use `model.createMachine(...)` instead.' : MachineConfig<TContext, any, TEvent, BaseActionObject, TServiceMap, TTypesMeta>, options?: InternalMachineOptions<TContext, TEvent, ResolveTypegenMeta<TTypesMeta, TEvent, BaseActionObject, TServiceMap>>): StateMachine<TContext, any, TEvent, TTypestate, BaseActionObject, TServiceMap, ResolveTypegenMeta<TTypesMeta, TEvent, BaseActionObject, TServiceMap>>;
|
|
12
13
|
//# sourceMappingURL=Machine.d.ts.map
|
package/lib/State.d.ts
CHANGED
|
@@ -1,19 +1,22 @@
|
|
|
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';
|
|
3
5
|
export declare function stateValuesEqual(a: StateValue | undefined, b: StateValue | undefined): boolean;
|
|
4
|
-
export declare function
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export declare
|
|
6
|
+
export declare function isStateConfig<TContext, TEvent extends EventObject>(state: any): state is StateConfig<TContext, TEvent>;
|
|
7
|
+
/**
|
|
8
|
+
* @deprecated Use `isStateConfig(object)` or `state instanceof State` instead.
|
|
9
|
+
*/
|
|
10
|
+
export declare const isState: typeof isStateConfig;
|
|
11
|
+
export declare function bindActionToState<TC, TE extends EventObject>(action: ActionObject<TC, TE>, state: State<TC, TE, any, any, any>): ActionObject<TC, TE>;
|
|
9
12
|
export declare class State<TContext, TEvent extends EventObject = EventObject, TStateSchema extends StateSchema<TContext> = any, TTypestate extends Typestate<TContext> = {
|
|
10
13
|
value: any;
|
|
11
14
|
context: TContext;
|
|
12
|
-
}> {
|
|
15
|
+
}, TResolvedTypesMeta = TypegenDisabled> {
|
|
13
16
|
value: StateValue;
|
|
14
17
|
context: TContext;
|
|
15
18
|
historyValue?: HistoryValue | undefined;
|
|
16
|
-
history?: State<TContext, TEvent, TStateSchema, TTypestate>;
|
|
19
|
+
history?: State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>;
|
|
17
20
|
actions: Array<ActionObject<TContext, TEvent>>;
|
|
18
21
|
activities: ActivityMap;
|
|
19
22
|
meta: any;
|
|
@@ -37,7 +40,7 @@ export declare class State<TContext, TEvent extends EventObject = EventObject, T
|
|
|
37
40
|
/**
|
|
38
41
|
* The enabled state nodes representative of the state value.
|
|
39
42
|
*/
|
|
40
|
-
configuration: Array<StateNode<TContext, any, TEvent, any>>;
|
|
43
|
+
configuration: Array<StateNode<TContext, any, TEvent, any, any>>;
|
|
41
44
|
/**
|
|
42
45
|
* The next events that will cause a transition from the current state.
|
|
43
46
|
*/
|
|
@@ -51,24 +54,24 @@ export declare class State<TContext, TEvent extends EventObject = EventObject, T
|
|
|
51
54
|
*/
|
|
52
55
|
children: Record<string, ActorRef<any>>;
|
|
53
56
|
tags: Set<string>;
|
|
54
|
-
machine: StateMachine<TContext, any, TEvent, TTypestate> | undefined;
|
|
57
|
+
machine: StateMachine<TContext, any, TEvent, TTypestate, BaseActionObject, any, TResolvedTypesMeta> | undefined;
|
|
55
58
|
/**
|
|
56
59
|
* Creates a new State instance for the given `stateValue` and `context`.
|
|
57
60
|
* @param stateValue
|
|
58
61
|
* @param context
|
|
59
62
|
*/
|
|
60
|
-
static from<TC, TE extends EventObject = EventObject>(stateValue: State<TC, TE, any, any> | StateValue, context?: TC | undefined): State<TC, TE, any, any>;
|
|
63
|
+
static from<TC, TE extends EventObject = EventObject>(stateValue: State<TC, TE, any, any, any> | StateValue, context?: TC | undefined): State<TC, TE, any, any, any>;
|
|
61
64
|
/**
|
|
62
65
|
* Creates a new State instance for the given `config`.
|
|
63
66
|
* @param config The state config
|
|
64
67
|
*/
|
|
65
|
-
static create<TC, TE extends EventObject = EventObject>(config: StateConfig<TC, TE>): State<TC, TE>;
|
|
68
|
+
static create<TC, TE extends EventObject = EventObject>(config: StateConfig<TC, TE>): State<TC, TE, any, any, any>;
|
|
66
69
|
/**
|
|
67
70
|
* Creates a new `State` instance for the given `stateValue` and `context` with no actions (side-effects).
|
|
68
71
|
* @param stateValue
|
|
69
72
|
* @param context
|
|
70
73
|
*/
|
|
71
|
-
static inert<TC, TE extends EventObject = EventObject>(stateValue: State<TC, TE> | StateValue, context: TC): State<TC, TE>;
|
|
74
|
+
static inert<TC, TE extends EventObject = EventObject>(stateValue: State<TC, TE, any, any, any> | StateValue, context: TC): State<TC, TE>;
|
|
72
75
|
/**
|
|
73
76
|
* Creates a new State instance.
|
|
74
77
|
* @param value The state value
|
|
@@ -95,17 +98,18 @@ export declare class State<TContext, TEvent extends EventObject = EventObject, T
|
|
|
95
98
|
* Whether the current state value is a subset of the given parent state value.
|
|
96
99
|
* @param parentStateValue
|
|
97
100
|
*/
|
|
98
|
-
matches<TSV extends
|
|
101
|
+
matches<TSV extends TResolvedTypesMeta extends TypegenEnabled ? Prop<TResolvedTypesMeta, 'matchesStates'> : never>(parentStateValue: TSV): boolean;
|
|
102
|
+
matches<TSV extends TResolvedTypesMeta extends TypegenDisabled ? TTypestate['value'] : never>(parentStateValue: TSV): this is State<(TTypestate extends any ? {
|
|
99
103
|
value: TSV;
|
|
100
104
|
context: any;
|
|
101
|
-
} extends TTypestate ? TTypestate : never : never)['context'], TEvent, TStateSchema, TTypestate> & {
|
|
105
|
+
} extends TTypestate ? TTypestate : never : never)['context'], TEvent, TStateSchema, TTypestate, TResolvedTypesMeta> & {
|
|
102
106
|
value: TSV;
|
|
103
107
|
};
|
|
104
108
|
/**
|
|
105
109
|
* Whether the current state configuration has a state node with the specified `tag`.
|
|
106
110
|
* @param tag
|
|
107
111
|
*/
|
|
108
|
-
hasTag(tag: string): boolean;
|
|
112
|
+
hasTag(tag: TResolvedTypesMeta extends TypegenEnabled ? Prop<TResolvedTypesMeta, 'tags'> : string): boolean;
|
|
109
113
|
/**
|
|
110
114
|
* Determines whether sending the `event` will cause a non-forbidden transition
|
|
111
115
|
* to be selected, even if the transitions have no actions nor
|
package/lib/State.js
CHANGED
|
@@ -28,12 +28,12 @@ function stateValuesEqual(a, b) {
|
|
|
28
28
|
return stateValuesEqual(a[key], b[key]);
|
|
29
29
|
});
|
|
30
30
|
}
|
|
31
|
-
function
|
|
32
|
-
if (
|
|
31
|
+
function isStateConfig(state) {
|
|
32
|
+
if (typeof state !== 'object' || state === null) {
|
|
33
33
|
return false;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
return 'value' in state && '
|
|
36
|
+
return 'value' in state && '_event' in state;
|
|
37
37
|
}
|
|
38
38
|
function bindActionToState(action, state) {
|
|
39
39
|
var exec = action.exec;
|
|
@@ -230,11 +230,6 @@ function () {
|
|
|
230
230
|
tags: Array.from(tags)
|
|
231
231
|
});
|
|
232
232
|
};
|
|
233
|
-
/**
|
|
234
|
-
* Whether the current state value is a subset of the given parent state value.
|
|
235
|
-
* @param parentStateValue
|
|
236
|
-
*/
|
|
237
|
-
|
|
238
233
|
|
|
239
234
|
State.prototype.matches = function (parentStateValue) {
|
|
240
235
|
return utils.matchesState(parentStateValue, this.value);
|
|
@@ -277,5 +272,5 @@ function () {
|
|
|
277
272
|
|
|
278
273
|
exports.State = State;
|
|
279
274
|
exports.bindActionToState = bindActionToState;
|
|
280
|
-
exports.
|
|
275
|
+
exports.isStateConfig = isStateConfig;
|
|
281
276
|
exports.stateValuesEqual = stateValuesEqual;
|
package/lib/StateNode.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { Event, StateValue, StateTransition, MachineOptions, EventObject, HistoryValue, StateNodeDefinition, TransitionDefinition, DelayedTransitionDefinition, ActivityDefinition, StateNodeConfig, StateSchema, StateNodesConfig, InvokeDefinition, ActionObject, Mapper, PropertyMapper, SCXML, Typestate, TransitionDefinitionMap, MachineSchema } from './types';
|
|
1
|
+
import { Event, StateValue, StateTransition, MachineOptions, EventObject, HistoryValue, StateNodeDefinition, TransitionDefinition, DelayedTransitionDefinition, ActivityDefinition, StateNodeConfig, StateSchema, StateNodesConfig, InvokeDefinition, ActionObject, Mapper, PropertyMapper, SCXML, Typestate, TransitionDefinitionMap, MachineSchema, InternalMachineOptions, ServiceMap, StateConfig } from './types';
|
|
2
2
|
import { State } from './State';
|
|
3
|
+
import { TypegenDisabled } from './typegenTypes';
|
|
3
4
|
declare class StateNode<TContext = any, TStateSchema extends StateSchema = any, TEvent extends EventObject = EventObject, TTypestate extends Typestate<TContext> = {
|
|
4
5
|
value: any;
|
|
5
6
|
context: TContext;
|
|
6
|
-
}> {
|
|
7
|
+
}, TServiceMap extends ServiceMap = ServiceMap, TResolvedTypesMeta = TypegenDisabled> {
|
|
7
8
|
/**
|
|
8
9
|
* The raw config used to create the machine.
|
|
9
10
|
*/
|
|
@@ -81,7 +82,7 @@ declare class StateNode<TContext = any, TStateSchema extends StateSchema = any,
|
|
|
81
82
|
/**
|
|
82
83
|
* The parent state node.
|
|
83
84
|
*/
|
|
84
|
-
parent?: StateNode<TContext, any, TEvent, any>;
|
|
85
|
+
parent?: StateNode<TContext, any, TEvent, any, any, any>;
|
|
85
86
|
/**
|
|
86
87
|
* The root machine node.
|
|
87
88
|
*/
|
|
@@ -119,11 +120,15 @@ declare class StateNode<TContext = any, TStateSchema extends StateSchema = any,
|
|
|
119
120
|
/**
|
|
120
121
|
* The raw config used to create the machine.
|
|
121
122
|
*/
|
|
122
|
-
config: StateNodeConfig<TContext, TStateSchema, TEvent>, options?:
|
|
123
|
+
config: StateNodeConfig<TContext, TStateSchema, TEvent>, options?: MachineOptions<TContext, TEvent>,
|
|
123
124
|
/**
|
|
124
125
|
* The initial extended state
|
|
125
126
|
*/
|
|
126
|
-
_context?: Readonly<TContext> | (() => Readonly<TContext>)
|
|
127
|
+
_context?: Readonly<TContext> | (() => Readonly<TContext>), // TODO: this is unsafe, but we're removing it in v5 anyway
|
|
128
|
+
_stateInfo?: {
|
|
129
|
+
parent: StateNode<any, any, any, any, any, any>;
|
|
130
|
+
key: string;
|
|
131
|
+
});
|
|
127
132
|
private _init;
|
|
128
133
|
/**
|
|
129
134
|
* Clones this state machine with custom options and context.
|
|
@@ -131,7 +136,7 @@ declare class StateNode<TContext = any, TStateSchema extends StateSchema = any,
|
|
|
131
136
|
* @param options Options (actions, guards, activities, services) to recursively merge with the existing options.
|
|
132
137
|
* @param context Custom context (will override predefined context)
|
|
133
138
|
*/
|
|
134
|
-
withConfig(options:
|
|
139
|
+
withConfig(options: InternalMachineOptions<TContext, TEvent, TResolvedTypesMeta, true>, context?: TContext | (() => TContext)): StateNode<TContext, TStateSchema, TEvent, TTypestate, TServiceMap, TResolvedTypesMeta>;
|
|
135
140
|
/**
|
|
136
141
|
* Clones this state machine with custom context.
|
|
137
142
|
*
|
|
@@ -163,7 +168,7 @@ declare class StateNode<TContext = any, TStateSchema extends StateSchema = any,
|
|
|
163
168
|
*
|
|
164
169
|
* @param state The state value or State instance
|
|
165
170
|
*/
|
|
166
|
-
getStateNodes(state: StateValue | State<TContext, TEvent, any, TTypestate>): Array<StateNode<TContext, any, TEvent, TTypestate>>;
|
|
171
|
+
getStateNodes(state: StateValue | State<TContext, TEvent, any, TTypestate, TResolvedTypesMeta>): Array<StateNode<TContext, any, TEvent, TTypestate, TServiceMap, TResolvedTypesMeta>>;
|
|
167
172
|
/**
|
|
168
173
|
* Returns `true` if this state node explicitly handles the given event.
|
|
169
174
|
*
|
|
@@ -177,12 +182,12 @@ declare class StateNode<TContext = any, TStateSchema extends StateSchema = any,
|
|
|
177
182
|
*
|
|
178
183
|
* @param state The state to resolve
|
|
179
184
|
*/
|
|
180
|
-
resolveState(state: State<TContext, TEvent, any, any>): State<TContext, TEvent, TStateSchema, TTypestate>;
|
|
185
|
+
resolveState(state: State<TContext, TEvent, any, any> | StateConfig<TContext, TEvent>): State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>;
|
|
181
186
|
private transitionLeafNode;
|
|
182
187
|
private transitionCompoundNode;
|
|
183
188
|
private transitionParallelNode;
|
|
184
189
|
private _transition;
|
|
185
|
-
getTransitionData(state: State<TContext, TEvent, any, any>, event: Event<TEvent> | SCXML.Event<TEvent>): StateTransition<TContext, TEvent> | undefined;
|
|
190
|
+
getTransitionData(state: State<TContext, TEvent, any, any, any>, event: Event<TEvent> | SCXML.Event<TEvent>): StateTransition<TContext, TEvent> | undefined;
|
|
186
191
|
private next;
|
|
187
192
|
private nodesFromChild;
|
|
188
193
|
/**
|
|
@@ -198,25 +203,25 @@ declare class StateNode<TContext = any, TStateSchema extends StateSchema = any,
|
|
|
198
203
|
* @param event The event that was sent at the current state
|
|
199
204
|
* @param context The current context (extended state) of the current state
|
|
200
205
|
*/
|
|
201
|
-
transition(state: StateValue | State<TContext, TEvent, any, TTypestate> | undefined, event: Event<TEvent> | SCXML.Event<TEvent>, context?: TContext): State<TContext, TEvent, TStateSchema, TTypestate>;
|
|
206
|
+
transition(state: StateValue | State<TContext, TEvent, any, TTypestate, TResolvedTypesMeta> | undefined, event: Event<TEvent> | SCXML.Event<TEvent>, context?: TContext): State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>;
|
|
202
207
|
private resolveRaisedTransition;
|
|
203
208
|
private resolveTransition;
|
|
204
209
|
/**
|
|
205
210
|
* Returns the child state node from its relative `stateKey`, or throws.
|
|
206
211
|
*/
|
|
207
|
-
getStateNode(stateKey: string): StateNode<TContext, any, TEvent, TTypestate>;
|
|
212
|
+
getStateNode(stateKey: string): StateNode<TContext, any, TEvent, TTypestate, TServiceMap, TResolvedTypesMeta>;
|
|
208
213
|
/**
|
|
209
214
|
* Returns the state node with the given `stateId`, or throws.
|
|
210
215
|
*
|
|
211
216
|
* @param stateId The state ID. The prefix "#" is removed.
|
|
212
217
|
*/
|
|
213
|
-
getStateNodeById(stateId: string): StateNode<TContext, any, TEvent, any>;
|
|
218
|
+
getStateNodeById(stateId: string): StateNode<TContext, any, TEvent, any, TServiceMap, TResolvedTypesMeta>;
|
|
214
219
|
/**
|
|
215
220
|
* Returns the relative state node from the given `statePath`, or throws.
|
|
216
221
|
*
|
|
217
222
|
* @param statePath The string or string array relative path to the state node.
|
|
218
223
|
*/
|
|
219
|
-
getStateNodeByPath(statePath: string | string[]): StateNode<TContext, any, TEvent, any>;
|
|
224
|
+
getStateNodeByPath(statePath: string | string[]): StateNode<TContext, any, TEvent, any, any, any>;
|
|
220
225
|
/**
|
|
221
226
|
* Resolves a partial state value with its full representation in this machine.
|
|
222
227
|
*
|
|
@@ -225,12 +230,12 @@ declare class StateNode<TContext = any, TStateSchema extends StateSchema = any,
|
|
|
225
230
|
resolve(stateValue: StateValue): StateValue;
|
|
226
231
|
private getResolvedPath;
|
|
227
232
|
private get initialStateValue();
|
|
228
|
-
getInitialState(stateValue: StateValue, context?: TContext): State<TContext, TEvent, TStateSchema, TTypestate>;
|
|
233
|
+
getInitialState(stateValue: StateValue, context?: TContext): State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>;
|
|
229
234
|
/**
|
|
230
235
|
* The initial State instance, which includes all actions to be executed from
|
|
231
236
|
* entering the initial state.
|
|
232
237
|
*/
|
|
233
|
-
get initialState(): State<TContext, TEvent, TStateSchema, TTypestate>;
|
|
238
|
+
get initialState(): State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>;
|
|
234
239
|
/**
|
|
235
240
|
* The target state value of the history state node, if it exists. This represents the
|
|
236
241
|
* default state value to transition to if no history value exists yet.
|
|
@@ -244,14 +249,14 @@ declare class StateNode<TContext = any, TStateSchema extends StateSchema = any,
|
|
|
244
249
|
* @param resolve Whether state nodes should resolve to initial child state nodes
|
|
245
250
|
*/
|
|
246
251
|
getRelativeStateNodes(relativeStateId: StateNode<TContext, any, TEvent>, historyValue?: HistoryValue, resolve?: boolean): Array<StateNode<TContext, any, TEvent>>;
|
|
247
|
-
get initialStateNodes(): Array<StateNode<TContext, any, TEvent, any>>;
|
|
252
|
+
get initialStateNodes(): Array<StateNode<TContext, any, TEvent, any, any, any>>;
|
|
248
253
|
/**
|
|
249
254
|
* Retrieves state nodes from a relative path to this state node.
|
|
250
255
|
*
|
|
251
256
|
* @param relativePath The relative path from this state node
|
|
252
257
|
* @param historyValue
|
|
253
258
|
*/
|
|
254
|
-
getFromRelativePath(relativePath: string[]): Array<StateNode<TContext, any, TEvent, any>>;
|
|
259
|
+
getFromRelativePath(relativePath: string[]): Array<StateNode<TContext, any, TEvent, any, any, any>>;
|
|
255
260
|
private historyValue;
|
|
256
261
|
/**
|
|
257
262
|
* Resolves to the historical value(s) of the parent state node,
|
package/lib/StateNode.js
CHANGED
|
@@ -54,8 +54,8 @@ function () {
|
|
|
54
54
|
/**
|
|
55
55
|
* The initial extended state
|
|
56
56
|
*/
|
|
57
|
-
_context // TODO: this is unsafe, but we're removing it in v5 anyway
|
|
58
|
-
) {
|
|
57
|
+
_context, // TODO: this is unsafe, but we're removing it in v5 anyway
|
|
58
|
+
_stateInfo) {
|
|
59
59
|
var _this = this;
|
|
60
60
|
|
|
61
61
|
if (_context === void 0) {
|
|
@@ -85,8 +85,8 @@ function () {
|
|
|
85
85
|
this.idMap = {};
|
|
86
86
|
this.tags = [];
|
|
87
87
|
this.options = Object.assign(createDefaultOptions(), options);
|
|
88
|
-
this.parent =
|
|
89
|
-
this.key = this.config.key ||
|
|
88
|
+
this.parent = _stateInfo === null || _stateInfo === void 0 ? void 0 : _stateInfo.parent;
|
|
89
|
+
this.key = this.config.key || (_stateInfo === null || _stateInfo === void 0 ? void 0 : _stateInfo.key) || this.config.id || '(machine)';
|
|
90
90
|
this.machine = this.parent ? this.parent.machine : this;
|
|
91
91
|
this.path = this.parent ? this.parent.path.concat(this.key) : [];
|
|
92
92
|
this.delimiter = this.config.delimiter || (this.parent ? this.parent.delimiter : constants.STATE_DELIMITER);
|
|
@@ -104,9 +104,9 @@ function () {
|
|
|
104
104
|
this.states = this.config.states ? utils.mapValues(this.config.states, function (stateConfig, key) {
|
|
105
105
|
var _a;
|
|
106
106
|
|
|
107
|
-
var stateNode = new StateNode(stateConfig, {
|
|
108
|
-
|
|
109
|
-
|
|
107
|
+
var stateNode = new StateNode(stateConfig, {}, undefined, {
|
|
108
|
+
parent: _this,
|
|
109
|
+
key: key
|
|
110
110
|
});
|
|
111
111
|
Object.assign(_this.idMap, _tslib.__assign((_a = {}, _a[stateNode.id] = stateNode, _a), stateNode.idMap));
|
|
112
112
|
return stateNode;
|
|
@@ -441,9 +441,10 @@ function () {
|
|
|
441
441
|
|
|
442
442
|
|
|
443
443
|
StateNode.prototype.resolveState = function (state) {
|
|
444
|
-
var
|
|
445
|
-
|
|
446
|
-
|
|
444
|
+
var stateFromConfig = state instanceof State.State ? state : State.State.create(state);
|
|
445
|
+
var configuration = Array.from(stateUtils.getConfiguration([], this.getStateNodes(stateFromConfig.value)));
|
|
446
|
+
return new State.State(_tslib.__assign(_tslib.__assign({}, stateFromConfig), {
|
|
447
|
+
value: this.resolve(stateFromConfig.value),
|
|
447
448
|
configuration: configuration,
|
|
448
449
|
done: stateUtils.isInFinalState(configuration, this),
|
|
449
450
|
tags: stateUtils.getTagsFromConfiguration(configuration)
|
|
@@ -1145,6 +1146,9 @@ function () {
|
|
|
1145
1146
|
});
|
|
1146
1147
|
|
|
1147
1148
|
StateNode.prototype.getInitialState = function (stateValue, context) {
|
|
1149
|
+
this._init(); // TODO: this should be in the constructor (see note in constructor)
|
|
1150
|
+
|
|
1151
|
+
|
|
1148
1152
|
var configuration = this.getStateNodes(stateValue);
|
|
1149
1153
|
return this.resolveTransition({
|
|
1150
1154
|
configuration: configuration,
|
|
@@ -1162,9 +1166,6 @@ function () {
|
|
|
1162
1166
|
* entering the initial state.
|
|
1163
1167
|
*/
|
|
1164
1168
|
get: function () {
|
|
1165
|
-
this._init(); // TODO: this should be in the constructor (see note in constructor)
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
1169
|
var initialStateValue = this.initialStateValue;
|
|
1169
1170
|
|
|
1170
1171
|
if (!initialStateValue) {
|
package/lib/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/lib/actions.js
CHANGED
|
@@ -292,6 +292,9 @@ var assign = function (assignment) {
|
|
|
292
292
|
assignment: assignment
|
|
293
293
|
};
|
|
294
294
|
};
|
|
295
|
+
function isActionObject(action) {
|
|
296
|
+
return typeof action === 'object' && 'type' in action;
|
|
297
|
+
}
|
|
295
298
|
/**
|
|
296
299
|
* Returns an event type that represents an implicit event that
|
|
297
300
|
* is sent after the specified `delay`.
|
|
@@ -516,6 +519,7 @@ function resolveActions(machine, currentState, currentContext, _event, actions,
|
|
|
516
519
|
return [resolvedActions, updatedContext];
|
|
517
520
|
}
|
|
518
521
|
|
|
522
|
+
exports.actionTypes = actionTypes;
|
|
519
523
|
exports.after = after;
|
|
520
524
|
exports.assign = assign;
|
|
521
525
|
exports.cancel = cancel;
|
|
@@ -527,6 +531,7 @@ exports.escalate = escalate;
|
|
|
527
531
|
exports.forwardTo = forwardTo;
|
|
528
532
|
exports.getActionFunction = getActionFunction;
|
|
529
533
|
exports.initEvent = initEvent;
|
|
534
|
+
exports.isActionObject = isActionObject;
|
|
530
535
|
exports.log = log;
|
|
531
536
|
exports.pure = pure;
|
|
532
537
|
exports.raise = raise;
|
package/lib/behaviors.d.ts
CHANGED
package/lib/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/lib/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/lib/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/lib/index.js
CHANGED
|
@@ -5,33 +5,21 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var utils = require('./utils.js');
|
|
6
6
|
var mapState = require('./mapState.js');
|
|
7
7
|
var types = require('./types.js');
|
|
8
|
-
var actions
|
|
8
|
+
var actions = require('./actions.js');
|
|
9
9
|
var State = require('./State.js');
|
|
10
|
+
var Actor = require('./Actor.js');
|
|
10
11
|
var StateNode = require('./StateNode.js');
|
|
11
12
|
var Machine = require('./Machine.js');
|
|
12
13
|
var interpreter = require('./interpreter.js');
|
|
13
14
|
var match = require('./match.js');
|
|
14
15
|
var schema = require('./schema.js');
|
|
15
16
|
|
|
16
|
-
var
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
log: actions$1.log,
|
|
23
|
-
cancel: actions$1.cancel,
|
|
24
|
-
start: actions$1.start,
|
|
25
|
-
stop: actions$1.stop,
|
|
26
|
-
assign: actions$1.assign,
|
|
27
|
-
after: actions$1.after,
|
|
28
|
-
done: actions$1.done,
|
|
29
|
-
respond: actions$1.respond,
|
|
30
|
-
forwardTo: actions$1.forwardTo,
|
|
31
|
-
escalate: actions$1.escalate,
|
|
32
|
-
choose: actions$1.choose,
|
|
33
|
-
pure: actions$1.pure
|
|
34
|
-
};
|
|
17
|
+
var assign = actions.assign,
|
|
18
|
+
send = actions.send,
|
|
19
|
+
sendParent = actions.sendParent,
|
|
20
|
+
sendUpdate = actions.sendUpdate,
|
|
21
|
+
forwardTo = actions.forwardTo,
|
|
22
|
+
doneInvoke = actions.doneInvoke;
|
|
35
23
|
|
|
36
24
|
exports.matchesState = utils.matchesState;
|
|
37
25
|
exports.mapState = mapState.mapState;
|
|
@@ -47,13 +35,9 @@ Object.defineProperty(exports, 'SpecialTargets', {
|
|
|
47
35
|
return types.SpecialTargets;
|
|
48
36
|
}
|
|
49
37
|
});
|
|
50
|
-
exports.
|
|
51
|
-
exports.doneInvoke = actions$1.doneInvoke;
|
|
52
|
-
exports.forwardTo = actions$1.forwardTo;
|
|
53
|
-
exports.send = actions$1.send;
|
|
54
|
-
exports.sendParent = actions$1.sendParent;
|
|
55
|
-
exports.sendUpdate = actions$1.sendUpdate;
|
|
38
|
+
exports.actions = actions;
|
|
56
39
|
exports.State = State.State;
|
|
40
|
+
exports.toActorRef = Actor.toActorRef;
|
|
57
41
|
exports.StateNode = StateNode.StateNode;
|
|
58
42
|
exports.Machine = Machine.Machine;
|
|
59
43
|
exports.createMachine = Machine.createMachine;
|
|
@@ -68,4 +52,10 @@ exports.interpret = interpreter.interpret;
|
|
|
68
52
|
exports.spawn = interpreter.spawn;
|
|
69
53
|
exports.matchState = match.matchState;
|
|
70
54
|
exports.createSchema = schema.createSchema;
|
|
71
|
-
exports.
|
|
55
|
+
exports.t = schema.t;
|
|
56
|
+
exports.assign = assign;
|
|
57
|
+
exports.doneInvoke = doneInvoke;
|
|
58
|
+
exports.forwardTo = forwardTo;
|
|
59
|
+
exports.send = send;
|
|
60
|
+
exports.sendParent = sendParent;
|
|
61
|
+
exports.sendUpdate = sendUpdate;
|