xstate 5.8.2 → 5.9.1
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/actions/dist/xstate-actions.cjs.js +3 -2
- package/actions/dist/xstate-actions.cjs.mjs +1 -0
- package/actions/dist/xstate-actions.development.cjs.js +3 -2
- package/actions/dist/xstate-actions.development.cjs.mjs +1 -0
- package/actions/dist/xstate-actions.development.esm.js +2 -2
- package/actions/dist/xstate-actions.esm.js +2 -2
- package/actions/dist/xstate-actions.umd.min.js +1 -1
- package/actions/dist/xstate-actions.umd.min.js.map +1 -1
- package/actors/dist/xstate-actors.cjs.js +1 -1
- package/actors/dist/xstate-actors.development.cjs.js +1 -1
- package/actors/dist/xstate-actors.development.esm.js +1 -1
- package/actors/dist/xstate-actors.esm.js +1 -1
- package/actors/dist/xstate-actors.umd.min.js +1 -1
- package/actors/dist/xstate-actors.umd.min.js.map +1 -1
- package/dist/declarations/src/State.d.ts +1 -1
- package/dist/declarations/src/StateMachine.d.ts +6 -5
- package/dist/declarations/src/StateNode.d.ts +9 -6
- package/dist/declarations/src/actions/assign.d.ts +1 -1
- package/dist/declarations/src/actions/emit.d.ts +44 -0
- package/dist/declarations/src/actions/enqueueActions.d.ts +10 -8
- package/dist/declarations/src/actions/raise.d.ts +1 -1
- package/dist/declarations/src/actions/send.d.ts +5 -5
- package/dist/declarations/src/actions/spawnChild.d.ts +1 -1
- package/dist/declarations/src/actions/stopChild.d.ts +2 -2
- package/dist/declarations/src/actions.d.ts +1 -0
- package/dist/declarations/src/actors/callback.d.ts +1 -1
- package/dist/declarations/src/actors/observable.d.ts +1 -1
- package/dist/declarations/src/actors/promise.d.ts +2 -2
- package/dist/declarations/src/actors/transition.d.ts +3 -3
- package/dist/declarations/src/createActor.d.ts +8 -4
- package/dist/declarations/src/createMachine.d.ts +4 -4
- package/dist/declarations/src/setup.d.ts +5 -5
- package/dist/declarations/src/typegenTypes.d.ts +3 -1
- package/dist/declarations/src/types.d.ts +77 -66
- package/dist/declarations/src/utils.d.ts +2 -2
- package/dist/declarations/src/waitFor.d.ts +2 -2
- package/dist/{log-ac1ff860.esm.js → log-0fbf8cec.development.esm.js} +96 -4
- package/dist/{log-12b88b7e.cjs.js → log-28ea35fe.development.cjs.js} +96 -3
- package/dist/{log-e73cded6.development.cjs.js → log-a312ebfc.cjs.js} +68 -25
- package/dist/{log-abca6761.development.esm.js → log-c48e8ab0.esm.js} +68 -26
- package/dist/{raise-af6a698b.cjs.js → raise-182bb5c9.cjs.js} +24 -0
- package/dist/{raise-a7ab421f.esm.js → raise-411df926.esm.js} +24 -0
- package/dist/{raise-3f85f1d9.development.esm.js → raise-80cc66b2.development.esm.js} +24 -0
- package/dist/{raise-7132462e.development.cjs.js → raise-933cd731.development.cjs.js} +24 -0
- package/dist/xstate.cjs.js +5 -3
- package/dist/xstate.cjs.mjs +1 -0
- package/dist/xstate.development.cjs.js +5 -3
- package/dist/xstate.development.cjs.mjs +1 -0
- package/dist/xstate.development.esm.js +6 -5
- package/dist/xstate.esm.js +6 -5
- package/dist/xstate.umd.min.js +1 -1
- package/dist/xstate.umd.min.js.map +1 -1
- package/guards/dist/xstate-guards.cjs.js +1 -1
- package/guards/dist/xstate-guards.development.cjs.js +1 -1
- package/guards/dist/xstate-guards.development.esm.js +1 -1
- package/guards/dist/xstate-guards.esm.js +1 -1
- package/guards/dist/xstate-guards.umd.min.js.map +1 -1
- package/package.json +1 -1
|
@@ -88,24 +88,21 @@ export interface UnifiedArg<TContext extends MachineContext, TExpressionEvent ex
|
|
|
88
88
|
export type MachineContext = Record<string, any>;
|
|
89
89
|
export interface ActionArgs<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject> extends UnifiedArg<TContext, TExpressionEvent, TEvent> {
|
|
90
90
|
}
|
|
91
|
-
export type InputFrom<T> = T extends StateMachine<infer _TContext, infer _TEvent, infer _TChildren, infer _TActor, infer _TAction, infer _TGuard, infer _TDelay, infer _TStateValue, infer _TTag, infer TInput, infer _TOutput, infer _TResolvedTypesMeta> ? TInput : T extends ActorLogic<infer _TSnapshot, infer _TEvent, infer TInput, infer _TSystem> ? TInput : never;
|
|
92
|
-
export type OutputFrom<T> = T extends ActorLogic<infer TSnapshot, infer _TEvent, infer _TInput, infer _TSystem> ? (TSnapshot & {
|
|
91
|
+
export type InputFrom<T> = T extends StateMachine<infer _TContext, infer _TEvent, infer _TChildren, infer _TActor, infer _TAction, infer _TGuard, infer _TDelay, infer _TStateValue, infer _TTag, infer TInput, infer _TOutput, infer _TResolvedTypesMeta> ? TInput : T extends ActorLogic<infer _TSnapshot, infer _TEvent, infer TInput, infer _TSystem, infer _TEmitted> ? TInput : never;
|
|
92
|
+
export type OutputFrom<T> = T extends ActorLogic<infer TSnapshot, infer _TEvent, infer _TInput, infer _TSystem, infer _TEmitted> ? (TSnapshot & {
|
|
93
93
|
status: 'done';
|
|
94
94
|
})['output'] : T extends ActorRef<infer TSnapshot, infer _TEvent> ? (TSnapshot & {
|
|
95
95
|
status: 'done';
|
|
96
96
|
})['output'] : never;
|
|
97
|
-
export type ActionFunction<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject, TParams extends ParameterizedObject['params'] | undefined, TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string> = {
|
|
97
|
+
export type ActionFunction<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject, TParams extends ParameterizedObject['params'] | undefined, TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string, TEmitted extends EventObject> = {
|
|
98
98
|
(args: ActionArgs<TContext, TExpressionEvent, TEvent>, params: TParams): void;
|
|
99
99
|
_out_TEvent?: TEvent;
|
|
100
100
|
_out_TActor?: TActor;
|
|
101
101
|
_out_TAction?: TAction;
|
|
102
102
|
_out_TGuard?: TGuard;
|
|
103
103
|
_out_TDelay?: TDelay;
|
|
104
|
+
_out_TEmitted?: TEmitted;
|
|
104
105
|
};
|
|
105
|
-
export interface ChooseBranch<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject = TExpressionEvent, TActor extends ProvidedActor = ProvidedActor, TAction extends ParameterizedObject = ParameterizedObject, TGuard extends ParameterizedObject = ParameterizedObject, TDelay extends string = string> {
|
|
106
|
-
guard?: Guard<TContext, TExpressionEvent, undefined, TGuard>;
|
|
107
|
-
actions: Actions<TContext, TExpressionEvent, TEvent, undefined, TActor, TAction, TGuard, TDelay>;
|
|
108
|
-
}
|
|
109
106
|
export type NoRequiredParams<T extends ParameterizedObject> = T extends any ? undefined extends T['params'] ? T['type'] : never : never;
|
|
110
107
|
export type ConditionalRequired<T, Condition extends boolean> = Condition extends true ? Required<T> : T;
|
|
111
108
|
export type WithDynamicParams<TContext extends MachineContext, TExpressionEvent extends EventObject, T extends ParameterizedObject> = T extends any ? ConditionalRequired<{
|
|
@@ -115,9 +112,9 @@ export type WithDynamicParams<TContext extends MachineContext, TExpressionEvent
|
|
|
115
112
|
event: TExpressionEvent;
|
|
116
113
|
}) => T['params']);
|
|
117
114
|
}, undefined extends T['params'] ? false : true> : never;
|
|
118
|
-
export type Action<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject, TParams extends ParameterizedObject['params'] | undefined, TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string> = NoRequiredParams<TAction> | WithDynamicParams<TContext, TExpressionEvent, TAction> | ActionFunction<TContext, TExpressionEvent, TEvent, TParams, TActor, TAction, TGuard, TDelay>;
|
|
119
|
-
export type UnknownAction = Action<MachineContext, EventObject, EventObject, ParameterizedObject['params'] | undefined, ProvidedActor, ParameterizedObject, ParameterizedObject, string>;
|
|
120
|
-
export type Actions<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject, TParams extends ParameterizedObject['params'] | undefined, TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string> = SingleOrArray<Action<TContext, TExpressionEvent, TEvent, TParams, TActor, TAction, TGuard, TDelay>>;
|
|
115
|
+
export type Action<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject, TParams extends ParameterizedObject['params'] | undefined, TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string, TEmitted extends EventObject> = NoRequiredParams<TAction> | WithDynamicParams<TContext, TExpressionEvent, TAction> | ActionFunction<TContext, TExpressionEvent, TEvent, TParams, TActor, TAction, TGuard, TDelay, TEmitted>;
|
|
116
|
+
export type UnknownAction = Action<MachineContext, EventObject, EventObject, ParameterizedObject['params'] | undefined, ProvidedActor, ParameterizedObject, ParameterizedObject, string, EventObject>;
|
|
117
|
+
export type Actions<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject, TParams extends ParameterizedObject['params'] | undefined, TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string, TEmitted extends EventObject> = SingleOrArray<Action<TContext, TExpressionEvent, TEvent, TParams, TActor, TAction, TGuard, TDelay, TEmitted>>;
|
|
121
118
|
export type StateKey = string | AnyMachineSnapshot;
|
|
122
119
|
export interface StateValueMap {
|
|
123
120
|
[key: string]: StateValue | undefined;
|
|
@@ -133,9 +130,9 @@ export interface StateValueMap {
|
|
|
133
130
|
*/
|
|
134
131
|
export type StateValue = string | StateValueMap;
|
|
135
132
|
export type TransitionTarget = SingleOrArray<string>;
|
|
136
|
-
export interface TransitionConfig<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject, TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string> {
|
|
133
|
+
export interface TransitionConfig<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject, TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string, TEmitted extends EventObject = EventObject> {
|
|
137
134
|
guard?: Guard<TContext, TExpressionEvent, undefined, TGuard>;
|
|
138
|
-
actions?: Actions<TContext, TExpressionEvent, TEvent, undefined, TActor, TAction, TGuard, TDelay>;
|
|
135
|
+
actions?: Actions<TContext, TExpressionEvent, TEvent, undefined, TActor, TAction, TGuard, TDelay, TEmitted>;
|
|
139
136
|
reenter?: boolean;
|
|
140
137
|
target?: TransitionTarget | undefined;
|
|
141
138
|
meta?: Record<string, any>;
|
|
@@ -173,22 +170,22 @@ export type SingleOrArray<T> = readonly T[] | T;
|
|
|
173
170
|
export type StateNodesConfig<TContext extends MachineContext, TEvent extends EventObject> = {
|
|
174
171
|
[K in string]: StateNode<TContext, TEvent>;
|
|
175
172
|
};
|
|
176
|
-
export type StatesConfig<TContext extends MachineContext, TEvent extends EventObject, TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string, TTag extends string, TOutput> = {
|
|
177
|
-
[K in string]: StateNodeConfig<TContext, TEvent, TActor, TAction, TGuard, TDelay, TTag, TOutput>;
|
|
173
|
+
export type StatesConfig<TContext extends MachineContext, TEvent extends EventObject, TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string, TTag extends string, TOutput, TEmitted extends EventObject> = {
|
|
174
|
+
[K in string]: StateNodeConfig<TContext, TEvent, TActor, TAction, TGuard, TDelay, TTag, TOutput, TEmitted>;
|
|
178
175
|
};
|
|
179
176
|
export type StatesDefinition<TContext extends MachineContext, TEvent extends EventObject> = {
|
|
180
177
|
[K in string]: StateNodeDefinition<TContext, TEvent>;
|
|
181
178
|
};
|
|
182
179
|
export type TransitionConfigTarget = string | undefined;
|
|
183
|
-
export type TransitionConfigOrTarget<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject, TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string> = SingleOrArray<TransitionConfigTarget | TransitionConfig<TContext, TExpressionEvent, TEvent, TActor, TAction, TGuard, TDelay>>;
|
|
184
|
-
export type TransitionsConfig<TContext extends MachineContext, TEvent extends EventObject, TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string> = {
|
|
185
|
-
[K in EventDescriptor<TEvent>]?: TransitionConfigOrTarget<TContext, ExtractEvent<TEvent, K>, TEvent, TActor, TAction, TGuard, TDelay>;
|
|
180
|
+
export type TransitionConfigOrTarget<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject, TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string, TEmitted extends EventObject> = SingleOrArray<TransitionConfigTarget | TransitionConfig<TContext, TExpressionEvent, TEvent, TActor, TAction, TGuard, TDelay, TEmitted>>;
|
|
181
|
+
export type TransitionsConfig<TContext extends MachineContext, TEvent extends EventObject, TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string, TEmitted extends EventObject> = {
|
|
182
|
+
[K in EventDescriptor<TEvent>]?: TransitionConfigOrTarget<TContext, ExtractEvent<TEvent, K>, TEvent, TActor, TAction, TGuard, TDelay, TEmitted>;
|
|
186
183
|
};
|
|
187
184
|
type PartialEventDescriptor<TEventType extends string> = TEventType extends `${infer TLeading}.${infer TTail}` ? `${TLeading}.*` | `${TLeading}.${PartialEventDescriptor<TTail>}` : never;
|
|
188
185
|
export type EventDescriptor<TEvent extends EventObject> = TEvent['type'] | PartialEventDescriptor<TEvent['type']> | '*';
|
|
189
186
|
type NormalizeDescriptor<TDescriptor extends string> = TDescriptor extends '*' ? string : TDescriptor extends `${infer TLeading}.*` ? `${TLeading}.${string}` : TDescriptor;
|
|
190
187
|
export type IsLiteralString<T extends string> = string extends T ? false : true;
|
|
191
|
-
type DistributeActors<TContext extends MachineContext, TEvent extends EventObject, TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string, TSpecificActor extends ProvidedActor> = TSpecificActor extends {
|
|
188
|
+
type DistributeActors<TContext extends MachineContext, TEvent extends EventObject, TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string, TEmitted extends EventObject, TSpecificActor extends ProvidedActor> = TSpecificActor extends {
|
|
192
189
|
src: infer TSrc;
|
|
193
190
|
} ? Compute<{
|
|
194
191
|
systemId?: string;
|
|
@@ -205,16 +202,16 @@ type DistributeActors<TContext extends MachineContext, TEvent extends EventObjec
|
|
|
205
202
|
/**
|
|
206
203
|
* The transition to take upon the invoked child machine reaching its final top-level state.
|
|
207
204
|
*/
|
|
208
|
-
onDone?: string | SingleOrArray<TransitionConfigOrTarget<TContext, DoneActorEvent<OutputFrom<TSpecificActor['logic']>>, TEvent, TActor, TAction, TGuard, TDelay>>;
|
|
205
|
+
onDone?: string | SingleOrArray<TransitionConfigOrTarget<TContext, DoneActorEvent<OutputFrom<TSpecificActor['logic']>>, TEvent, TActor, TAction, TGuard, TDelay, TEmitted>>;
|
|
209
206
|
/**
|
|
210
207
|
* The transition to take upon the invoked child machine sending an error event.
|
|
211
208
|
*/
|
|
212
|
-
onError?: string | SingleOrArray<TransitionConfigOrTarget<TContext, ErrorActorEvent, TEvent, TActor, TAction, TGuard, TDelay>>;
|
|
213
|
-
onSnapshot?: string | SingleOrArray<TransitionConfigOrTarget<TContext, SnapshotEvent<SnapshotFrom<TSpecificActor['logic']>>, TEvent, TActor, TAction, TGuard, TDelay>>;
|
|
209
|
+
onError?: string | SingleOrArray<TransitionConfigOrTarget<TContext, ErrorActorEvent, TEvent, TActor, TAction, TGuard, TDelay, TEmitted>>;
|
|
210
|
+
onSnapshot?: string | SingleOrArray<TransitionConfigOrTarget<TContext, SnapshotEvent<SnapshotFrom<TSpecificActor['logic']>>, TEvent, TActor, TAction, TGuard, TDelay, TEmitted>>;
|
|
214
211
|
} & {
|
|
215
212
|
[K in RequiredActorOptions<TSpecificActor>]: unknown;
|
|
216
213
|
}> : never;
|
|
217
|
-
export type InvokeConfig<TContext extends MachineContext, TEvent extends EventObject, TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string> = IsLiteralString<TActor['src']> extends true ? DistributeActors<TContext, TEvent, TActor, TAction, TGuard, TDelay, TActor> : {
|
|
214
|
+
export type InvokeConfig<TContext extends MachineContext, TEvent extends EventObject, TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string, TEmitted extends EventObject> = IsLiteralString<TActor['src']> extends true ? DistributeActors<TContext, TEvent, TActor, TAction, TGuard, TDelay, TEmitted, TActor> : {
|
|
218
215
|
/**
|
|
219
216
|
* The unique identifier for the invoked machine. If not specified, this
|
|
220
217
|
* will be the machine's own `id`, or the URL (from `src`).
|
|
@@ -230,15 +227,15 @@ export type InvokeConfig<TContext extends MachineContext, TEvent extends EventOb
|
|
|
230
227
|
* The transition to take upon the invoked child machine reaching its final top-level state.
|
|
231
228
|
*/
|
|
232
229
|
onDone?: string | SingleOrArray<TransitionConfigOrTarget<TContext, DoneActorEvent<any>, // TODO: consider replacing with `unknown`
|
|
233
|
-
TEvent, TActor, TAction, TGuard, TDelay>>;
|
|
230
|
+
TEvent, TActor, TAction, TGuard, TDelay, TEmitted>>;
|
|
234
231
|
/**
|
|
235
232
|
* The transition to take upon the invoked child machine sending an error event.
|
|
236
233
|
*/
|
|
237
|
-
onError?: string | SingleOrArray<TransitionConfigOrTarget<TContext, ErrorActorEvent, TEvent, TActor, TAction, TGuard, TDelay>>;
|
|
238
|
-
onSnapshot?: string | SingleOrArray<TransitionConfigOrTarget<TContext, SnapshotEvent, TEvent, TActor, TAction, TGuard, TDelay>>;
|
|
234
|
+
onError?: string | SingleOrArray<TransitionConfigOrTarget<TContext, ErrorActorEvent, TEvent, TActor, TAction, TGuard, TDelay, TEmitted>>;
|
|
235
|
+
onSnapshot?: string | SingleOrArray<TransitionConfigOrTarget<TContext, SnapshotEvent, TEvent, TActor, TAction, TGuard, TDelay, TEmitted>>;
|
|
239
236
|
};
|
|
240
|
-
export type AnyInvokeConfig = InvokeConfig<any, any, any, any, any, any>;
|
|
241
|
-
export interface StateNodeConfig<TContext extends MachineContext, TEvent extends EventObject, TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string, TTag extends string, TOutput> {
|
|
237
|
+
export type AnyInvokeConfig = InvokeConfig<any, any, any, any, any, any, any>;
|
|
238
|
+
export interface StateNodeConfig<TContext extends MachineContext, TEvent extends EventObject, TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string, TTag extends string, TOutput, TEmitted extends EventObject> {
|
|
242
239
|
/**
|
|
243
240
|
* The initial state transition.
|
|
244
241
|
*/
|
|
@@ -262,23 +259,23 @@ export interface StateNodeConfig<TContext extends MachineContext, TEvent extends
|
|
|
262
259
|
/**
|
|
263
260
|
* The mapping of state node keys to their state node configurations (recursive).
|
|
264
261
|
*/
|
|
265
|
-
states?: StatesConfig<TContext, TEvent, TActor, TAction, TGuard, TDelay, TTag, NonReducibleUnknown> | undefined;
|
|
262
|
+
states?: StatesConfig<TContext, TEvent, TActor, TAction, TGuard, TDelay, TTag, NonReducibleUnknown, TEmitted> | undefined;
|
|
266
263
|
/**
|
|
267
264
|
* The services to invoke upon entering this state node. These services will be stopped upon exiting this state node.
|
|
268
265
|
*/
|
|
269
|
-
invoke?: SingleOrArray<InvokeConfig<TContext, TEvent, TActor, TAction, TGuard, TDelay>>;
|
|
266
|
+
invoke?: SingleOrArray<InvokeConfig<TContext, TEvent, TActor, TAction, TGuard, TDelay, TEmitted>>;
|
|
270
267
|
/**
|
|
271
268
|
* The mapping of event types to their potential transition(s).
|
|
272
269
|
*/
|
|
273
|
-
on?: TransitionsConfig<TContext, TEvent, TActor, TAction, TGuard, TDelay>;
|
|
270
|
+
on?: TransitionsConfig<TContext, TEvent, TActor, TAction, TGuard, TDelay, TEmitted>;
|
|
274
271
|
/**
|
|
275
272
|
* The action(s) to be executed upon entering the state node.
|
|
276
273
|
*/
|
|
277
|
-
entry?: Actions<TContext, TEvent, TEvent, undefined, TActor, TAction, TGuard, TDelay>;
|
|
274
|
+
entry?: Actions<TContext, TEvent, TEvent, undefined, TActor, TAction, TGuard, TDelay, TEmitted>;
|
|
278
275
|
/**
|
|
279
276
|
* The action(s) to be executed upon exiting the state node.
|
|
280
277
|
*/
|
|
281
|
-
exit?: Actions<TContext, TEvent, TEvent, undefined, TActor, TAction, TGuard, TDelay>;
|
|
278
|
+
exit?: Actions<TContext, TEvent, TEvent, undefined, TActor, TAction, TGuard, TDelay, TEmitted>;
|
|
282
279
|
/**
|
|
283
280
|
* The potential transition(s) to be taken upon reaching a final child state node.
|
|
284
281
|
*
|
|
@@ -293,7 +290,7 @@ export interface StateNodeConfig<TContext extends MachineContext, TEvent extends
|
|
|
293
290
|
/**
|
|
294
291
|
* An eventless transition that is always taken when this state node is active.
|
|
295
292
|
*/
|
|
296
|
-
always?: TransitionConfigOrTarget<TContext, TEvent, TEvent, TActor, TAction, TGuard, TDelay>;
|
|
293
|
+
always?: TransitionConfigOrTarget<TContext, TEvent, TEvent, TActor, TAction, TGuard, TDelay, TEmitted>;
|
|
297
294
|
parent?: StateNode<TContext, TEvent>;
|
|
298
295
|
/**
|
|
299
296
|
* The meta data associated with this state node, which will be returned in State instances.
|
|
@@ -328,7 +325,7 @@ export interface StateNodeConfig<TContext extends MachineContext, TEvent extends
|
|
|
328
325
|
*/
|
|
329
326
|
target?: string;
|
|
330
327
|
}
|
|
331
|
-
export type AnyStateNodeConfig = StateNodeConfig<any, any, any, any, any, any, any, any>;
|
|
328
|
+
export type AnyStateNodeConfig = StateNodeConfig<any, any, any, any, any, any, any, any, any>;
|
|
332
329
|
export interface StateNodeDefinition<TContext extends MachineContext, TEvent extends EventObject> {
|
|
333
330
|
id: string;
|
|
334
331
|
version?: string | undefined;
|
|
@@ -343,7 +340,7 @@ export interface StateNodeDefinition<TContext extends MachineContext, TEvent ext
|
|
|
343
340
|
exit: UnknownAction[];
|
|
344
341
|
meta: any;
|
|
345
342
|
order: number;
|
|
346
|
-
output?: StateNodeConfig<TContext, TEvent, ProvidedActor, ParameterizedObject, ParameterizedObject, string, string, unknown>['output'];
|
|
343
|
+
output?: StateNodeConfig<TContext, TEvent, ProvidedActor, ParameterizedObject, ParameterizedObject, string, string, unknown, EventObject>['output'];
|
|
347
344
|
invoke: Array<InvokeDefinition<TContext, TEvent, TODO, TODO, TODO, TODO>>;
|
|
348
345
|
description?: string;
|
|
349
346
|
tags: string[];
|
|
@@ -366,9 +363,10 @@ any, // state value
|
|
|
366
363
|
any, // tag
|
|
367
364
|
any, // input
|
|
368
365
|
any, // output
|
|
366
|
+
any, // emitted
|
|
369
367
|
any>;
|
|
370
368
|
export type AnyStateConfig = StateConfig<any, AnyEventObject>;
|
|
371
|
-
export interface AtomicStateNodeConfig<TContext extends MachineContext, TEvent extends EventObject> extends StateNodeConfig<TContext, TEvent, TODO, TODO, TODO, TODO, TODO, TODO> {
|
|
369
|
+
export interface AtomicStateNodeConfig<TContext extends MachineContext, TEvent extends EventObject> extends StateNodeConfig<TContext, TEvent, TODO, TODO, TODO, TODO, TODO, TODO, TODO> {
|
|
372
370
|
initial?: undefined;
|
|
373
371
|
parallel?: false | undefined;
|
|
374
372
|
states?: undefined;
|
|
@@ -378,11 +376,11 @@ export interface HistoryStateNodeConfig<TContext extends MachineContext, TEvent
|
|
|
378
376
|
history: 'shallow' | 'deep' | true;
|
|
379
377
|
target: string | undefined;
|
|
380
378
|
}
|
|
381
|
-
export type SimpleOrStateNodeConfig<TContext extends MachineContext, TEvent extends EventObject> = AtomicStateNodeConfig<TContext, TEvent> | StateNodeConfig<TContext, TEvent, TODO, TODO, TODO, TODO, TODO, TODO>;
|
|
382
|
-
export type ActionFunctionMap<TContext extends MachineContext, TEvent extends EventObject, TActor extends ProvidedActor, TAction extends ParameterizedObject = ParameterizedObject, TGuard extends ParameterizedObject = ParameterizedObject, TDelay extends string = string> = {
|
|
379
|
+
export type SimpleOrStateNodeConfig<TContext extends MachineContext, TEvent extends EventObject> = AtomicStateNodeConfig<TContext, TEvent> | StateNodeConfig<TContext, TEvent, TODO, TODO, TODO, TODO, TODO, TODO, TODO>;
|
|
380
|
+
export type ActionFunctionMap<TContext extends MachineContext, TEvent extends EventObject, TActor extends ProvidedActor, TAction extends ParameterizedObject = ParameterizedObject, TGuard extends ParameterizedObject = ParameterizedObject, TDelay extends string = string, TEmitted extends EventObject = EventObject> = {
|
|
383
381
|
[K in TAction['type']]?: ActionFunction<TContext, TEvent, TEvent, GetParameterizedParams<TAction extends {
|
|
384
382
|
type: K;
|
|
385
|
-
} ? TAction : never>, TActor, TAction, TGuard, TDelay>;
|
|
383
|
+
} ? TAction : never>, TActor, TAction, TGuard, TDelay, TEmitted>;
|
|
386
384
|
};
|
|
387
385
|
type GuardMap<TContext extends MachineContext, TEvent extends EventObject, TGuard extends ParameterizedObject> = {
|
|
388
386
|
[K in TGuard['type']]?: GuardPredicate<TContext, TEvent, GetParameterizedParams<TGuard extends {
|
|
@@ -404,8 +402,8 @@ export interface MachineImplementationsSimplified<TContext extends MachineContex
|
|
|
404
402
|
delays: DelayFunctionMap<TContext, TEvent, TAction>;
|
|
405
403
|
}
|
|
406
404
|
type MaybeNarrowedEvent<TIndexedEvents, TCausingLookup, K> = Cast<Prop<TIndexedEvents, K extends keyof TCausingLookup ? TCausingLookup[K] : TIndexedEvents[keyof TIndexedEvents]>, EventObject>;
|
|
407
|
-
type MachineImplementationsActions<TContext extends MachineContext, TResolvedTypesMeta, TEventsCausingActions = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'eventsCausingActions'>, TIndexedEvents = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'indexedEvents'>, TIndexedActors = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'indexedActors'>, TIndexedActions = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'indexedActions'>, TIndexedGuards = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'indexedGuards'>, TIndexedDelays = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'indexedDelays'>> = {
|
|
408
|
-
[K in keyof TIndexedActions]?: ActionFunction<TContext, MaybeNarrowedEvent<TIndexedEvents, TEventsCausingActions, K>, Cast<Prop<TIndexedEvents, keyof TIndexedEvents>, EventObject>, GetParameterizedParams<Cast<TIndexedActions[K], ParameterizedObject>>, Cast<Prop<TIndexedActors, keyof TIndexedActors>, ProvidedActor>, Cast<Prop<TIndexedActions, keyof TIndexedActions>, ParameterizedObject>, Cast<Prop<TIndexedGuards, keyof TIndexedGuards>, ParameterizedObject>, Cast<Prop<TIndexedDelays, keyof TIndexedDelays>, ParameterizedObject>['type']
|
|
405
|
+
type MachineImplementationsActions<TContext extends MachineContext, TResolvedTypesMeta, TEventsCausingActions = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'eventsCausingActions'>, TIndexedEvents = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'indexedEvents'>, TIndexedActors = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'indexedActors'>, TIndexedActions = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'indexedActions'>, TIndexedGuards = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'indexedGuards'>, TIndexedDelays = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'indexedDelays'>, TEmitted = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'emitted'>> = {
|
|
406
|
+
[K in keyof TIndexedActions]?: ActionFunction<TContext, MaybeNarrowedEvent<TIndexedEvents, TEventsCausingActions, K>, Cast<Prop<TIndexedEvents, keyof TIndexedEvents>, EventObject>, GetParameterizedParams<Cast<TIndexedActions[K], ParameterizedObject>>, Cast<Prop<TIndexedActors, keyof TIndexedActors>, ProvidedActor>, Cast<Prop<TIndexedActions, keyof TIndexedActions>, ParameterizedObject>, Cast<Prop<TIndexedGuards, keyof TIndexedGuards>, ParameterizedObject>, Cast<Prop<TIndexedDelays, keyof TIndexedDelays>, ParameterizedObject>['type'], Cast<TEmitted, EventObject>>;
|
|
409
407
|
};
|
|
410
408
|
type MachineImplementationsActors<_TContext extends MachineContext, TResolvedTypesMeta, TIndexedActors = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'indexedActors'>, _TInvokeSrcNameMap = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'invokeSrcNameMap'>> = {
|
|
411
409
|
[K in keyof TIndexedActors]?: Cast<Prop<TIndexedActors[K], 'logic'>, AnyActorLogic>;
|
|
@@ -443,7 +441,7 @@ export type ContextFactory<TContext extends MachineContext, TActor extends Provi
|
|
|
443
441
|
self: ActorRef<MachineSnapshot<TContext, TEvent, Record<string, AnyActorRef | undefined>, // TODO: this should be replaced with `TChildren`
|
|
444
442
|
StateValue, string, unknown>, TEvent>;
|
|
445
443
|
}) => TContext;
|
|
446
|
-
export type MachineConfig<TContext extends MachineContext, TEvent extends EventObject, TActor extends ProvidedActor = ProvidedActor, TAction extends ParameterizedObject = ParameterizedObject, TGuard extends ParameterizedObject = ParameterizedObject, TDelay extends string = string, TTag extends string = string, TInput = any, TOutput = unknown, TTypesMeta = TypegenDisabled> = (Omit<StateNodeConfig<NoInfer<TContext>, NoInfer<TEvent>, NoInfer<TActor>, NoInfer<TAction>, NoInfer<TGuard>, NoInfer<TDelay>, NoInfer<TTag>, NoInfer<TOutput>>, 'output'> & {
|
|
444
|
+
export type MachineConfig<TContext extends MachineContext, TEvent extends EventObject, TActor extends ProvidedActor = ProvidedActor, TAction extends ParameterizedObject = ParameterizedObject, TGuard extends ParameterizedObject = ParameterizedObject, TDelay extends string = string, TTag extends string = string, TInput = any, TOutput = unknown, TEmitted extends EventObject = EventObject, TTypesMeta = TypegenDisabled> = (Omit<StateNodeConfig<NoInfer<TContext>, NoInfer<TEvent>, NoInfer<TActor>, NoInfer<TAction>, NoInfer<TGuard>, NoInfer<TDelay>, NoInfer<TTag>, NoInfer<TOutput>, NoInfer<TEmitted>>, 'output'> & {
|
|
447
445
|
/**
|
|
448
446
|
* The initial context (extended state)
|
|
449
447
|
*/
|
|
@@ -463,15 +461,16 @@ export interface ProvidedActor {
|
|
|
463
461
|
logic: UnknownActorLogic;
|
|
464
462
|
id?: string;
|
|
465
463
|
}
|
|
466
|
-
export interface SetupTypes<TContext extends MachineContext, TEvent extends EventObject, TChildrenMap extends Record<string, string>, TTag extends string, TInput, TOutput> {
|
|
464
|
+
export interface SetupTypes<TContext extends MachineContext, TEvent extends EventObject, TChildrenMap extends Record<string, string>, TTag extends string, TInput, TOutput, TEmitted extends EventObject> {
|
|
467
465
|
context?: TContext;
|
|
468
466
|
events?: TEvent;
|
|
469
467
|
children?: TChildrenMap;
|
|
470
468
|
tags?: TTag;
|
|
471
469
|
input?: TInput;
|
|
472
470
|
output?: TOutput;
|
|
471
|
+
emitted?: TEmitted;
|
|
473
472
|
}
|
|
474
|
-
export interface MachineTypes<TContext extends MachineContext, TEvent extends EventObject, TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string, TTag extends string, TInput, TOutput, TTypesMeta = TypegenDisabled> extends SetupTypes<TContext, TEvent, never, TTag, TInput, TOutput> {
|
|
473
|
+
export interface MachineTypes<TContext extends MachineContext, TEvent extends EventObject, TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string, TTag extends string, TInput, TOutput, TEmitted extends EventObject, TTypesMeta = TypegenDisabled> extends SetupTypes<TContext, TEvent, never, TTag, TInput, TOutput, TEmitted> {
|
|
475
474
|
actors?: TActor;
|
|
476
475
|
actions?: TAction;
|
|
477
476
|
guards?: TGuard;
|
|
@@ -567,11 +566,11 @@ export interface StateLike<TContext extends MachineContext> {
|
|
|
567
566
|
export interface StateConfig<TContext extends MachineContext, TEvent extends EventObject> {
|
|
568
567
|
context: TContext;
|
|
569
568
|
historyValue?: HistoryValue<TContext, TEvent>;
|
|
570
|
-
children: Record<string,
|
|
569
|
+
children: Record<string, AnyActorRef>;
|
|
571
570
|
status: 'active' | 'done' | 'error' | 'stopped';
|
|
572
571
|
output?: any;
|
|
573
572
|
error?: unknown;
|
|
574
|
-
machine?: StateMachine<TContext, TEvent, any, any, any, any, any, any, any, any, any>;
|
|
573
|
+
machine?: StateMachine<TContext, TEvent, any, any, any, any, any, any, any, any, any, any>;
|
|
575
574
|
}
|
|
576
575
|
export interface ActorOptions<TLogic extends AnyActorLogic> {
|
|
577
576
|
/**
|
|
@@ -595,7 +594,7 @@ export interface ActorOptions<TLogic extends AnyActorLogic> {
|
|
|
595
594
|
* Specifies the logger to be used for `log(...)` actions. Defaults to the native `console.log(...)` method.
|
|
596
595
|
*/
|
|
597
596
|
logger?: (...args: any[]) => void;
|
|
598
|
-
parent?:
|
|
597
|
+
parent?: AnyActorRef;
|
|
599
598
|
/**
|
|
600
599
|
* The custom `id` for referencing this service.
|
|
601
600
|
*/
|
|
@@ -741,7 +740,7 @@ export interface BaseActorRef<TEvent extends EventObject> {
|
|
|
741
740
|
export interface ActorLike<TCurrent, TEvent extends EventObject> extends Subscribable<TCurrent> {
|
|
742
741
|
send: (event: TEvent) => void;
|
|
743
742
|
}
|
|
744
|
-
export interface ActorRef<TSnapshot extends Snapshot<unknown>, TEvent extends EventObject> extends Subscribable<TSnapshot>, InteropObservable<TSnapshot> {
|
|
743
|
+
export interface ActorRef<TSnapshot extends Snapshot<unknown>, TEvent extends EventObject, TEmitted extends EventObject = EventObject> extends Subscribable<TSnapshot>, InteropObservable<TSnapshot> {
|
|
745
744
|
/**
|
|
746
745
|
* The unique identifier for this actor relative to its parent.
|
|
747
746
|
*/
|
|
@@ -753,19 +752,22 @@ export interface ActorRef<TSnapshot extends Snapshot<unknown>, TEvent extends Ev
|
|
|
753
752
|
getPersistedSnapshot: () => Snapshot<unknown>;
|
|
754
753
|
stop: () => void;
|
|
755
754
|
toJSON?: () => any;
|
|
756
|
-
_parent?:
|
|
755
|
+
_parent?: AnyActorRef;
|
|
757
756
|
system: AnyActorSystem;
|
|
758
757
|
src: string | AnyActorLogic;
|
|
758
|
+
on: <TType extends TEmitted['type']>(type: TType, handler: (emitted: TEmitted & {
|
|
759
|
+
type: TType;
|
|
760
|
+
}) => void) => Subscription;
|
|
759
761
|
}
|
|
760
|
-
export type AnyActorRef = ActorRef<any, any>;
|
|
762
|
+
export type AnyActorRef = ActorRef<any, any, any>;
|
|
761
763
|
export type ActorLogicFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<any, any, any, any, any, any, any, any, any, any, any, any> ? R : R extends Promise<infer U> ? PromiseActorLogic<U> : never : never;
|
|
762
|
-
export type ActorRefFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<infer TContext, infer TEvent, infer TChildren, infer _TActor, infer _TAction, infer _TGuard, infer _TDelay, infer TStateValue, infer TTag, infer _TInput, infer TOutput, infer _TResolvedTypesMeta> ? ActorRef<MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput>, TEvent> : R extends Promise<infer U> ? ActorRefFrom<PromiseActorLogic<U>> : R extends ActorLogic<infer TSnapshot, infer TEvent, infer _TInput, infer _TSystem> ? ActorRef<TSnapshot, TEvent> : never : never;
|
|
764
|
+
export type ActorRefFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<infer TContext, infer TEvent, infer TChildren, infer _TActor, infer _TAction, infer _TGuard, infer _TDelay, infer TStateValue, infer TTag, infer _TInput, infer TOutput, infer TEmitted, infer _TResolvedTypesMeta> ? ActorRef<MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput>, TEvent, TEmitted> : R extends Promise<infer U> ? ActorRefFrom<PromiseActorLogic<U>> : R extends ActorLogic<infer TSnapshot, infer TEvent, infer _TInput, infer _TSystem, infer TEmitted> ? ActorRef<TSnapshot, TEvent, TEmitted> : never : never;
|
|
763
765
|
export type DevToolsAdapter = (service: AnyActor) => void;
|
|
764
766
|
/**
|
|
765
767
|
* @deprecated Use `Actor<T>` instead.
|
|
766
768
|
*/
|
|
767
|
-
export type InterpreterFrom<T extends AnyStateMachine | ((...args: any[]) => AnyStateMachine)> = ReturnTypeOrValue<T> extends StateMachine<infer TContext, infer TEvent, infer TChildren, infer _TActor, infer _TAction, infer _TGuard, infer _TDelay, infer TStateValue, infer TTag, infer TInput, infer TOutput, infer _TResolvedTypesMeta> ? Actor<ActorLogic<MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput>, TEvent, TInput, AnyActorSystem>> : never;
|
|
768
|
-
export type MachineImplementationsFrom<T extends AnyStateMachine | ((...args: any[]) => AnyStateMachine), TRequireMissingImplementations extends boolean = false> = ReturnTypeOrValue<T> extends StateMachine<infer TContext, infer _TEvent, infer _TChildren, infer _TActor, infer _TAction, infer _TGuard, infer _TDelay, infer _TStateValue, infer _TTag, infer _TInput, infer _TOutput, infer TResolvedTypesMeta> ? InternalMachineImplementations<TContext, TResolvedTypesMeta, TRequireMissingImplementations> : never;
|
|
769
|
+
export type InterpreterFrom<T extends AnyStateMachine | ((...args: any[]) => AnyStateMachine)> = ReturnTypeOrValue<T> extends StateMachine<infer TContext, infer TEvent, infer TChildren, infer _TActor, infer _TAction, infer _TGuard, infer _TDelay, infer TStateValue, infer TTag, infer TInput, infer TOutput, infer TEmitted, infer _TResolvedTypesMeta> ? Actor<ActorLogic<MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput>, TEvent, TInput, AnyActorSystem, TEmitted>> : never;
|
|
770
|
+
export type MachineImplementationsFrom<T extends AnyStateMachine | ((...args: any[]) => AnyStateMachine), TRequireMissingImplementations extends boolean = false> = ReturnTypeOrValue<T> extends StateMachine<infer TContext, infer _TEvent, infer _TChildren, infer _TActor, infer _TAction, infer _TGuard, infer _TDelay, infer _TStateValue, infer _TTag, infer _TInput, infer _TOutput, infer _TEmitted, infer TResolvedTypesMeta> ? InternalMachineImplementations<TContext, TResolvedTypesMeta, TRequireMissingImplementations> : never;
|
|
769
771
|
export type __ResolvedTypesMetaFrom<T> = T extends StateMachine<any, // context
|
|
770
772
|
any, // event
|
|
771
773
|
any, // children
|
|
@@ -777,17 +779,21 @@ any, // state value
|
|
|
777
779
|
any, // tag
|
|
778
780
|
any, // input
|
|
779
781
|
any, // output
|
|
782
|
+
any, // emitted
|
|
780
783
|
infer TResolvedTypesMeta> ? TResolvedTypesMeta : never;
|
|
781
|
-
export interface ActorScope<TSnapshot extends Snapshot<unknown>, TEvent extends EventObject, TSystem extends AnyActorSystem = AnyActorSystem> {
|
|
782
|
-
self: ActorRef<TSnapshot, TEvent>;
|
|
784
|
+
export interface ActorScope<TSnapshot extends Snapshot<unknown>, TEvent extends EventObject, TSystem extends AnyActorSystem = AnyActorSystem, TEmitted extends EventObject = EventObject> {
|
|
785
|
+
self: ActorRef<TSnapshot, TEvent, TEmitted>;
|
|
783
786
|
id: string;
|
|
784
787
|
sessionId: string;
|
|
785
788
|
logger: (...args: any[]) => void;
|
|
786
789
|
defer: (fn: () => void) => void;
|
|
790
|
+
emit: (event: TEmitted) => void;
|
|
787
791
|
system: TSystem;
|
|
788
792
|
stopChild: (child: AnyActorRef) => void;
|
|
789
793
|
}
|
|
790
|
-
export type AnyActorScope = ActorScope<any,
|
|
794
|
+
export type AnyActorScope = ActorScope<any, // TSnapshot
|
|
795
|
+
any, // TEvent
|
|
796
|
+
AnyActorSystem, any>;
|
|
791
797
|
export type Snapshot<TOutput> = {
|
|
792
798
|
status: 'active';
|
|
793
799
|
output: undefined;
|
|
@@ -815,7 +821,7 @@ export type Snapshot<TOutput> = {
|
|
|
815
821
|
*/
|
|
816
822
|
export interface ActorLogic<in out TSnapshot extends Snapshot<unknown>, // it's invariant because it's also part of `ActorScope["self"]["getSnapshot"]`
|
|
817
823
|
in out TEvent extends EventObject, // it's invariant because it's also part of `ActorScope["self"]["send"]`
|
|
818
|
-
in TInput = NonReducibleUnknown, TSystem extends AnyActorSystem = AnyActorSystem> {
|
|
824
|
+
in TInput = NonReducibleUnknown, TSystem extends AnyActorSystem = AnyActorSystem, in out TEmitted extends EventObject = EventObject> {
|
|
819
825
|
/** The initial setup/configuration used to create the actor logic. */
|
|
820
826
|
config?: unknown;
|
|
821
827
|
/**
|
|
@@ -826,14 +832,14 @@ in TInput = NonReducibleUnknown, TSystem extends AnyActorSystem = AnyActorSystem
|
|
|
826
832
|
* @param actorScope - The actor scope.
|
|
827
833
|
* @returns The new state.
|
|
828
834
|
*/
|
|
829
|
-
transition: (snapshot: TSnapshot, message: TEvent, actorScope: ActorScope<TSnapshot, TEvent, TSystem>) => TSnapshot;
|
|
835
|
+
transition: (snapshot: TSnapshot, message: TEvent, actorScope: ActorScope<TSnapshot, TEvent, TSystem, TEmitted>) => TSnapshot;
|
|
830
836
|
/**
|
|
831
837
|
* Called to provide the initial state of the actor.
|
|
832
838
|
* @param actorScope - The actor scope.
|
|
833
839
|
* @param input - The input for the initial state.
|
|
834
840
|
* @returns The initial state.
|
|
835
841
|
*/
|
|
836
|
-
getInitialSnapshot: (actorScope: ActorScope<TSnapshot, TEvent, TSystem>, input: TInput) => TSnapshot;
|
|
842
|
+
getInitialSnapshot: (actorScope: ActorScope<TSnapshot, TEvent, TSystem, TEmitted>, input: TInput) => TSnapshot;
|
|
837
843
|
/**
|
|
838
844
|
* Called when Actor is created to restore the internal state of the actor given a persisted state.
|
|
839
845
|
* The persisted state can be created by `getPersistedSnapshot`.
|
|
@@ -841,13 +847,13 @@ in TInput = NonReducibleUnknown, TSystem extends AnyActorSystem = AnyActorSystem
|
|
|
841
847
|
* @param actorScope - The actor scope.
|
|
842
848
|
* @returns The restored state.
|
|
843
849
|
*/
|
|
844
|
-
restoreSnapshot?: (persistedState: Snapshot<unknown>, actorScope: ActorScope<TSnapshot, TEvent>) => TSnapshot;
|
|
850
|
+
restoreSnapshot?: (persistedState: Snapshot<unknown>, actorScope: ActorScope<TSnapshot, TEvent, AnyActorSystem, TEmitted>) => TSnapshot;
|
|
845
851
|
/**
|
|
846
852
|
* Called when the actor is started.
|
|
847
853
|
* @param snapshot - The starting state.
|
|
848
854
|
* @param actorScope - The actor scope.
|
|
849
855
|
*/
|
|
850
|
-
start?: (snapshot: TSnapshot, actorScope: ActorScope<TSnapshot, TEvent>) => void;
|
|
856
|
+
start?: (snapshot: TSnapshot, actorScope: ActorScope<TSnapshot, TEvent, AnyActorSystem, TEmitted>) => void;
|
|
851
857
|
/**
|
|
852
858
|
* Obtains the internal state of the actor in a representation which can be be persisted.
|
|
853
859
|
* The persisted state can be restored by `restoreSnapshot`.
|
|
@@ -859,13 +865,18 @@ in TInput = NonReducibleUnknown, TSystem extends AnyActorSystem = AnyActorSystem
|
|
|
859
865
|
export type AnyActorLogic = ActorLogic<any, // snapshot
|
|
860
866
|
any, // event
|
|
861
867
|
any, // input
|
|
868
|
+
any, // system
|
|
862
869
|
any>;
|
|
863
|
-
export type UnknownActorLogic = ActorLogic<any,
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
870
|
+
export type UnknownActorLogic = ActorLogic<any, // snapshot
|
|
871
|
+
any, // event
|
|
872
|
+
never, // input
|
|
873
|
+
AnyActorSystem, any>;
|
|
874
|
+
export type SnapshotFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends ActorRef<infer TSnapshot, infer _> ? TSnapshot : R extends Actor<infer TLogic> ? SnapshotFrom<TLogic> : R extends ActorLogic<infer _TSnapshot, infer _TEvent, infer _TInput, infer _TEmitted, infer _TSystem> ? ReturnType<R['transition']> : R extends ActorScope<infer TSnapshot, infer _TEvent, infer _TEmitted, infer _TSystem> ? TSnapshot : never : never;
|
|
875
|
+
export type EventFromLogic<TLogic extends AnyActorLogic> = TLogic extends ActorLogic<infer _TSnapshot, infer TEvent, infer _TInput, infer _TEmitted, infer _TSystem> ? TEvent : never;
|
|
876
|
+
export type EmittedFrom<TLogic extends AnyActorLogic> = TLogic extends ActorLogic<infer _TSnapshot, infer _TEvent, infer _TInput, infer _TSystem, infer TEmitted> ? TEmitted : never;
|
|
877
|
+
type ResolveEventType<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<infer _TContext, infer TEvent, infer _TChildren, infer _TActor, infer _TAction, infer _TGuard, infer _TDelay, infer _TStateValue, infer _TTag, infer _TInput, infer _TOutput, infer _TEmitted, infer _TResolvedTypesMeta> ? TEvent : R extends MachineSnapshot<infer _TContext, infer TEvent, infer _TChildren, infer _TStateValue, infer _TTag, infer _TOutput> ? TEvent : R extends ActorRef<infer _, infer TEvent> ? TEvent : never : never;
|
|
867
878
|
export type EventFrom<T, K extends Prop<TEvent, 'type'> = never, TEvent extends EventObject = ResolveEventType<T>> = IsNever<K> extends true ? TEvent : ExtractEvent<TEvent, K>;
|
|
868
|
-
export type ContextFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<infer TContext, infer _TEvent, infer _TChildren, infer _TActor, infer _TAction, infer _TGuard, infer _TDelay, infer _TStateValue, infer _TTag, infer _TInput, infer _TOutput, infer _TResolvedTypesMeta> ? TContext : R extends MachineSnapshot<infer TContext, infer _TEvent, infer _TChildren, infer _TStateValue, infer _TTag, infer _TOutput> ? TContext : R extends Actor<infer TActorLogic> ? TActorLogic extends StateMachine<infer TContext, infer _TEvent, infer _TChildren, infer _TActor, infer _TAction, infer _TGuard, infer _TDelay, infer _TTag, infer _TInput, infer _TOutput, infer _TResolvedTypesMeta> ? TContext : never : never : never;
|
|
879
|
+
export type ContextFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<infer TContext, infer _TEvent, infer _TChildren, infer _TActor, infer _TAction, infer _TGuard, infer _TDelay, infer _TStateValue, infer _TTag, infer _TInput, infer _TOutput, infer _TEmitted, infer _TResolvedTypesMeta> ? TContext : R extends MachineSnapshot<infer TContext, infer _TEvent, infer _TChildren, infer _TStateValue, infer _TTag, infer _TOutput> ? TContext : R extends Actor<infer TActorLogic> ? TActorLogic extends StateMachine<infer TContext, infer _TEvent, infer _TChildren, infer _TActor, infer _TAction, infer _TGuard, infer _TDelay, infer _TTag, infer _TInput, infer _TOutput, infer _TEmitted, infer _TResolvedTypesMeta> ? TContext : never : never : never;
|
|
869
880
|
export type InferEvent<E extends EventObject> = {
|
|
870
881
|
[T in E['type']]: {
|
|
871
882
|
type: T;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { StateNode } from "./StateNode.js";
|
|
2
|
-
import type {
|
|
2
|
+
import type { AnyActorLogic, AnyActorRef, AnyEventObject, AnyMachineSnapshot, AnyStateMachine, AnyTransitionConfig, ErrorActorEvent, EventObject, MachineContext, Mapper, NonReducibleUnknown, Observer, SingleOrArray, StateLike, StateValue, TransitionConfigTarget } from "./types.js";
|
|
3
3
|
export declare function matchesState(parentStateId: StateValue, childStateId: StateValue): boolean;
|
|
4
4
|
export declare function toStatePath(stateId: string | string[]): string[];
|
|
5
5
|
export declare function toStateValue(stateValue: StateLike<any> | StateValue): StateValue;
|
|
@@ -10,7 +10,7 @@ export declare function mapValues<P, O extends Record<string, unknown>>(collecti
|
|
|
10
10
|
export declare function toArrayStrict<T>(value: readonly T[] | T): readonly T[];
|
|
11
11
|
export declare function toArray<T>(value: readonly T[] | T | undefined): readonly T[];
|
|
12
12
|
export declare function resolveOutput<TContext extends MachineContext, TExpressionEvent extends EventObject>(mapper: Mapper<TContext, TExpressionEvent, unknown, EventObject> | NonReducibleUnknown, context: TContext, event: TExpressionEvent, self: AnyActorRef): unknown;
|
|
13
|
-
export declare function isActorLogic(value: any): value is
|
|
13
|
+
export declare function isActorLogic(value: any): value is AnyActorLogic;
|
|
14
14
|
export declare function isArray(value: any): value is readonly any[];
|
|
15
15
|
export declare function isErrorActorEvent(event: AnyEventObject): event is ErrorActorEvent;
|
|
16
16
|
export declare function toTransitionConfigArray<TContext extends MachineContext, TEvent extends EventObject>(configLike: SingleOrArray<AnyTransitionConfig | TransitionConfigTarget>): Array<AnyTransitionConfig>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AnyActorRef, SnapshotFrom } from "./types.js";
|
|
2
2
|
interface WaitForOptions {
|
|
3
3
|
/**
|
|
4
4
|
* How long to wait before rejecting, if no emitted
|
|
@@ -29,5 +29,5 @@ interface WaitForOptions {
|
|
|
29
29
|
* @returns A promise that eventually resolves to the emitted value
|
|
30
30
|
* that matches the condition
|
|
31
31
|
*/
|
|
32
|
-
export declare function waitFor<TActorRef extends
|
|
32
|
+
export declare function waitFor<TActorRef extends AnyActorRef>(actorRef: TActorRef, predicate: (emitted: SnapshotFrom<TActorRef>) => boolean, options?: Partial<WaitForOptions>): Promise<SnapshotFrom<TActorRef>>;
|
|
33
33
|
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { T as ProcessingStatus, z as resolveReferencedActor, A as createActor, U as cloneMachineSnapshot, V as XSTATE_ERROR, W as createErrorActorEvent, e as evaluateGuard, M as cancel, O as raise, P as spawnChild, R as stopChild } from './raise-
|
|
1
|
+
import { T as ProcessingStatus, z as resolveReferencedActor, A as createActor, U as cloneMachineSnapshot, V as XSTATE_ERROR, W as createErrorActorEvent, e as evaluateGuard, M as cancel, O as raise, P as spawnChild, R as stopChild } from './raise-80cc66b2.development.esm.js';
|
|
2
2
|
|
|
3
3
|
// it's likely-ish that `(TActor & { src: TSrc })['logic']` would be faster
|
|
4
4
|
// but it's only possible to do it since https://github.com/microsoft/TypeScript/pull/53098 (TS 5.1)
|
|
@@ -122,6 +122,9 @@ function resolveAssign(actorScope, snapshot, actionArgs, actionParams, {
|
|
|
122
122
|
*/
|
|
123
123
|
function assign(assignment) {
|
|
124
124
|
function assign(args, params) {
|
|
125
|
+
{
|
|
126
|
+
throw new Error(`This isn't supposed to be called`);
|
|
127
|
+
}
|
|
125
128
|
}
|
|
126
129
|
assign.type = 'xstate.assign';
|
|
127
130
|
assign.assignment = assignment;
|
|
@@ -129,6 +132,73 @@ function assign(assignment) {
|
|
|
129
132
|
return assign;
|
|
130
133
|
}
|
|
131
134
|
|
|
135
|
+
function resolveEmit(_, snapshot, args, actionParams, {
|
|
136
|
+
event: eventOrExpr
|
|
137
|
+
}) {
|
|
138
|
+
if (typeof eventOrExpr === 'string') {
|
|
139
|
+
throw new Error(`Only event objects may be used with emit; use emit({ type: "${eventOrExpr}" }) instead`);
|
|
140
|
+
}
|
|
141
|
+
const resolvedEvent = typeof eventOrExpr === 'function' ? eventOrExpr(args, actionParams) : eventOrExpr;
|
|
142
|
+
return [snapshot, {
|
|
143
|
+
event: resolvedEvent
|
|
144
|
+
}];
|
|
145
|
+
}
|
|
146
|
+
function executeEmit(actorScope, {
|
|
147
|
+
event
|
|
148
|
+
}) {
|
|
149
|
+
actorScope.defer(() => actorScope.emit(event));
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Emits an event to event handlers registered on the actor via `actor.on(event, handler)`.
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
155
|
+
```ts
|
|
156
|
+
import { emit } from 'xstate';
|
|
157
|
+
|
|
158
|
+
const machine = createMachine({
|
|
159
|
+
// ...
|
|
160
|
+
on: {
|
|
161
|
+
something: {
|
|
162
|
+
actions: emit({
|
|
163
|
+
type: 'emitted',
|
|
164
|
+
some: 'data'
|
|
165
|
+
})
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
// ...
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
const actor = createActor(machine).start();
|
|
172
|
+
|
|
173
|
+
actor.on('emitted', (event) => {
|
|
174
|
+
console.log(event);
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
actor.send({ type: 'something' });
|
|
178
|
+
// logs:
|
|
179
|
+
// {
|
|
180
|
+
// type: 'emitted',
|
|
181
|
+
// some: 'data'
|
|
182
|
+
// }
|
|
183
|
+
```
|
|
184
|
+
*/
|
|
185
|
+
function emit(
|
|
186
|
+
/**
|
|
187
|
+
* The event to emit, or an expression that returns an event to emit.
|
|
188
|
+
*/
|
|
189
|
+
eventOrExpr) {
|
|
190
|
+
function emit(args, params) {
|
|
191
|
+
{
|
|
192
|
+
throw new Error(`This isn't supposed to be called`);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
emit.type = 'xstate.emit';
|
|
196
|
+
emit.event = eventOrExpr;
|
|
197
|
+
emit.resolve = resolveEmit;
|
|
198
|
+
emit.execute = executeEmit;
|
|
199
|
+
return emit;
|
|
200
|
+
}
|
|
201
|
+
|
|
132
202
|
/**
|
|
133
203
|
*
|
|
134
204
|
* @remarks
|
|
@@ -276,6 +346,9 @@ function executeSendTo(actorScope, params) {
|
|
|
276
346
|
*/
|
|
277
347
|
function sendTo(to, eventOrExpr, options) {
|
|
278
348
|
function sendTo(args, params) {
|
|
349
|
+
{
|
|
350
|
+
throw new Error(`This isn't supposed to be called`);
|
|
351
|
+
}
|
|
279
352
|
}
|
|
280
353
|
sendTo.type = 'xsnapshot.sendTo';
|
|
281
354
|
sendTo.to = to;
|
|
@@ -304,12 +377,22 @@ function sendParent(event, options) {
|
|
|
304
377
|
* @param options Options to pass into the send action creator.
|
|
305
378
|
*/
|
|
306
379
|
function forwardTo(target, options) {
|
|
380
|
+
if ((!target || typeof target === 'function')) {
|
|
381
|
+
const originalTarget = target;
|
|
382
|
+
target = (...args) => {
|
|
383
|
+
const resolvedTarget = typeof originalTarget === 'function' ? originalTarget(...args) : originalTarget;
|
|
384
|
+
if (!resolvedTarget) {
|
|
385
|
+
throw new Error(`Attempted to forward event to undefined actor. This risks an infinite loop in the sender.`);
|
|
386
|
+
}
|
|
387
|
+
return resolvedTarget;
|
|
388
|
+
};
|
|
389
|
+
}
|
|
307
390
|
return sendTo(target, ({
|
|
308
391
|
event
|
|
309
392
|
}) => event, options);
|
|
310
393
|
}
|
|
311
394
|
|
|
312
|
-
function resolveEnqueueActions(actorScope, snapshot, args,
|
|
395
|
+
function resolveEnqueueActions(actorScope, snapshot, args, actionParams, {
|
|
313
396
|
collect
|
|
314
397
|
}) {
|
|
315
398
|
const actions = [];
|
|
@@ -338,6 +421,9 @@ function resolveEnqueueActions(actorScope, snapshot, args, _actionParams, {
|
|
|
338
421
|
enqueue.stopChild = (...args) => {
|
|
339
422
|
actions.push(stopChild(...args));
|
|
340
423
|
};
|
|
424
|
+
enqueue.emit = (...args) => {
|
|
425
|
+
actions.push(emit(...args));
|
|
426
|
+
};
|
|
341
427
|
collect({
|
|
342
428
|
context: args.context,
|
|
343
429
|
event: args.event,
|
|
@@ -345,7 +431,7 @@ function resolveEnqueueActions(actorScope, snapshot, args, _actionParams, {
|
|
|
345
431
|
check: guard => evaluateGuard(guard, snapshot.context, args.event, snapshot),
|
|
346
432
|
self: actorScope.self,
|
|
347
433
|
system: actorScope.system
|
|
348
|
-
});
|
|
434
|
+
}, actionParams);
|
|
349
435
|
return [snapshot, undefined, actions];
|
|
350
436
|
}
|
|
351
437
|
/**
|
|
@@ -370,6 +456,9 @@ function resolveEnqueueActions(actorScope, snapshot, args, _actionParams, {
|
|
|
370
456
|
*/
|
|
371
457
|
function enqueueActions(collect) {
|
|
372
458
|
function enqueueActions(args, params) {
|
|
459
|
+
{
|
|
460
|
+
throw new Error(`This isn't supposed to be called`);
|
|
461
|
+
}
|
|
373
462
|
}
|
|
374
463
|
enqueueActions.type = 'xstate.enqueueActions';
|
|
375
464
|
enqueueActions.collect = collect;
|
|
@@ -414,6 +503,9 @@ function log(value = ({
|
|
|
414
503
|
event
|
|
415
504
|
}), label) {
|
|
416
505
|
function log(args, params) {
|
|
506
|
+
{
|
|
507
|
+
throw new Error(`This isn't supposed to be called`);
|
|
508
|
+
}
|
|
417
509
|
}
|
|
418
510
|
log.type = 'xstate.log';
|
|
419
511
|
log.value = value;
|
|
@@ -423,4 +515,4 @@ function log(value = ({
|
|
|
423
515
|
return log;
|
|
424
516
|
}
|
|
425
517
|
|
|
426
|
-
export { SpecialTargets as S, assign as a,
|
|
518
|
+
export { SpecialTargets as S, assign as a, enqueueActions as b, sendTo as c, emit as e, forwardTo as f, log as l, sendParent as s };
|