xstate 6.0.0-alpha.6 → 6.0.0-alpha.7
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/README.md +4 -2
- package/dist/{StateMachine-f310bc72.esm.js → StateMachine-1ff90553.esm.js} +6 -6
- package/dist/{StateMachine-4deb4090.development.esm.js → StateMachine-2b259bff.development.esm.js} +6 -6
- package/dist/{StateMachine-445a8480.cjs.js → StateMachine-6673bf76.cjs.js} +6 -6
- package/dist/{StateMachine-f83f01f9.development.cjs.js → StateMachine-68fe6077.development.cjs.js} +6 -6
- package/dist/declarations/src/createActor.d.ts +1 -1
- package/dist/declarations/src/createMachineFromConfig.d.ts +2 -1
- package/dist/declarations/src/index.d.ts +1 -1
- package/dist/declarations/src/setup.d.ts +95 -28
- package/dist/declarations/src/spawn.d.ts +3 -3
- package/dist/declarations/src/stateUtils.d.ts +1 -0
- package/dist/declarations/src/system.d.ts +1 -1
- package/dist/declarations/src/types.d.ts +15 -10
- package/dist/declarations/src/types.v6.d.ts +16 -14
- package/dist/{index-918ab496.cjs.js → index-87499be0.cjs.js} +51 -33
- package/dist/{index-ccbe7c0b.development.esm.js → index-9594f050.development.esm.js} +51 -33
- package/dist/{index-9cce3480.esm.js → index-aaf74d09.esm.js} +51 -33
- package/dist/{index-ebaf6fd8.development.cjs.js → index-b063a967.development.cjs.js} +51 -33
- package/dist/xstate-actors.cjs.js +1 -1
- package/dist/xstate-actors.development.cjs.js +1 -1
- package/dist/xstate-actors.development.esm.js +1 -1
- package/dist/xstate-actors.esm.js +1 -1
- package/dist/xstate-actors.umd.min.js +1 -1
- package/dist/xstate-actors.umd.min.js.map +1 -1
- package/dist/xstate-graph.cjs.js +2 -2
- package/dist/xstate-graph.development.cjs.js +2 -2
- package/dist/xstate-graph.development.esm.js +2 -2
- package/dist/xstate-graph.esm.js +2 -2
- package/dist/xstate-graph.umd.min.js +1 -1
- package/dist/xstate-graph.umd.min.js.map +1 -1
- package/dist/xstate.cjs.js +55 -3
- package/dist/xstate.cjs.mjs +1 -0
- package/dist/xstate.development.cjs.js +55 -3
- package/dist/xstate.development.cjs.mjs +1 -0
- package/dist/xstate.development.esm.js +57 -6
- package/dist/xstate.esm.js +57 -6
- package/dist/xstate.umd.min.js +1 -1
- package/dist/xstate.umd.min.js.map +1 -1
- package/package.json +1 -1
|
@@ -126,6 +126,7 @@ export interface TransitionConfig<TContext extends MachineContext, TExpressionEv
|
|
|
126
126
|
guard?: unknown;
|
|
127
127
|
reenter?: boolean;
|
|
128
128
|
target?: TransitionTarget | undefined;
|
|
129
|
+
context?: Partial<TContext>;
|
|
129
130
|
to?: TransitionConfigFunction<TContext, TExpressionEvent, TEvent, TEmitted, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta>;
|
|
130
131
|
meta?: TMeta;
|
|
131
132
|
description?: string;
|
|
@@ -144,7 +145,7 @@ any, // TGuardMap
|
|
|
144
145
|
any>;
|
|
145
146
|
export interface InvokeDefinition<TContext extends MachineContext, TEvent extends EventObject, TEmitted extends EventObject, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actors'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays']> {
|
|
146
147
|
id: string;
|
|
147
|
-
|
|
148
|
+
registryKey: string | undefined;
|
|
148
149
|
logic: string | AnyActorLogic | (({ actors, context, event, self }: {
|
|
149
150
|
actors: TActorMap;
|
|
150
151
|
context: TContext;
|
|
@@ -201,7 +202,7 @@ export type TransitionConfigFunction<TContext extends MachineContext, TCurrentEv
|
|
|
201
202
|
delays: TDelayMap;
|
|
202
203
|
}, enq: EnqueueObject<TEvent, TEmitted>) => {
|
|
203
204
|
target?: string | string[];
|
|
204
|
-
context?: _TCtx
|
|
205
|
+
context?: Partial<_TCtx>;
|
|
205
206
|
reenter?: boolean;
|
|
206
207
|
meta?: TMeta;
|
|
207
208
|
} | void;
|
|
@@ -222,7 +223,7 @@ type ActorImplementationsBySrc<TActor extends ProvidedActor> = {
|
|
|
222
223
|
type DistributeActors<TContext extends MachineContext, TEvent extends EventObject, TActor extends ProvidedActor, _TAction extends ParameterizedObject, _TGuard extends ParameterizedObject, _TDelay extends string, TEmitted extends EventObject, TMeta extends MetaObject, TSpecificActor extends ProvidedActor> = TSpecificActor extends {
|
|
223
224
|
src: infer TSrc;
|
|
224
225
|
} ? Compute<{
|
|
225
|
-
|
|
226
|
+
registryKey?: string;
|
|
226
227
|
/** The source of the machine to be invoked, or the machine itself. */
|
|
227
228
|
src: TSrc | (({ actors, context, event, self }: {
|
|
228
229
|
actors: ActorImplementationsBySrc<TActor>;
|
|
@@ -256,7 +257,7 @@ type DistributeActors<TContext extends MachineContext, TEvent extends EventObjec
|
|
|
256
257
|
[K in RequiredActorOptions<TSpecificActor>]: unknown;
|
|
257
258
|
}> | {
|
|
258
259
|
id?: never;
|
|
259
|
-
|
|
260
|
+
registryKey?: string;
|
|
260
261
|
src: string | AnyActorLogic | (({ actors, context, event, self }: {
|
|
261
262
|
actors: ActorImplementationsBySrc<TActor>;
|
|
262
263
|
context: TContext;
|
|
@@ -279,7 +280,7 @@ export type InvokeConfig<TContext extends MachineContext, TEvent extends EventOb
|
|
|
279
280
|
* will be the machine's own `id`, or the URL (from `src`).
|
|
280
281
|
*/
|
|
281
282
|
id?: string;
|
|
282
|
-
|
|
283
|
+
registryKey?: string;
|
|
283
284
|
/** The source of the machine to be invoked, or the machine itself. */
|
|
284
285
|
src: string | AnyActorLogic | (({ actors, context, event, self }: {
|
|
285
286
|
actors: ActorImplementationsBySrc<TActor>;
|
|
@@ -511,8 +512,8 @@ export interface ActorOptions<TLogic extends AnyActorLogic> {
|
|
|
511
512
|
id?: string;
|
|
512
513
|
/** @deprecated Use `inspect` instead. */
|
|
513
514
|
devTools?: never;
|
|
514
|
-
/** The
|
|
515
|
-
|
|
515
|
+
/** The registry key to register this actor under. */
|
|
516
|
+
registryKey?: string;
|
|
516
517
|
/** The input data to pass to the actor. */
|
|
517
518
|
input?: InputFrom<TLogic>;
|
|
518
519
|
/**
|
|
@@ -861,6 +862,10 @@ export type TagsFrom<TMachine extends AnyStateMachine> = Parameters<StateFrom<TM
|
|
|
861
862
|
export interface ActorSystemInfo {
|
|
862
863
|
actors: Record<string, AnyActorRef>;
|
|
863
864
|
}
|
|
865
|
+
export type SystemRegistry = Record<string, AnyActorLogic>;
|
|
866
|
+
export type RegistryKeyForLogic<TLogic extends AnyActorLogic, TSystemRegistry extends SystemRegistry> = string extends keyof TSystemRegistry ? string : Values<{
|
|
867
|
+
[K in keyof TSystemRegistry & string]: ActorRefFromLogic<TLogic> extends ActorRefFromLogic<TSystemRegistry[K]> ? K : never;
|
|
868
|
+
}>;
|
|
864
869
|
export type RequiredActorOptions<TActor extends ProvidedActor> = (undefined extends TActor['id'] ? never : 'id') | (undefined extends InputFrom<TActor['logic']> ? never : 'input');
|
|
865
870
|
export type RequiredLogicInput<TLogic extends AnyActorLogic> = undefined extends InputFrom<TLogic> ? never : 'input';
|
|
866
871
|
type ExtractLiteralString<T extends string | undefined> = T extends string ? string extends T ? never : T : never;
|
|
@@ -1028,7 +1033,7 @@ export interface SubscribeToMappers<TSnapshot extends Snapshot<unknown>, TOutput
|
|
|
1028
1033
|
done?: (output: TOutput) => TMappedEvent;
|
|
1029
1034
|
error?: (error: unknown) => TMappedEvent;
|
|
1030
1035
|
}
|
|
1031
|
-
export type EnqueueObject<TEvent extends EventObject, TEmittedEvent extends EventObject> = {
|
|
1036
|
+
export type EnqueueObject<TEvent extends EventObject, TEmittedEvent extends EventObject, TSystemRegistry extends SystemRegistry = SystemRegistry> = {
|
|
1032
1037
|
cancel: (id: string) => void;
|
|
1033
1038
|
raise: (ev: TEvent, options?: {
|
|
1034
1039
|
id?: string;
|
|
@@ -1038,7 +1043,7 @@ export type EnqueueObject<TEvent extends EventObject, TEmittedEvent extends Even
|
|
|
1038
1043
|
input?: InputFrom<T>;
|
|
1039
1044
|
id?: string;
|
|
1040
1045
|
syncSnapshot?: boolean;
|
|
1041
|
-
|
|
1046
|
+
registryKey?: RegistryKeyForLogic<T, TSystemRegistry>;
|
|
1042
1047
|
}) => ActorFromLogic<T>;
|
|
1043
1048
|
emit: (emittedEvent: TEmittedEvent) => void;
|
|
1044
1049
|
<T extends (...args: any[]) => any>(fn: T, ...args: Parameters<T>): void;
|
|
@@ -1085,7 +1090,7 @@ export type Action<TContext extends MachineContext, TEvent extends EventObject,
|
|
|
1085
1090
|
system?: AnyActorSystem;
|
|
1086
1091
|
params: TParams;
|
|
1087
1092
|
}, enqueue: EnqueueObject<TEvent, TEmittedEvent>) => {
|
|
1088
|
-
context?: _TCtx
|
|
1093
|
+
context?: Partial<_TCtx>;
|
|
1089
1094
|
children?: Record<string, AnyActor | undefined>;
|
|
1090
1095
|
} | void;
|
|
1091
1096
|
export type AnyAction = Action<MachineContext, EventObject, EventObject, Implementations['actions'], Implementations['actors'], Implementations['guards'], Implementations['delays']> | {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { StandardSchemaV1 } from "./schema.types.js";
|
|
2
2
|
import { MachineSnapshot } from "./State.js";
|
|
3
|
-
import { Action, ActorLogic, ActorRef, ActorRefFromLogic, ActorSelf, AnyActorLogic, AnyActorRef, Compute, DoneActorEvent, DoNotInfer, EventDescriptor, EventObject, ExtractEvent, InitialContext, InputFrom, IsNever, MetaObject, NonReducibleUnknown, SingleOrArray, SnapshotEvent, StateValue, TODO, TransitionConfigFunction, Values, AnyStateNode } from "./types.js";
|
|
3
|
+
import { Action, ActorLogic, ActorRef, ActorRefFromLogic, ActorSelf, AnyActorLogic, AnyActorRef, Compute, DoneActorEvent, DoNotInfer, EventDescriptor, EventObject, ExtractEvent, InitialContext, InputFrom, IsNever, MetaObject, NonReducibleUnknown, SingleOrArray, SnapshotEvent, StateValue, TODO, TransitionConfigFunction, Values, AnyStateNode, SystemRegistry } from "./types.js";
|
|
4
4
|
import { MachineContext, Mapper } from "./types.js";
|
|
5
5
|
import { LowInfer } from "./types.js";
|
|
6
6
|
import { DoneStateEvent } from "./types.js";
|
|
@@ -61,7 +61,7 @@ type MachineSchemas<TContextSchema extends StandardSchemaV1, TEventSchemaMap ext
|
|
|
61
61
|
children?: TChildrenSchemaMap;
|
|
62
62
|
};
|
|
63
63
|
export type AnyMachineSchemas = MachineSchemas<StandardSchemaV1, Record<string, StandardSchemaV1>, Record<string, StandardSchemaV1>, StandardSchemaV1, StandardSchemaV1, StandardSchemaV1, StandardSchemaV1, Record<string, StandardSchemaV1>>;
|
|
64
|
-
export type Next_MachineConfig<TContextSchema extends StandardSchemaV1, TEventSchemaMap extends Record<string, StandardSchemaV1>, TEmittedSchemaMap extends Record<string, StandardSchemaV1>, TInputSchema extends StandardSchemaV1, TOutputSchema extends StandardSchemaV1, TMetaSchema extends StandardSchemaV1, TTagSchema extends StandardSchemaV1, TChildrenSchemaMap extends Record<string, StandardSchemaV1>, TContext extends MachineContext = InferOutput<TContextSchema, MachineContext>, TEvent extends EventObject = InferEvents<TEventSchemaMap>, TChildren extends Record<string, AnyActorRef | undefined> = InferChildren<TChildrenSchemaMap>, TDelays extends string = string, _TTag extends string = string, TActionMap extends Implementations['actions'] = Implementations['actions'], TActorMap extends Implementations['actors'] = Implementations['actors'], TGuardMap extends Implementations['guards'] = Implementations['guards'], TDelayMap extends Implementations['delays'] = Implementations['delays'], TContextRequired extends boolean = IsNever<TContext> extends true ? false : true> = (DistributiveOmit<Next_StateNodeConfig<TContext, DoNotInfer<InferEvents<TEventSchemaMap>>, DoNotInfer<TDelays>, DoNotInfer<StandardSchemaV1.InferOutput<TTagSchema> & string>, DoNotInfer<StandardSchemaV1.InferOutput<TOutputSchema>>, DoNotInfer<InferEvents<TEmittedSchemaMap>>, DoNotInfer<InferOutput<TMetaSchema, MetaObject>>, DoNotInfer<TChildren>, DoNotInfer<TActionMap>, DoNotInfer<TActorMap>, DoNotInfer<TGuardMap>, DoNotInfer<TDelayMap>>, 'output'> & {
|
|
64
|
+
export type Next_MachineConfig<TContextSchema extends StandardSchemaV1, TEventSchemaMap extends Record<string, StandardSchemaV1>, TEmittedSchemaMap extends Record<string, StandardSchemaV1>, TInputSchema extends StandardSchemaV1, TOutputSchema extends StandardSchemaV1, TMetaSchema extends StandardSchemaV1, TTagSchema extends StandardSchemaV1, TChildrenSchemaMap extends Record<string, StandardSchemaV1>, TContext extends MachineContext = InferOutput<TContextSchema, MachineContext>, TEvent extends EventObject = InferEvents<TEventSchemaMap>, TChildren extends Record<string, AnyActorRef | undefined> = InferChildren<TChildrenSchemaMap>, TDelays extends string = string, _TTag extends string = string, TActionMap extends Implementations['actions'] = Implementations['actions'], TActorMap extends Implementations['actors'] = Implementations['actors'], TGuardMap extends Implementations['guards'] = Implementations['guards'], TDelayMap extends Implementations['delays'] = Implementations['delays'], TContextRequired extends boolean = IsNever<TContext> extends true ? false : true, TSystemRegistry extends SystemRegistry = SystemRegistry> = (DistributiveOmit<Next_StateNodeConfig<TContext, DoNotInfer<InferEvents<TEventSchemaMap>>, DoNotInfer<TDelays>, DoNotInfer<StandardSchemaV1.InferOutput<TTagSchema> & string>, DoNotInfer<StandardSchemaV1.InferOutput<TOutputSchema>>, DoNotInfer<InferEvents<TEmittedSchemaMap>>, DoNotInfer<InferOutput<TMetaSchema, MetaObject>>, DoNotInfer<TChildren>, DoNotInfer<TActionMap>, DoNotInfer<TActorMap>, DoNotInfer<TGuardMap>, DoNotInfer<TDelayMap>, Record<string, unknown> | undefined, Record<string, unknown>, DoNotInfer<TSystemRegistry>>, 'output'> & {
|
|
65
65
|
internalEvents?: readonly InternalEventDescriptorFor<InferEvents<TEventSchemaMap>>[];
|
|
66
66
|
schemas?: MachineSchemas<TContextSchema, TEventSchemaMap, TEmittedSchemaMap, TInputSchema, TOutputSchema, TMetaSchema, TTagSchema, TChildrenSchemaMap>;
|
|
67
67
|
actions?: TActionMap;
|
|
@@ -117,14 +117,14 @@ type ChildIdForLogic<TLogic extends AnyActorLogic, TChildren extends Record<stri
|
|
|
117
117
|
[K in keyof TChildren & string]: ActorRefFromLogic<TLogic> extends NonNullable<TChildren[K]> ? K : never;
|
|
118
118
|
}> : string;
|
|
119
119
|
type LogicForChildRef<TActorRef> = NonNullable<TActorRef> extends ActorRef<infer TSnapshot, infer TEvent, infer TEmitted, any> ? ActorLogic<TSnapshot, TEvent, any, any, TEmitted> : never;
|
|
120
|
-
type InlineChildInvokeConfig<TContext extends MachineContext, TEvent extends EventObject, TEmitted extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actors'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TMeta extends MetaObject> = Values<{
|
|
121
|
-
[K in keyof TChildren & string]: Next_InvokeConfigBase<TContext, TEvent, TEmitted, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta> & {
|
|
120
|
+
type InlineChildInvokeConfig<TContext extends MachineContext, TEvent extends EventObject, TEmitted extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actors'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TMeta extends MetaObject, TSystemRegistry extends SystemRegistry> = Values<{
|
|
121
|
+
[K in keyof TChildren & string]: Next_InvokeConfigBase<TContext, TEvent, TEmitted, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta, TSystemRegistry> & {
|
|
122
122
|
id: K;
|
|
123
123
|
src: LogicForChildRef<TChildren[K]>;
|
|
124
124
|
input?: ((args: InvokeInputArgs<TContext, TEvent, TEmitted, TChildren>) => unknown) | NonReducibleUnknown;
|
|
125
125
|
};
|
|
126
126
|
}>;
|
|
127
|
-
type InlineInvokeConfig<TContext extends MachineContext, TEvent extends EventObject, TEmitted extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actors'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TMeta extends MetaObject> = HasExplicitChildren<TChildren> extends true ? InlineChildInvokeConfig<TContext, TEvent, TEmitted, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta> : Next_InvokeConfigBase<TContext, TEvent, TEmitted, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta> & {
|
|
127
|
+
type InlineInvokeConfig<TContext extends MachineContext, TEvent extends EventObject, TEmitted extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actors'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TMeta extends MetaObject, TSystemRegistry extends SystemRegistry> = HasExplicitChildren<TChildren> extends true ? InlineChildInvokeConfig<TContext, TEvent, TEmitted, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta, TSystemRegistry> : Next_InvokeConfigBase<TContext, TEvent, TEmitted, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta, TSystemRegistry> & {
|
|
128
128
|
src: AnyActorLogic;
|
|
129
129
|
input?: ((args: InvokeInputArgs<TContext, TEvent, TEmitted, TChildren>) => unknown) | NonReducibleUnknown;
|
|
130
130
|
};
|
|
@@ -138,19 +138,19 @@ type InlineInvokeConfig<TContext extends MachineContext, TEvent extends EventObj
|
|
|
138
138
|
* - A branch for inline (unregistered) actor logic values, whose `input` cannot
|
|
139
139
|
* be correlated (the config is not generic over inline logic).
|
|
140
140
|
*/
|
|
141
|
-
export type Next_InvokeConfig<TContext extends MachineContext, TEvent extends EventObject, TEmitted extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actors'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TMeta extends MetaObject> = string extends keyof TActorMap ? HasExplicitChildren<TChildren> extends true ? InlineInvokeConfig<TContext, TEvent, TEmitted, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta> : Next_InvokeConfigBase<TContext, TEvent, TEmitted, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta> & {
|
|
141
|
+
export type Next_InvokeConfig<TContext extends MachineContext, TEvent extends EventObject, TEmitted extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actors'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TMeta extends MetaObject, TSystemRegistry extends SystemRegistry = SystemRegistry> = string extends keyof TActorMap ? HasExplicitChildren<TChildren> extends true ? InlineInvokeConfig<TContext, TEvent, TEmitted, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta, TSystemRegistry> : Next_InvokeConfigBase<TContext, TEvent, TEmitted, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta, TSystemRegistry> & {
|
|
142
142
|
src: string | AnyActorLogic | ((args: InvokeSrcArgs<TContext, TEvent, TActorMap>) => string | AnyActorLogic);
|
|
143
143
|
input?: ((args: InvokeInputArgs<TContext, TEvent, TEmitted, TChildren>) => unknown) | NonReducibleUnknown;
|
|
144
144
|
} : {
|
|
145
|
-
[K in keyof TActorMap & string]: Next_InvokeConfigBase<TContext, TEvent, TEmitted, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta> & {
|
|
145
|
+
[K in keyof TActorMap & string]: Next_InvokeConfigBase<TContext, TEvent, TEmitted, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta, TSystemRegistry> & {
|
|
146
146
|
src: K | TActorMap[K] | ((args: InvokeSrcArgs<TContext, TEvent, TActorMap>) => K | TActorMap[K]);
|
|
147
147
|
id?: ChildIdForLogic<TActorMap[K], TChildren>;
|
|
148
148
|
input?: ((args: InvokeInputArgs<TContext, TEvent, TEmitted, TChildren>) => InputFrom<TActorMap[K]>) | InputFrom<TActorMap[K]>;
|
|
149
149
|
};
|
|
150
|
-
}[keyof TActorMap & string] | InlineInvokeConfig<TContext, TEvent, TEmitted, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta>;
|
|
151
|
-
interface Next_InvokeConfigBase<TContext extends MachineContext, TEvent extends EventObject, TEmitted extends EventObject, _TChildren extends Record<string, AnyActorRef | undefined>, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actors'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TMeta extends MetaObject> {
|
|
150
|
+
}[keyof TActorMap & string] | InlineInvokeConfig<TContext, TEvent, TEmitted, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta, TSystemRegistry>;
|
|
151
|
+
interface Next_InvokeConfigBase<TContext extends MachineContext, TEvent extends EventObject, TEmitted extends EventObject, _TChildren extends Record<string, AnyActorRef | undefined>, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actors'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TMeta extends MetaObject, TSystemRegistry extends SystemRegistry> {
|
|
152
152
|
id?: string;
|
|
153
|
-
|
|
153
|
+
registryKey?: keyof TSystemRegistry & string;
|
|
154
154
|
onDone?: Next_TransitionConfigOrTarget<TContext, DoneActorEvent<any>, TEvent, TEmitted, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta>;
|
|
155
155
|
onError?: Next_TransitionConfigOrTarget<TContext, ErrorEvent, TEvent, TEmitted, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta>;
|
|
156
156
|
onSnapshot?: Next_TransitionConfigOrTarget<TContext, SnapshotEvent<any>, TEvent, TEmitted, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta>;
|
|
@@ -214,7 +214,7 @@ type Next_RouteConfig<TContext extends MachineContext, TEvent extends EventObjec
|
|
|
214
214
|
}) => Record<string, unknown>);
|
|
215
215
|
});
|
|
216
216
|
type Next_ChoiceConfigFunction<TContext extends MachineContext, TCurrentEvent extends EventObject, TEvent extends EventObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actors'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TMeta extends MetaObject, _TCtx = [TContext] extends [never] ? any : TContext> = (args: Next_ChoiceArgs<TContext, TCurrentEvent, TEvent, TActionMap, TActorMap, TGuardMap, TDelayMap, _TCtx>) => Next_ChoiceTarget<TMeta>;
|
|
217
|
-
export type Next_StateNodeConfig<TContext extends MachineContext, TEvent extends EventObject, TDelays extends string, TTag extends string, _TOutput, TEmitted extends EventObject, TMeta extends MetaObject, TChildren extends Record<string, AnyActorRef | undefined>, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actors'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TInput = Record<string, unknown> | undefined, TInputMap extends Record<string, unknown> = Record<string, unknown
|
|
217
|
+
export type Next_StateNodeConfig<TContext extends MachineContext, TEvent extends EventObject, TDelays extends string, TTag extends string, _TOutput, TEmitted extends EventObject, TMeta extends MetaObject, TChildren extends Record<string, AnyActorRef | undefined>, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actors'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TInput = Record<string, unknown> | undefined, TInputMap extends Record<string, unknown> = Record<string, unknown>, TSystemRegistry extends SystemRegistry = SystemRegistry> = Next_RegularStateNodeConfig<TContext, TEvent, TDelays, TTag, _TOutput, TEmitted, TMeta, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, TInput, TInputMap, TSystemRegistry> | Next_ChoiceStateNodeConfig<TContext, TEvent, TTag, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap>;
|
|
218
218
|
interface Next_ChoiceStateNodeConfig<TContext extends MachineContext, TEvent extends EventObject, TTag extends string, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actors'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays']> {
|
|
219
219
|
contextSchema?: StandardSchemaV1;
|
|
220
220
|
type: 'choice';
|
|
@@ -241,7 +241,7 @@ interface Next_ChoiceStateNodeConfig<TContext extends MachineContext, TEvent ext
|
|
|
241
241
|
output?: never;
|
|
242
242
|
target?: never;
|
|
243
243
|
}
|
|
244
|
-
interface Next_RegularStateNodeConfig<TContext extends MachineContext, TEvent extends EventObject, TDelays extends string, TTag extends string, _TOutput, TEmitted extends EventObject, TMeta extends MetaObject, TChildren extends Record<string, AnyActorRef | undefined>, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actors'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TInput = Record<string, unknown> | undefined, TInputMap extends Record<string, unknown> = Record<string, unknown
|
|
244
|
+
interface Next_RegularStateNodeConfig<TContext extends MachineContext, TEvent extends EventObject, TDelays extends string, TTag extends string, _TOutput, TEmitted extends EventObject, TMeta extends MetaObject, TChildren extends Record<string, AnyActorRef | undefined>, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actors'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TInput = Record<string, unknown> | undefined, TInputMap extends Record<string, unknown> = Record<string, unknown>, TSystemRegistry extends SystemRegistry = SystemRegistry> {
|
|
245
245
|
contextSchema?: StandardSchemaV1;
|
|
246
246
|
/** The initial state transition. */
|
|
247
247
|
initial?: string | {
|
|
@@ -272,13 +272,13 @@ interface Next_RegularStateNodeConfig<TContext extends MachineContext, TEvent ex
|
|
|
272
272
|
*/
|
|
273
273
|
states?: {
|
|
274
274
|
[K in string]: Next_StateNodeConfig<TContext, TEvent, TDelays, TTag, any, // TOutput,
|
|
275
|
-
TEmitted, TMeta, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, LookupInput<TInputMap, K>, TInputMap>;
|
|
275
|
+
TEmitted, TMeta, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, LookupInput<TInputMap, K>, TInputMap, TSystemRegistry>;
|
|
276
276
|
};
|
|
277
277
|
/**
|
|
278
278
|
* The services to invoke upon entering this state node. These services will
|
|
279
279
|
* be stopped upon exiting this state node.
|
|
280
280
|
*/
|
|
281
|
-
invoke?: SingleOrArray<Next_InvokeConfig<TContext, TEvent, TEmitted, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta>>;
|
|
281
|
+
invoke?: SingleOrArray<Next_InvokeConfig<TContext, TEvent, TEmitted, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta, TSystemRegistry>>;
|
|
282
282
|
/** The mapping of event types to their potential transition(s). */
|
|
283
283
|
on?: {
|
|
284
284
|
[K in EventDescriptor<TEvent>]?: Next_TransitionConfigOrTarget<TContext, ExtractEvent<TEvent, K>, TEvent, TEmitted, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta>;
|
|
@@ -366,6 +366,7 @@ interface Next_RegularStateNodeConfig<TContext extends MachineContext, TEvent ex
|
|
|
366
366
|
}
|
|
367
367
|
export type Next_TransitionConfigOrTarget<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject, TEmitted extends EventObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actors'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TMeta extends MetaObject> = undefined | {
|
|
368
368
|
target?: string | string[];
|
|
369
|
+
context?: Partial<TContext>;
|
|
369
370
|
description?: string;
|
|
370
371
|
reenter?: boolean;
|
|
371
372
|
meta?: TMeta;
|
|
@@ -375,6 +376,7 @@ export type Next_TransitionConfigOrTarget<TContext extends MachineContext, TExpr
|
|
|
375
376
|
}) => Record<string, unknown>);
|
|
376
377
|
} | {
|
|
377
378
|
to?: TransitionConfigFunction<TContext, TExpressionEvent, TEvent, TEmitted, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta>;
|
|
379
|
+
context?: Partial<TContext>;
|
|
378
380
|
description?: string;
|
|
379
381
|
reenter?: boolean;
|
|
380
382
|
meta?: TMeta;
|
|
@@ -339,6 +339,12 @@ function createSubscriptionLogic() {
|
|
|
339
339
|
// Singleton logic instance
|
|
340
340
|
const subscriptionLogic = /* #__PURE__ */createSubscriptionLogic();
|
|
341
341
|
|
|
342
|
+
function mergeContextPatch$1(context, patch) {
|
|
343
|
+
return {
|
|
344
|
+
...context,
|
|
345
|
+
...patch
|
|
346
|
+
};
|
|
347
|
+
}
|
|
342
348
|
function pushBuiltInAction(actions, action, ...args) {
|
|
343
349
|
actions.push({
|
|
344
350
|
action,
|
|
@@ -543,8 +549,8 @@ function resolveActionsWithContext(currentSnapshot, event, actorScope, actions)
|
|
|
543
549
|
const res = specialAction(actionArgs, emptyEnqueueObject);
|
|
544
550
|
if (res && ('context' in res || 'children' in res)) {
|
|
545
551
|
intermediateSnapshot = cloneMachineSnapshot(intermediateSnapshot, {
|
|
546
|
-
...(
|
|
547
|
-
context: res.context
|
|
552
|
+
...(res.context !== undefined ? {
|
|
553
|
+
context: mergeContextPatch$1(intermediateSnapshot.context, res.context)
|
|
548
554
|
} : {}),
|
|
549
555
|
...('children' in res ? {
|
|
550
556
|
children: res.children
|
|
@@ -1250,6 +1256,12 @@ function initialMicrostep(root, preInitialState, actorScope, initEvent, internal
|
|
|
1250
1256
|
toJSON: null
|
|
1251
1257
|
}], preInitialState, actorScope, initEvent, true, internalQueue);
|
|
1252
1258
|
}
|
|
1259
|
+
function mergeContextPatch(context, patch) {
|
|
1260
|
+
return {
|
|
1261
|
+
...context,
|
|
1262
|
+
...patch
|
|
1263
|
+
};
|
|
1264
|
+
}
|
|
1253
1265
|
|
|
1254
1266
|
/** https://www.w3.org/TR/scxml/#microstepProcedure */
|
|
1255
1267
|
function microstep(transitions, currentSnapshot, actorScope, event, isInitial, internalQueue) {
|
|
@@ -1283,8 +1295,8 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
|
|
|
1283
1295
|
delays: currentSnapshot.machine.implementations.delays,
|
|
1284
1296
|
input
|
|
1285
1297
|
}, enqueue);
|
|
1286
|
-
if (res?.context) {
|
|
1287
|
-
updatedContext = res.context;
|
|
1298
|
+
if (res?.context !== undefined) {
|
|
1299
|
+
updatedContext = mergeContextPatch(context, res.context);
|
|
1288
1300
|
}
|
|
1289
1301
|
return [actions, updatedContext, internalEvents];
|
|
1290
1302
|
}
|
|
@@ -1357,8 +1369,8 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
|
|
|
1357
1369
|
transitionActions.push(...toArray(t.actions));
|
|
1358
1370
|
}
|
|
1359
1371
|
const res = getCurrentTransitionResult(t);
|
|
1360
|
-
if (res.context) {
|
|
1361
|
-
context = res.context;
|
|
1372
|
+
if (res.context !== undefined) {
|
|
1373
|
+
context = mergeContextPatch(context, res.context);
|
|
1362
1374
|
}
|
|
1363
1375
|
if (res.actions) {
|
|
1364
1376
|
transitionActions.push(...res.actions);
|
|
@@ -1541,18 +1553,23 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
|
|
|
1541
1553
|
children
|
|
1542
1554
|
});
|
|
1543
1555
|
}
|
|
1544
|
-
let context;
|
|
1556
|
+
let context = nextState.context;
|
|
1557
|
+
let contextChangedByEntry = false;
|
|
1545
1558
|
const stateInput = stateInputMap[stateNodeToEnter.id];
|
|
1546
1559
|
if (stateNodeToEnter.entry) {
|
|
1547
|
-
const [resultActions, nextContext, nextInternalEvents] = getStateActionsAndContext(stateNodeToEnter.entry,
|
|
1560
|
+
const [resultActions, nextContext, nextInternalEvents] = getStateActionsAndContext(stateNodeToEnter.entry, context, children, stateInput);
|
|
1548
1561
|
actions.push(...resultActions);
|
|
1549
1562
|
if (nextInternalEvents?.length) {
|
|
1550
1563
|
internalQueue.push(...nextInternalEvents);
|
|
1551
1564
|
}
|
|
1552
1565
|
if (nextContext) {
|
|
1553
1566
|
context = nextContext;
|
|
1567
|
+
contextChangedByEntry = true;
|
|
1554
1568
|
}
|
|
1555
1569
|
}
|
|
1570
|
+
if (contextChangedByEntry) {
|
|
1571
|
+
nextState.context = context;
|
|
1572
|
+
}
|
|
1556
1573
|
if (statesForDefaultEntry.has(stateNodeToEnter)) {
|
|
1557
1574
|
const {
|
|
1558
1575
|
actions: initialActions,
|
|
@@ -1571,9 +1588,6 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
|
|
|
1571
1588
|
nextState = resolvedState;
|
|
1572
1589
|
actions.length = 0;
|
|
1573
1590
|
executableActions.push(...resolvedActions);
|
|
1574
|
-
if (context) {
|
|
1575
|
-
nextState.context = context;
|
|
1576
|
-
}
|
|
1577
1591
|
if (stateNodeToEnter.type !== 'final') {
|
|
1578
1592
|
continue;
|
|
1579
1593
|
}
|
|
@@ -1709,7 +1723,7 @@ function getTransitionResult(transition, snapshot, event, actorScope) {
|
|
|
1709
1723
|
}) : transition.input;
|
|
1710
1724
|
return {
|
|
1711
1725
|
targets: transition.target,
|
|
1712
|
-
context:
|
|
1726
|
+
context: transition.context,
|
|
1713
1727
|
reenter: transition.reenter,
|
|
1714
1728
|
actions: undefined,
|
|
1715
1729
|
internalEvents: undefined,
|
|
@@ -2110,7 +2124,7 @@ function getPersistedSnapshot(snapshot, options) {
|
|
|
2110
2124
|
childrenJson[id] = {
|
|
2111
2125
|
snapshot: child.getPersistedSnapshot(options),
|
|
2112
2126
|
src: child.src,
|
|
2113
|
-
|
|
2127
|
+
registryKey: child.registryKey,
|
|
2114
2128
|
syncSnapshot: child._syncSnapshot
|
|
2115
2129
|
};
|
|
2116
2130
|
}
|
|
@@ -2361,7 +2375,7 @@ function matchesEventDescriptor(eventType, descriptor) {
|
|
|
2361
2375
|
function createScheduledEventId(actor, id) {
|
|
2362
2376
|
return `${actor.sessionId}.${id}`;
|
|
2363
2377
|
}
|
|
2364
|
-
function
|
|
2378
|
+
function createRuntimeSystem(rootActor, options) {
|
|
2365
2379
|
let idCounter = 0;
|
|
2366
2380
|
const children = new Map();
|
|
2367
2381
|
const keyedActors = new Map();
|
|
@@ -2467,25 +2481,25 @@ function createSystem(rootActor, options) {
|
|
|
2467
2481
|
},
|
|
2468
2482
|
_unregister: actor => {
|
|
2469
2483
|
children.delete(actor.sessionId);
|
|
2470
|
-
const
|
|
2471
|
-
if (
|
|
2472
|
-
keyedActors.delete(
|
|
2484
|
+
const registryKey = reverseKeyedActors.get(actor);
|
|
2485
|
+
if (registryKey !== undefined) {
|
|
2486
|
+
keyedActors.delete(registryKey);
|
|
2473
2487
|
reverseKeyedActors.delete(actor);
|
|
2474
2488
|
}
|
|
2475
2489
|
},
|
|
2476
|
-
get:
|
|
2477
|
-
return keyedActors.get(
|
|
2490
|
+
get: registryKey => {
|
|
2491
|
+
return keyedActors.get(registryKey);
|
|
2478
2492
|
},
|
|
2479
2493
|
getAll: () => {
|
|
2480
2494
|
return Object.fromEntries(keyedActors.entries());
|
|
2481
2495
|
},
|
|
2482
|
-
_set: (
|
|
2483
|
-
const existing = keyedActors.get(
|
|
2496
|
+
_set: (registryKey, actor) => {
|
|
2497
|
+
const existing = keyedActors.get(registryKey);
|
|
2484
2498
|
if (existing && existing !== actor) {
|
|
2485
|
-
throw new Error(`Actor with
|
|
2499
|
+
throw new Error(`Actor with registry key '${registryKey}' already exists.`);
|
|
2486
2500
|
}
|
|
2487
|
-
keyedActors.set(
|
|
2488
|
-
reverseKeyedActors.set(actor,
|
|
2501
|
+
keyedActors.set(registryKey, actor);
|
|
2502
|
+
reverseKeyedActors.set(actor, registryKey);
|
|
2489
2503
|
},
|
|
2490
2504
|
inspect: observerOrFn => {
|
|
2491
2505
|
const observer = toObserver(observerOrFn);
|
|
@@ -2849,7 +2863,7 @@ class Actor {
|
|
|
2849
2863
|
/** @internal Events relayed to other actors during the in-flight transition. */
|
|
2850
2864
|
this._collectedSent = [];
|
|
2851
2865
|
this._initialEffects = void 0;
|
|
2852
|
-
this.
|
|
2866
|
+
this.registryKey = void 0;
|
|
2853
2867
|
/** The globally unique process ID for this invocation. */
|
|
2854
2868
|
this.sessionId = void 0;
|
|
2855
2869
|
/** The system to which this actor belongs. */
|
|
@@ -2870,14 +2884,17 @@ class Actor {
|
|
|
2870
2884
|
parent,
|
|
2871
2885
|
syncSnapshot,
|
|
2872
2886
|
id,
|
|
2873
|
-
|
|
2887
|
+
registryKey,
|
|
2874
2888
|
inspect
|
|
2875
2889
|
} = resolvedOptions;
|
|
2876
|
-
this.system = parent ? parent.system :
|
|
2890
|
+
this.system = parent ? parent.system : resolvedOptions._systemRef?.current ?? createRuntimeSystem(this, {
|
|
2877
2891
|
clock,
|
|
2878
2892
|
logger,
|
|
2879
2893
|
timers: resolvedOptions.timers
|
|
2880
2894
|
});
|
|
2895
|
+
if (!parent && resolvedOptions._systemRef && !resolvedOptions._systemRef.current) {
|
|
2896
|
+
resolvedOptions._systemRef.current = this.system;
|
|
2897
|
+
}
|
|
2881
2898
|
if (inspect && !parent) {
|
|
2882
2899
|
// Always inspect at the system-level
|
|
2883
2900
|
this.system.inspect(toObserver(inspect));
|
|
@@ -2975,9 +2992,10 @@ class Actor {
|
|
|
2975
2992
|
|
|
2976
2993
|
// unified '@xstate.transition' event replaces '@xstate.actor'
|
|
2977
2994
|
|
|
2978
|
-
|
|
2979
|
-
|
|
2980
|
-
this.
|
|
2995
|
+
const resolvedRegistryKey = registryKey;
|
|
2996
|
+
if (resolvedRegistryKey) {
|
|
2997
|
+
this.registryKey = resolvedRegistryKey;
|
|
2998
|
+
this.system._set(resolvedRegistryKey, this);
|
|
2981
2999
|
}
|
|
2982
3000
|
|
|
2983
3001
|
// prepare to collect initial microsteps during initialTransition
|
|
@@ -3014,7 +3032,7 @@ class Actor {
|
|
|
3014
3032
|
// computation so they can't run against an inconsistent actor
|
|
3015
3033
|
this._deferred.length = 0;
|
|
3016
3034
|
}
|
|
3017
|
-
if (
|
|
3035
|
+
if (resolvedRegistryKey && this._snapshot.status !== 'active') {
|
|
3018
3036
|
this.system._unregister(this);
|
|
3019
3037
|
}
|
|
3020
3038
|
|
|
@@ -3279,8 +3297,8 @@ class Actor {
|
|
|
3279
3297
|
});
|
|
3280
3298
|
}
|
|
3281
3299
|
this.system._register(this.sessionId, this);
|
|
3282
|
-
if (this.
|
|
3283
|
-
this.system._set(this.
|
|
3300
|
+
if (this.registryKey) {
|
|
3301
|
+
this.system._set(this.registryKey, this);
|
|
3284
3302
|
}
|
|
3285
3303
|
this._processingStatus = ProcessingStatus.Running;
|
|
3286
3304
|
|