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/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/lib/interpreter.js
CHANGED
|
@@ -462,7 +462,7 @@ function () {
|
|
|
462
462
|
this.initialized = true;
|
|
463
463
|
this.status = exports.InterpreterStatus.Running;
|
|
464
464
|
var resolvedState = initialState === undefined ? this.initialState : serviceScope.provide(this, function () {
|
|
465
|
-
return State.
|
|
465
|
+
return State.isStateConfig(initialState) ? _this.machine.resolveState(initialState) : _this.machine.resolveState(State.State.from(initialState, _this.machine.context));
|
|
466
466
|
});
|
|
467
467
|
|
|
468
468
|
if (this.options.devTools) {
|
|
@@ -1000,6 +1000,8 @@ function () {
|
|
|
1000
1000
|
};
|
|
1001
1001
|
|
|
1002
1002
|
Interpreter.prototype.spawnPromise = function (promise, id) {
|
|
1003
|
+
var _a;
|
|
1004
|
+
|
|
1003
1005
|
var _this = this;
|
|
1004
1006
|
|
|
1005
1007
|
var canceled = false;
|
|
@@ -1042,8 +1044,7 @@ function () {
|
|
|
1042
1044
|
}
|
|
1043
1045
|
}
|
|
1044
1046
|
});
|
|
1045
|
-
|
|
1046
|
-
var actor = _tslib.__assign({
|
|
1047
|
+
var actor = (_a = {
|
|
1047
1048
|
id: id,
|
|
1048
1049
|
send: function () {
|
|
1049
1050
|
return void 0;
|
|
@@ -1087,13 +1088,16 @@ function () {
|
|
|
1087
1088
|
getSnapshot: function () {
|
|
1088
1089
|
return resolvedData;
|
|
1089
1090
|
}
|
|
1090
|
-
}, utils.
|
|
1091
|
-
|
|
1091
|
+
}, _a[utils.symbolObservable] = function () {
|
|
1092
|
+
return this;
|
|
1093
|
+
}, _a);
|
|
1092
1094
|
this.children.set(id, actor);
|
|
1093
1095
|
return actor;
|
|
1094
1096
|
};
|
|
1095
1097
|
|
|
1096
1098
|
Interpreter.prototype.spawnCallback = function (callback, id) {
|
|
1099
|
+
var _a;
|
|
1100
|
+
|
|
1097
1101
|
var _this = this;
|
|
1098
1102
|
|
|
1099
1103
|
var canceled = false;
|
|
@@ -1132,7 +1136,7 @@ function () {
|
|
|
1132
1136
|
return this.spawnPromise(callbackStop, id);
|
|
1133
1137
|
}
|
|
1134
1138
|
|
|
1135
|
-
var actor =
|
|
1139
|
+
var actor = (_a = {
|
|
1136
1140
|
id: id,
|
|
1137
1141
|
send: function (event) {
|
|
1138
1142
|
return receivers.forEach(function (receiver) {
|
|
@@ -1140,10 +1144,11 @@ function () {
|
|
|
1140
1144
|
});
|
|
1141
1145
|
},
|
|
1142
1146
|
subscribe: function (next) {
|
|
1143
|
-
|
|
1147
|
+
var observer = utils.toObserver(next);
|
|
1148
|
+
listeners.add(observer.next);
|
|
1144
1149
|
return {
|
|
1145
1150
|
unsubscribe: function () {
|
|
1146
|
-
listeners.delete(next);
|
|
1151
|
+
listeners.delete(observer.next);
|
|
1147
1152
|
}
|
|
1148
1153
|
};
|
|
1149
1154
|
},
|
|
@@ -1162,13 +1167,16 @@ function () {
|
|
|
1162
1167
|
getSnapshot: function () {
|
|
1163
1168
|
return emitted;
|
|
1164
1169
|
}
|
|
1165
|
-
}, utils.
|
|
1166
|
-
|
|
1170
|
+
}, _a[utils.symbolObservable] = function () {
|
|
1171
|
+
return this;
|
|
1172
|
+
}, _a);
|
|
1167
1173
|
this.children.set(id, actor);
|
|
1168
1174
|
return actor;
|
|
1169
1175
|
};
|
|
1170
1176
|
|
|
1171
1177
|
Interpreter.prototype.spawnObservable = function (source, id) {
|
|
1178
|
+
var _a;
|
|
1179
|
+
|
|
1172
1180
|
var _this = this;
|
|
1173
1181
|
|
|
1174
1182
|
var emitted;
|
|
@@ -1191,8 +1199,7 @@ function () {
|
|
|
1191
1199
|
origin: id
|
|
1192
1200
|
}));
|
|
1193
1201
|
});
|
|
1194
|
-
|
|
1195
|
-
var actor = _tslib.__assign({
|
|
1202
|
+
var actor = (_a = {
|
|
1196
1203
|
id: id,
|
|
1197
1204
|
send: function () {
|
|
1198
1205
|
return void 0;
|
|
@@ -1211,8 +1218,9 @@ function () {
|
|
|
1211
1218
|
id: id
|
|
1212
1219
|
};
|
|
1213
1220
|
}
|
|
1214
|
-
}, utils.
|
|
1215
|
-
|
|
1221
|
+
}, _a[utils.symbolObservable] = function () {
|
|
1222
|
+
return this;
|
|
1223
|
+
}, _a);
|
|
1216
1224
|
this.children.set(id, actor);
|
|
1217
1225
|
return actor;
|
|
1218
1226
|
};
|
|
@@ -1240,7 +1248,9 @@ function () {
|
|
|
1240
1248
|
};
|
|
1241
1249
|
|
|
1242
1250
|
Interpreter.prototype.spawnEffect = function (id, dispose) {
|
|
1243
|
-
|
|
1251
|
+
var _a;
|
|
1252
|
+
|
|
1253
|
+
this.children.set(id, (_a = {
|
|
1244
1254
|
id: id,
|
|
1245
1255
|
send: function () {
|
|
1246
1256
|
return void 0;
|
|
@@ -1261,7 +1271,9 @@ function () {
|
|
|
1261
1271
|
id: id
|
|
1262
1272
|
};
|
|
1263
1273
|
}
|
|
1264
|
-
}, utils.
|
|
1274
|
+
}, _a[utils.symbolObservable] = function () {
|
|
1275
|
+
return this;
|
|
1276
|
+
}, _a));
|
|
1265
1277
|
};
|
|
1266
1278
|
|
|
1267
1279
|
Interpreter.prototype.attachDev = function () {
|
|
@@ -1302,9 +1314,7 @@ function () {
|
|
|
1302
1314
|
|
|
1303
1315
|
Interpreter.prototype[utils.symbolObservable] = function () {
|
|
1304
1316
|
return this;
|
|
1305
|
-
};
|
|
1306
|
-
// it has to be here to be included in the generated .d.ts
|
|
1307
|
-
|
|
1317
|
+
};
|
|
1308
1318
|
|
|
1309
1319
|
Interpreter.prototype.getSnapshot = function () {
|
|
1310
1320
|
if (this.status === exports.InterpreterStatus.NotStarted) {
|
package/lib/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/lib/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/lib/schema.d.ts
CHANGED
package/lib/schema.js
CHANGED
package/lib/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
|
package/lib/stateUtils.d.ts
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import { EventObject,
|
|
1
|
+
import { EventObject, StateValue } from './types';
|
|
2
|
+
import { StateNode } from './StateNode';
|
|
2
3
|
declare type Configuration<TC, TE extends EventObject> = Iterable<StateNode<TC, any, TE>>;
|
|
3
4
|
declare type AdjList<TC, TE extends EventObject> = Map<StateNode<TC, any, TE>, Array<StateNode<TC, any, TE>>>;
|
|
4
|
-
export declare const isLeafNode: (stateNode: StateNode<any, any, any, any>) => boolean;
|
|
5
|
+
export declare const isLeafNode: (stateNode: StateNode<any, any, any, any, any, any>) => boolean;
|
|
5
6
|
export declare function getChildren<TC, TE extends EventObject>(stateNode: StateNode<TC, any, TE>): Array<StateNode<TC, any, TE>>;
|
|
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>>): Set<StateNode<TC, any, TE, any>>;
|
|
7
|
+
export declare function getAllStateNodes<TC, TE extends EventObject>(stateNode: StateNode<TC, any, TE, any, any, any>): Array<StateNode<TC, any, TE, any, any, any>>;
|
|
8
|
+
export declare function getConfiguration<TC, TE extends EventObject>(prevStateNodes: Iterable<StateNode<TC, any, TE, any, any, any>>, stateNodes: Iterable<StateNode<TC, any, TE, any, any, any>>): Set<StateNode<TC, any, TE, any, any, any>>;
|
|
8
9
|
export declare function getAdjList<TC, TE extends EventObject>(configuration: Configuration<TC, TE>): AdjList<TC, TE>;
|
|
9
10
|
export declare function getValue<TC, TE extends EventObject>(rootNode: StateNode<TC, any, TE, any>, configuration: Configuration<TC, TE>): StateValue;
|
|
10
11
|
export declare function has<T>(iterable: Iterable<T>, item: T): boolean;
|
|
11
12
|
export declare function nextEvents<TC, TE extends EventObject>(configuration: Array<StateNode<TC, any, TE>>): Array<TE['type']>;
|
|
12
|
-
export declare function isInFinalState<TC, TE extends EventObject>(configuration: Array<StateNode<TC, any, TE, any>>, stateNode: StateNode<TC, any, TE, any>): boolean;
|
|
13
|
+
export declare function isInFinalState<TC, TE extends EventObject>(configuration: Array<StateNode<TC, any, TE, any, any, any>>, stateNode: StateNode<TC, any, TE, any, any, any>): boolean;
|
|
13
14
|
export declare function getMeta(configuration?: StateNode[]): Record<string, any>;
|
|
14
15
|
export declare function getTagsFromConfiguration(configuration: StateNode<any, any, any, any>[]): Set<string>;
|
|
15
16
|
export {};
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { BaseActionObject, EventObject, IndexByType, IsNever, Prop, Values, IsAny, ServiceMap, Cast } from './types';
|
|
2
|
+
export interface TypegenDisabled {
|
|
3
|
+
'@@xstate/typegen': false;
|
|
4
|
+
}
|
|
5
|
+
export interface TypegenEnabled {
|
|
6
|
+
'@@xstate/typegen': true;
|
|
7
|
+
}
|
|
8
|
+
export interface TypegenMeta extends TypegenEnabled {
|
|
9
|
+
/**
|
|
10
|
+
* Allows you to specify all the results of state.matches
|
|
11
|
+
*/
|
|
12
|
+
matchesStates: string | {};
|
|
13
|
+
/**
|
|
14
|
+
* Allows you to specify all tags used by the machine
|
|
15
|
+
*/
|
|
16
|
+
tags: string;
|
|
17
|
+
/**
|
|
18
|
+
* Allows you to specify all the missing implementations
|
|
19
|
+
* of the machine
|
|
20
|
+
*/
|
|
21
|
+
missingImplementations: {
|
|
22
|
+
actions: string;
|
|
23
|
+
delays: string;
|
|
24
|
+
guards: string;
|
|
25
|
+
services: string;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* A map for the internal events of the machine.
|
|
29
|
+
*
|
|
30
|
+
* key: 'done.invoke.myService'
|
|
31
|
+
* value: {
|
|
32
|
+
* type: 'done.invoke.myService';
|
|
33
|
+
* data: unknown;
|
|
34
|
+
* __tip: 'Declare the type in event types!';
|
|
35
|
+
* }
|
|
36
|
+
*/
|
|
37
|
+
internalEvents: {};
|
|
38
|
+
/**
|
|
39
|
+
* Maps the name of the service to the event type
|
|
40
|
+
* of the done.invoke action
|
|
41
|
+
*
|
|
42
|
+
* key: 'invokeSrc'
|
|
43
|
+
* value: 'done.invoke.invokeName'
|
|
44
|
+
*/
|
|
45
|
+
invokeSrcNameMap: Record<string, string>;
|
|
46
|
+
/**
|
|
47
|
+
* Keeps track of which events lead to which
|
|
48
|
+
* actions.
|
|
49
|
+
*
|
|
50
|
+
* Key: 'EVENT_NAME'
|
|
51
|
+
* Value: 'actionName' | 'otherActionName'
|
|
52
|
+
*/
|
|
53
|
+
eventsCausingActions: Record<string, string>;
|
|
54
|
+
/**
|
|
55
|
+
* Keeps track of which events lead to which
|
|
56
|
+
* delays.
|
|
57
|
+
*
|
|
58
|
+
* Key: 'EVENT_NAME'
|
|
59
|
+
* Value: 'delayName' | 'otherDelayName'
|
|
60
|
+
*/
|
|
61
|
+
eventsCausingDelays: Record<string, string>;
|
|
62
|
+
/**
|
|
63
|
+
* Keeps track of which events lead to which
|
|
64
|
+
* guards.
|
|
65
|
+
*
|
|
66
|
+
* Key: 'EVENT_NAME'
|
|
67
|
+
* Value: 'guardName' | 'otherGuardName'
|
|
68
|
+
*/
|
|
69
|
+
eventsCausingGuards: Record<string, string>;
|
|
70
|
+
/**
|
|
71
|
+
* Keeps track of which events lead to which
|
|
72
|
+
* services.
|
|
73
|
+
*
|
|
74
|
+
* Key: 'EVENT_NAME'
|
|
75
|
+
* Value: 'serviceName' | 'otherServiceName'
|
|
76
|
+
*/
|
|
77
|
+
eventsCausingServices: Record<string, string>;
|
|
78
|
+
}
|
|
79
|
+
export interface ResolvedTypegenMeta extends TypegenMeta {
|
|
80
|
+
indexedActions: Record<string, BaseActionObject>;
|
|
81
|
+
indexedEvents: Record<string, EventObject>;
|
|
82
|
+
}
|
|
83
|
+
export declare type TypegenConstraint = TypegenEnabled | TypegenDisabled;
|
|
84
|
+
export declare type AreAllImplementationsAssumedToBeProvided<TResolvedTypesMeta, TMissingImplementations = Prop<TResolvedTypesMeta, 'missingImplementations'>> = IsAny<TResolvedTypesMeta> extends true ? true : TResolvedTypesMeta extends TypegenEnabled ? IsNever<Values<{
|
|
85
|
+
[K in keyof TMissingImplementations]: TMissingImplementations[K];
|
|
86
|
+
}>> extends true ? true : false : true;
|
|
87
|
+
export declare type MarkAllImplementationsAsProvided<TResolvedTypesMeta> = TResolvedTypesMeta & {
|
|
88
|
+
missingImplementations: {
|
|
89
|
+
actions: never;
|
|
90
|
+
delays: never;
|
|
91
|
+
guards: never;
|
|
92
|
+
services: never;
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
declare type GenerateServiceEvent<TServiceName, TEventType, TServiceMap extends ServiceMap> = TEventType extends any ? {
|
|
96
|
+
type: TEventType;
|
|
97
|
+
} & Prop<TServiceMap, TServiceName> : never;
|
|
98
|
+
declare type GenerateServiceEvents<TServiceMap extends ServiceMap, TInvokeSrcNameMap> = string extends keyof TServiceMap ? never : Cast<{
|
|
99
|
+
[K in keyof TInvokeSrcNameMap]: GenerateServiceEvent<K, TInvokeSrcNameMap[K], TServiceMap>;
|
|
100
|
+
}[keyof TInvokeSrcNameMap], EventObject>;
|
|
101
|
+
declare type MergeWithInternalEvents<TIndexedEvents, TInternalEvents> = TIndexedEvents & Pick<TInternalEvents, Exclude<keyof TInternalEvents, keyof TIndexedEvents>>;
|
|
102
|
+
declare type AllowAllEvents = {
|
|
103
|
+
eventsCausingActions: Record<string, string>;
|
|
104
|
+
eventsCausingDelays: Record<string, string>;
|
|
105
|
+
eventsCausingGuards: Record<string, string>;
|
|
106
|
+
eventsCausingServices: Record<string, string>;
|
|
107
|
+
};
|
|
108
|
+
export declare type ResolveTypegenMeta<TTypesMeta extends TypegenConstraint, TEvent extends EventObject, TAction extends BaseActionObject, TServiceMap extends ServiceMap> = TTypesMeta extends TypegenEnabled ? TTypesMeta & {
|
|
109
|
+
indexedActions: IndexByType<TAction>;
|
|
110
|
+
indexedEvents: MergeWithInternalEvents<IndexByType<(string extends TEvent['type'] ? never : TEvent) | GenerateServiceEvents<TServiceMap, Prop<TTypesMeta, 'invokeSrcNameMap'>>>, Prop<TTypesMeta, 'internalEvents'>>;
|
|
111
|
+
} : MarkAllImplementationsAsProvided<TypegenDisabled> & AllowAllEvents & {
|
|
112
|
+
indexedActions: IndexByType<TAction>;
|
|
113
|
+
indexedEvents: Record<string, TEvent> & {
|
|
114
|
+
__XSTATE_ALLOW_ANY_INVOKE_DATA_HACK__: {
|
|
115
|
+
data: any;
|
|
116
|
+
};
|
|
117
|
+
};
|
|
118
|
+
invokeSrcNameMap: Record<string, '__XSTATE_ALLOW_ANY_INVOKE_DATA_HACK__'>;
|
|
119
|
+
};
|
|
120
|
+
export {};
|
|
121
|
+
//# sourceMappingURL=typegenTypes.d.ts.map
|