xstate 6.0.0-alpha.20 → 6.0.0-alpha.21
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/dist/{StateMachine-f2b70732.cjs.js → StateMachine-1b155670.cjs.js} +1 -1
- package/dist/{StateMachine-42f1d26c.esm.js → StateMachine-3c17fe3e.esm.js} +1 -1
- package/dist/{StateMachine-6661eb0d.development.cjs.js → StateMachine-550ff7f2.development.cjs.js} +1 -1
- package/dist/{StateMachine-ba3ccedf.development.esm.js → StateMachine-e25dd61f.development.esm.js} +1 -1
- package/dist/declarations/src/setup.d.ts +19 -27
- package/dist/declarations/src/types.v6.d.ts +5 -2
- package/dist/declarations/src/utils.d.ts +1 -1
- package/dist/{index-d88b0c55.esm.js → index-3f87408c.esm.js} +20 -27
- package/dist/{index-dc3443b6.development.esm.js → index-d39fb138.development.esm.js} +20 -27
- package/dist/{index-42956779.cjs.js → index-e694228c.cjs.js} +20 -27
- package/dist/{index-49293864.development.cjs.js → index-ec7c7a2d.development.cjs.js} +20 -27
- 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.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 +2 -2
- package/dist/xstate.development.cjs.js +2 -2
- package/dist/xstate.development.esm.js +4 -4
- package/dist/xstate.esm.js +4 -4
- package/dist/xstate.umd.min.js +1 -1
- package/dist/xstate.umd.min.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { P as ProcessingStatus, H as resolveReferencedActor, e as createActor, S as STATE_DELIMITER, I as mapValues, t as toArray, J as createInvokeId, K as getDelayedTransitions, L as evaluateCandidate, M as formatTransition, N as NULL_EVENT, O as toTransitionConfigArray, Q as createInvokeTimeoutEvent, R as getCandidates, U as formatRouteTransitions, V as resolveStateValue, W as getAllStateNodes, l as getStateNodes, Y as createMachineSnapshot, Z as isInFinalState, f as macrostep, d as deriveDeferredStarts, _ as cloneMachineSnapshot, $ as transitionNode, m as matchesEventDescriptor, a0 as getTransitionResult, a1 as hasEffect, a2 as createErrorPlatformEvent, r as resolveActionsWithContext, g as createInitEvent, h as initialMicrostep, a3 as toStatePath, a4 as isStateId, a5 as getStateNodeByPath, a6 as getPersistedSnapshot, a7 as $$ACTOR_TYPE } from './index-
|
|
1
|
+
import { P as ProcessingStatus, H as resolveReferencedActor, e as createActor, S as STATE_DELIMITER, I as mapValues, t as toArray, J as createInvokeId, K as getDelayedTransitions, L as evaluateCandidate, M as formatTransition, N as NULL_EVENT, O as toTransitionConfigArray, Q as createInvokeTimeoutEvent, R as getCandidates, U as formatRouteTransitions, V as resolveStateValue, W as getAllStateNodes, l as getStateNodes, Y as createMachineSnapshot, Z as isInFinalState, f as macrostep, d as deriveDeferredStarts, _ as cloneMachineSnapshot, $ as transitionNode, m as matchesEventDescriptor, a0 as getTransitionResult, a1 as hasEffect, a2 as createErrorPlatformEvent, r as resolveActionsWithContext, g as createInitEvent, h as initialMicrostep, a3 as toStatePath, a4 as isStateId, a5 as getStateNodeByPath, a6 as getPersistedSnapshot, a7 as $$ACTOR_TYPE } from './index-3f87408c.esm.js';
|
|
2
2
|
|
|
3
3
|
function createSpawner(actorScope, {
|
|
4
4
|
machine,
|
package/dist/{StateMachine-ba3ccedf.development.esm.js → StateMachine-e25dd61f.development.esm.js}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { P as ProcessingStatus, H as resolveReferencedActor, e as createActor, S as STATE_DELIMITER, I as mapValues, t as toArray, J as createInvokeId, K as getDelayedTransitions, L as evaluateCandidate, M as formatTransition, N as NULL_EVENT, O as toTransitionConfigArray, Q as createInvokeTimeoutEvent, R as getCandidates, U as formatRouteTransitions, V as resolveStateValue, W as getAllStateNodes, l as getStateNodes, Y as createMachineSnapshot, Z as isInFinalState, f as macrostep, d as deriveDeferredStarts, _ as cloneMachineSnapshot, $ as transitionNode, m as matchesEventDescriptor, a0 as getTransitionResult, a1 as hasEffect, a2 as createErrorPlatformEvent, r as resolveActionsWithContext, g as createInitEvent, h as initialMicrostep, a3 as toStatePath, a4 as isStateId, a5 as getStateNodeByPath, a6 as getPersistedSnapshot, a7 as $$ACTOR_TYPE } from './index-
|
|
1
|
+
import { P as ProcessingStatus, H as resolveReferencedActor, e as createActor, S as STATE_DELIMITER, I as mapValues, t as toArray, J as createInvokeId, K as getDelayedTransitions, L as evaluateCandidate, M as formatTransition, N as NULL_EVENT, O as toTransitionConfigArray, Q as createInvokeTimeoutEvent, R as getCandidates, U as formatRouteTransitions, V as resolveStateValue, W as getAllStateNodes, l as getStateNodes, Y as createMachineSnapshot, Z as isInFinalState, f as macrostep, d as deriveDeferredStarts, _ as cloneMachineSnapshot, $ as transitionNode, m as matchesEventDescriptor, a0 as getTransitionResult, a1 as hasEffect, a2 as createErrorPlatformEvent, r as resolveActionsWithContext, g as createInitEvent, h as initialMicrostep, a3 as toStatePath, a4 as isStateId, a5 as getStateNodeByPath, a6 as getPersistedSnapshot, a7 as $$ACTOR_TYPE } from './index-d39fb138.development.esm.js';
|
|
2
2
|
|
|
3
3
|
function createSpawner(actorScope, {
|
|
4
4
|
machine,
|
|
@@ -80,6 +80,9 @@ type SetupOrConfigSchemaMap<TSchemas, TKey extends 'events' | 'emitted' | 'child
|
|
|
80
80
|
type SetupStateKeys<TStateSchemas extends Record<string, SetupStateSchema>> = keyof TStateSchemas & string;
|
|
81
81
|
type SetupStateKey<TStateSchemas extends Record<string, SetupStateSchema>> = string extends SetupStateKeys<TStateSchemas> ? string : [SetupStateKeys<TStateSchemas>] extends [never] ? string : SetupStateKeys<TStateSchemas>;
|
|
82
82
|
type SetupStateTarget<TStateSchemas extends Record<string, SetupStateSchema>> = string extends SetupStateKeys<TStateSchemas> ? string : [SetupStateKeys<TStateSchemas>] extends [never] ? string : SetupStateKeys<TStateSchemas> | `.${string}` | `#${string}`;
|
|
83
|
+
type StateSchemasWithKeys<TStateSchemas extends Record<string, SetupStateSchema>, TStateKeys extends string> = TStateSchemas & {
|
|
84
|
+
[K in Exclude<TStateKeys, keyof TStateSchemas>]: {};
|
|
85
|
+
};
|
|
83
86
|
/**
|
|
84
87
|
* The sibling state schemas of a dotted path: the children of the path's
|
|
85
88
|
* parent. A bare transition target resolves relative to the parent, so the
|
|
@@ -103,23 +106,6 @@ type StatePaths<TStates extends Record<string, SetupStateSchema>> = string exten
|
|
|
103
106
|
* the leading sibling-schemas and state-schema arguments.
|
|
104
107
|
*/
|
|
105
108
|
type SetupStateNodeConfig<TStates extends Record<string, SetupStateSchema>, TStateSchema extends SetupStateSchema, TSchemas extends SetupSchemas, TSetupActionMap extends Implementations['actions'], TSetupActorMap extends Implementations['actorSources'], TSetupGuardMap extends Implementations['guards'], TSetupDelayMap extends Implementations['delays'], TSystemRegistry extends SystemRegistry> = StateNodeConfigWithNestedInput<TStates, TStateSchema, SetupContext<TSchemas, StandardSchemaV1>, SetupContextShape<TSchemas, StandardSchemaV1, SetupContext<TSchemas, StandardSchemaV1>>, SetupEvents<TSchemas, Record<string, StandardSchemaV1>>, Cast<SetupChildren<TSchemas, Record<string, StandardSchemaV1>>, Record<string, AnyActorRef | undefined>>, string, SetupTags<TSchemas, StandardSchemaV1>, SetupOutput<TSchemas, StandardSchemaV1>, SetupEmitted<TSchemas, Record<string, StandardSchemaV1>>, SetupMeta<TSchemas, StandardSchemaV1>, SetupActions<TSchemas, TSetupActionMap>, TSetupActorMap, SetupGuards<TSchemas, TSetupGuardMap>, TSetupDelayMap, TSystemRegistry>;
|
|
106
|
-
type InvalidSetupStateKeys<TConfig, TStateSchemas extends Record<string, SetupStateSchema>> = string extends SetupStateKeys<TStateSchemas> ? never : [SetupStateKeys<TStateSchemas>] extends [never] ? never : TConfig extends {
|
|
107
|
-
states: infer TStates;
|
|
108
|
-
} ? Exclude<keyof TStates & string, SetupStateKeys<TStateSchemas>> : never;
|
|
109
|
-
type ValidateSetupStateKeys<TConfig, TStateSchemas extends Record<string, SetupStateSchema>> = [InvalidSetupStateKeys<TConfig, TStateSchemas>] extends [never] ? unknown : {
|
|
110
|
-
states: {
|
|
111
|
-
[K in InvalidSetupStateKeys<TConfig, TStateSchemas>]: never;
|
|
112
|
-
};
|
|
113
|
-
};
|
|
114
|
-
type ValidateNestedSetupStateKeys<TConfig, TStateSchemas extends Record<string, SetupStateSchema>> = TConfig extends {
|
|
115
|
-
states: infer TConfigStates;
|
|
116
|
-
} ? TConfigStates extends Record<string, unknown> ? {
|
|
117
|
-
states: {
|
|
118
|
-
[K in keyof TConfigStates & keyof TStateSchemas & string]: TStateSchemas[K] extends {
|
|
119
|
-
states: infer TChildStateSchemas;
|
|
120
|
-
} ? TChildStateSchemas extends Record<string, SetupStateSchema> ? TConfigStates[K] & ValidateSetupStateKeys<TConfigStates[K], TChildStateSchemas> & ValidateNestedSetupStateKeys<TConfigStates[K], TChildStateSchemas> : TConfigStates[K] : TConfigStates[K];
|
|
121
|
-
};
|
|
122
|
-
} : unknown : unknown;
|
|
123
109
|
type SetupContext<TSchemas, TContextSchema extends StandardSchemaV1> = [
|
|
124
110
|
SetupSchema<TSchemas, 'context'>
|
|
125
111
|
] extends [never] ? unknown extends StandardSchemaV1.InferOutput<TContextSchema> ? MachineContext : StandardSchemaV1.InferOutput<TContextSchema> & MachineContext : StandardSchemaV1.InferOutput<SetupSchema<TSchemas, 'context'>> & MachineContext;
|
|
@@ -176,10 +162,15 @@ type StateInput<TStateSchema extends SetupStateSchema> = TStateSchema['schemas']
|
|
|
176
162
|
} ? TInputSchema extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<TInputSchema> : undefined : undefined;
|
|
177
163
|
type StateContext<TStateSchema extends SetupStateSchema, TFallbackContext extends MachineContext> = TStateSchema['schemas'] extends {
|
|
178
164
|
context: infer TContextSchema;
|
|
179
|
-
} ? TContextSchema extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<TContextSchema> & MachineContext : TFallbackContext : TFallbackContext
|
|
165
|
+
} ? TContextSchema extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<TContextSchema> & MachineContext & RootContextMarker<TFallbackContext> : RootContext<TFallbackContext> : RootContext<TFallbackContext>;
|
|
166
|
+
declare const rootContext: unique symbol;
|
|
167
|
+
type RootContextMarker<TContext> = {
|
|
168
|
+
readonly [rootContext]?: RootContext<TContext>;
|
|
169
|
+
};
|
|
170
|
+
type RootContext<TContext> = typeof rootContext extends keyof TContext ? TContext[typeof rootContext] : TContext;
|
|
180
171
|
type StateContextShape<TStateSchema extends SetupStateSchema, TFallbackContext> = TStateSchema['schemas'] extends {
|
|
181
172
|
context: infer TContextSchema;
|
|
182
|
-
} ? TContextSchema extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<TContextSchema> : TFallbackContext : TFallbackContext
|
|
173
|
+
} ? TContextSchema extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<TContextSchema> & RootContextMarker<TFallbackContext> : RootContext<TFallbackContext> : RootContext<TFallbackContext>;
|
|
183
174
|
type WithNestedStates<TConfig, TNestedStates> = TConfig extends {
|
|
184
175
|
type: 'choice';
|
|
185
176
|
} ? TConfig : Omit<TConfig, 'states'> & {
|
|
@@ -232,7 +223,7 @@ type MergeStateSchema<TConfig extends StateSchema, TSetup extends StateSchema> =
|
|
|
232
223
|
} : undefined : undefined;
|
|
233
224
|
};
|
|
234
225
|
/** Machine config with typed state input */
|
|
235
|
-
type SetupMachineConfig<TStateSchemas extends Record<string, SetupStateSchema>, TSchemas extends SetupSchemas, 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, TEvent extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TDelays extends string, TTag extends string, TEmitted extends EventObject, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TSystemRegistry extends SystemRegistry, TContextRequired extends boolean, TRootDelays extends string = TDelays, TRootActionMap extends Implementations['actions'] = TActionMap, TRootActorMap extends Implementations['actorSources'] = TActorMap, TRootGuardMap extends Implementations['guards'] = TGuardMap> = Omit<Next_MachineConfig<SetupOrConfigSchema<TSchemas, 'context', TContextSchema>, SetupOrConfigSchemaMap<TSchemas, 'events', TEventSchemaMap>, SetupOrConfigSchemaMap<TSchemas, 'emitted', TEmittedSchemaMap>, SetupOrConfigSchema<TSchemas, 'input', TInputSchema>, SetupOrConfigSchema<TSchemas, 'output', TOutputSchema>, SetupOrConfigSchema<TSchemas, 'meta', TMetaSchema>, SetupOrConfigSchema<TSchemas, 'tags', TTagSchema>, SetupOrConfigSchemaMap<TSchemas, 'children', TChildrenSchemaMap>, TContext, TEvent, TChildren, TDelays, TTag, TActionMap, TActorMap, TGuardMap, TDelayMap, TContextRequired, TSystemRegistry>, 'states' | 'initial' | 'on' | 'always' | 'invoke' | 'actions' | 'actorSources' | 'guards' | 'delays'> & {
|
|
226
|
+
type SetupMachineConfig<TStateSchemas extends Record<string, SetupStateSchema>, TStateKeys extends string, TSchemas extends SetupSchemas, 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, TEvent extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TDelays extends string, TTag extends string, TEmitted extends EventObject, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TSystemRegistry extends SystemRegistry, TContextRequired extends boolean, TRootDelays extends string = TDelays, TRootActionMap extends Implementations['actions'] = TActionMap, TRootActorMap extends Implementations['actorSources'] = TActorMap, TRootGuardMap extends Implementations['guards'] = TGuardMap> = Omit<Next_MachineConfig<SetupOrConfigSchema<TSchemas, 'context', TContextSchema>, SetupOrConfigSchemaMap<TSchemas, 'events', TEventSchemaMap>, SetupOrConfigSchemaMap<TSchemas, 'emitted', TEmittedSchemaMap>, SetupOrConfigSchema<TSchemas, 'input', TInputSchema>, SetupOrConfigSchema<TSchemas, 'output', TOutputSchema>, SetupOrConfigSchema<TSchemas, 'meta', TMetaSchema>, SetupOrConfigSchema<TSchemas, 'tags', TTagSchema>, SetupOrConfigSchemaMap<TSchemas, 'children', TChildrenSchemaMap>, TContext, TEvent, TChildren, TDelays, TTag, TActionMap, TActorMap, TGuardMap, TDelayMap, TContextRequired, TSystemRegistry>, 'states' | 'initial' | 'on' | 'always' | 'invoke' | 'actions' | 'actorSources' | 'guards' | 'delays'> & {
|
|
236
227
|
actions?: TRootActionMap;
|
|
237
228
|
actorSources?: TRootActorMap;
|
|
238
229
|
guards?: TRootGuardMap;
|
|
@@ -243,19 +234,19 @@ type SetupMachineConfig<TStateSchemas extends Record<string, SetupStateSchema>,
|
|
|
243
234
|
stateNode: AnyStateNode;
|
|
244
235
|
}) => number);
|
|
245
236
|
};
|
|
246
|
-
initial?:
|
|
237
|
+
initial?: TStateKeys | InitialTransitionWithInput<TStateSchemas, TContext, TEvent> | undefined;
|
|
247
238
|
on?: StateTransitions<TStateSchemas, TContext, SetupContextShape<TSchemas, TContextSchema, TContext>, TEvent, TEmitted, TChildren, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry>;
|
|
248
239
|
always?: StateTransitionConfigOrTarget<TStateSchemas, TContext, SetupContextShape<TSchemas, TContextSchema, TContext>, TEvent, TEvent, TEmitted, TChildren, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry>;
|
|
249
240
|
invoke?: SingleOrArray<SetupInvokeConfig<TStateSchemas, TContext, SetupContextShape<TSchemas, TContextSchema, TContext>, TEvent, TEmitted, TChildren, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry>>;
|
|
250
|
-
states?: StatesWithInput<TStateSchemas, TStateSchemas, TContext, SetupContextShape<TSchemas, TContextSchema, TContext>, TEvent, TChildren, TDelays, TTag, SetupOutput<TSchemas, TOutputSchema>, TEmitted, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry>;
|
|
241
|
+
states?: StatesWithInput<TStateSchemas, TStateSchemas, TContext, SetupContextShape<TSchemas, TContextSchema, TContext>, TEvent, TChildren, TDelays, TTag, SetupOutput<TSchemas, TOutputSchema>, TEmitted, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry, TStateKeys>;
|
|
251
242
|
};
|
|
252
243
|
/** States config type that provides typed input for known states */
|
|
253
|
-
type StatesWithInput<TRootStateSchemas extends Record<string, SetupStateSchema>, TStateSchemas extends Record<string, SetupStateSchema>, TContext extends MachineContext, TContextShape, TEvent extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TDelays extends string, TTag extends string, TOutput, TEmitted extends EventObject, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TSystemRegistry extends SystemRegistry
|
|
254
|
-
[K in
|
|
244
|
+
type StatesWithInput<TRootStateSchemas extends Record<string, SetupStateSchema>, TStateSchemas extends Record<string, SetupStateSchema>, TContext extends MachineContext, TContextShape, TEvent extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TDelays extends string, TTag extends string, TOutput, TEmitted extends EventObject, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TSystemRegistry extends SystemRegistry, TStateKeys extends string = SetupStateKey<TStateSchemas>> = {
|
|
245
|
+
[K in TStateKeys]?: StateNodeConfigWithNestedInput<StateSchemasWithKeys<TRootStateSchemas, TStateKeys>, K extends keyof TStateSchemas ? TStateSchemas[K] : {}, TContext, TContextShape, TEvent, TChildren, TDelays, TTag, TOutput, TEmitted, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry>;
|
|
255
246
|
};
|
|
256
247
|
/** State node config that recursively applies typed input for nested states */
|
|
257
248
|
type StateNodeConfigWithNestedInput<TSiblingStateSchemas extends Record<string, SetupStateSchema>, TStateSchema extends SetupStateSchema, TContext extends MachineContext, TContextShape, TEvent extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TDelays extends string, TTag extends string, TOutput, TEmitted extends EventObject, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TSystemRegistry extends SystemRegistry> = WithNestedStates<Omit<Next_StateNodeConfig<StateContext<TStateSchema, TContext>, TEvent, TDelays, TTag, TOutput, TEmitted, TMeta, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, StateInput<TStateSchema>, Record<string, unknown>, TSystemRegistry>, 'on' | 'always' | 'initial' | 'invoke' | 'onDone'> & {
|
|
258
|
-
initial?: TStateSchema['states'] extends Record<string, SetupStateSchema> ? SetupStateKey<TStateSchema['states']> | InitialTransitionWithInput<TStateSchema['states'], StateContext<TStateSchema, TContext>, TEvent> : string | {
|
|
249
|
+
initial?: TStateSchema['states'] extends Record<string, SetupStateSchema> ? SetupStateKey<TStateSchema['states']> | (string & {}) | InitialTransitionWithInput<TStateSchema['states'], StateContext<TStateSchema, TContext>, TEvent> : string | {
|
|
259
250
|
target: string;
|
|
260
251
|
input?: Record<string, unknown>;
|
|
261
252
|
} | undefined;
|
|
@@ -371,7 +362,7 @@ export interface SetupReturn<TStates extends Record<string, SetupStateSchema> =
|
|
|
371
362
|
/** Extends the setup configuration */
|
|
372
363
|
extend<const TExtendSchemas extends SetupSchemas = {}, const TExtendStates extends Record<string, SetupStateSchema> = {}, TExtendActionMap extends Implementations['actions'] = {}, TExtendActorMap extends Implementations['actorSources'] = {}, TExtendGuardMap extends Implementations['guards'] = {}, TExtendDelayMap extends Implementations['delays'] = {}>(config: SetupConfig<TExtendSchemas, TExtendStates, TExtendActionMap, TExtendActorMap, TExtendGuardMap, TExtendDelayMap>): SetupReturn<MergeImplementationMaps<TStates, TExtendStates>, MergeImplementationMaps<TSchemas, TExtendSchemas>, MergeImplementationMaps<TSetupActionMap, TExtendActionMap>, MergeImplementationMaps<TSetupActorMap, TExtendActorMap>, MergeImplementationMaps<TSetupGuardMap, TExtendGuardMap>, MergeImplementationMaps<TSetupDelayMap, TExtendDelayMap>, TSetupDelays | Extract<keyof TExtendDelayMap, string>, TSystemRegistry>;
|
|
373
364
|
/** Creates a state machine with the setup configuration */
|
|
374
|
-
createMachine<TContextSchema extends StandardSchemaV1 = StandardSchemaV1, const TEventSchemaMap extends Record<string, StandardSchemaV1> = Record<string, StandardSchemaV1>, TEmittedSchemaMap extends Record<string, StandardSchemaV1> = Record<string, StandardSchemaV1>, TInputSchema extends StandardSchemaV1 = StandardSchemaV1, TOutputSchema extends StandardSchemaV1 = StandardSchemaV1, TMetaSchema extends StandardSchemaV1 = StandardSchemaV1, TTagSchema extends StandardSchemaV1 = StandardSchemaV1, const TChildrenSchemaMap extends Record<string, StandardSchemaV1> = Record<string, StandardSchemaV1>, const TActionSchemaMap extends ActionSchemas = {}, const TGuardSchemaMap extends GuardSchemas = {}, _TEvent extends EventObject = EventObject, TActor extends ProvidedActor = ProvidedActor, TActionMap extends Implementations['actions'] = {}, TActorMap extends Implementations['actorSources'] = {}, TGuardMap extends Implementations['guards'] = {}, TDelayMap extends Implementations['delays'] = {}, TDelays extends string = Extract<keyof TDelayMap, string>, TTag extends SetupTags<TSchemas, TTagSchema> = SetupTags<TSchemas, TTagSchema>, TInput = unknown, TConfig extends SetupMachineConfig<TStates, TSchemas, TContextSchema, TEventSchemaMap, TEmittedSchemaMap, TInputSchema, TOutputSchema, TMetaSchema, TTagSchema, TChildrenSchemaMap, SetupContext<TSchemas, TContextSchema>, SetupEvents<TSchemas, TEventSchemaMap>, Cast<MergeChildren<SetupChildren<TSchemas, TChildrenSchemaMap>, TActor>, Record<string, AnyActorRef | undefined>>, TSetupDelays | TDelays, TTag, SetupEmitted<TSchemas, TEmittedSchemaMap>, SetupMeta<TSchemas, TMetaSchema>, MergeImplementationMaps<SetupActions<TSchemas, TSetupActionMap>, MergeImplementationMaps<InferActions<TActionSchemaMap>, TActionMap>>, MergeImplementationMaps<TSetupActorMap, TActorMap>, MergeImplementationMaps<SetupGuards<TSchemas, TSetupGuardMap>, MergeImplementationMaps<InferGuards<TGuardSchemaMap>, TGuardMap>>, MergeImplementationMaps<TSetupDelayMap, TDelayMap>, TSystemRegistry, SetupContextRequired<TSchemas, TContextSchema>, TDelays, TActionMap, TActorMap, TGuardMap> = SetupMachineConfig<TStates, TSchemas, TContextSchema, TEventSchemaMap, TEmittedSchemaMap, TInputSchema, TOutputSchema, TMetaSchema, TTagSchema, TChildrenSchemaMap, SetupContext<TSchemas, TContextSchema>, SetupEvents<TSchemas, TEventSchemaMap>, Cast<MergeChildren<SetupChildren<TSchemas, TChildrenSchemaMap>, TActor>, Record<string, AnyActorRef | undefined>>, TSetupDelays | TDelays, TTag, SetupEmitted<TSchemas, TEmittedSchemaMap>, SetupMeta<TSchemas, TMetaSchema>, MergeImplementationMaps<SetupActions<TSchemas, TSetupActionMap>, MergeImplementationMaps<InferActions<TActionSchemaMap>, TActionMap>>, MergeImplementationMaps<TSetupActorMap, TActorMap>, MergeImplementationMaps<SetupGuards<TSchemas, TSetupGuardMap>, MergeImplementationMaps<InferGuards<TGuardSchemaMap>, TGuardMap>>, MergeImplementationMaps<TSetupDelayMap, TDelayMap>, TSystemRegistry, SetupContextRequired<TSchemas, TContextSchema>, TDelays, TActionMap, TActorMap, TGuardMap>>(config: {
|
|
365
|
+
createMachine<TContextSchema extends StandardSchemaV1 = StandardSchemaV1, const TEventSchemaMap extends Record<string, StandardSchemaV1> = Record<string, StandardSchemaV1>, TEmittedSchemaMap extends Record<string, StandardSchemaV1> = Record<string, StandardSchemaV1>, TInputSchema extends StandardSchemaV1 = StandardSchemaV1, TOutputSchema extends StandardSchemaV1 = StandardSchemaV1, TMetaSchema extends StandardSchemaV1 = StandardSchemaV1, TTagSchema extends StandardSchemaV1 = StandardSchemaV1, const TChildrenSchemaMap extends Record<string, StandardSchemaV1> = Record<string, StandardSchemaV1>, const TActionSchemaMap extends ActionSchemas = {}, const TGuardSchemaMap extends GuardSchemas = {}, _TEvent extends EventObject = EventObject, TActor extends ProvidedActor = ProvidedActor, TActionMap extends Implementations['actions'] = {}, TActorMap extends Implementations['actorSources'] = {}, TGuardMap extends Implementations['guards'] = {}, TDelayMap extends Implementations['delays'] = {}, TDelays extends string = Extract<keyof TDelayMap, string>, TTag extends SetupTags<TSchemas, TTagSchema> = SetupTags<TSchemas, TTagSchema>, TInput = unknown, const TStateKeys extends string = SetupStateKey<TStates>, TConfig extends SetupMachineConfig<TStates, TStateKeys, TSchemas, TContextSchema, TEventSchemaMap, TEmittedSchemaMap, TInputSchema, TOutputSchema, TMetaSchema, TTagSchema, TChildrenSchemaMap, SetupContext<TSchemas, TContextSchema>, SetupEvents<TSchemas, TEventSchemaMap>, Cast<MergeChildren<SetupChildren<TSchemas, TChildrenSchemaMap>, TActor>, Record<string, AnyActorRef | undefined>>, TSetupDelays | TDelays, TTag, SetupEmitted<TSchemas, TEmittedSchemaMap>, SetupMeta<TSchemas, TMetaSchema>, MergeImplementationMaps<SetupActions<TSchemas, TSetupActionMap>, MergeImplementationMaps<InferActions<TActionSchemaMap>, TActionMap>>, MergeImplementationMaps<TSetupActorMap, TActorMap>, MergeImplementationMaps<SetupGuards<TSchemas, TSetupGuardMap>, MergeImplementationMaps<InferGuards<TGuardSchemaMap>, TGuardMap>>, MergeImplementationMaps<TSetupDelayMap, TDelayMap>, TSystemRegistry, SetupContextRequired<TSchemas, TContextSchema>, TDelays, TActionMap, TActorMap, TGuardMap> = SetupMachineConfig<TStates, TStateKeys, TSchemas, TContextSchema, TEventSchemaMap, TEmittedSchemaMap, TInputSchema, TOutputSchema, TMetaSchema, TTagSchema, TChildrenSchemaMap, SetupContext<TSchemas, TContextSchema>, SetupEvents<TSchemas, TEventSchemaMap>, Cast<MergeChildren<SetupChildren<TSchemas, TChildrenSchemaMap>, TActor>, Record<string, AnyActorRef | undefined>>, TSetupDelays | TDelays, TTag, SetupEmitted<TSchemas, TEmittedSchemaMap>, SetupMeta<TSchemas, TMetaSchema>, MergeImplementationMaps<SetupActions<TSchemas, TSetupActionMap>, MergeImplementationMaps<InferActions<TActionSchemaMap>, TActionMap>>, MergeImplementationMaps<TSetupActorMap, TActorMap>, MergeImplementationMaps<SetupGuards<TSchemas, TSetupGuardMap>, MergeImplementationMaps<InferGuards<TGuardSchemaMap>, TGuardMap>>, MergeImplementationMaps<TSetupDelayMap, TDelayMap>, TSystemRegistry, SetupContextRequired<TSchemas, TContextSchema>, TDelays, TActionMap, TActorMap, TGuardMap>>(config: {
|
|
375
366
|
schemas?: {
|
|
376
367
|
events?: TEventSchemaMap;
|
|
377
368
|
context?: TContextSchema;
|
|
@@ -388,7 +379,8 @@ export interface SetupReturn<TStates extends Record<string, SetupStateSchema> =
|
|
|
388
379
|
actorSources?: TActorMap;
|
|
389
380
|
guards?: TGuardMap;
|
|
390
381
|
delays?: TDelayMap;
|
|
391
|
-
|
|
382
|
+
states?: Record<TStateKeys, unknown>;
|
|
383
|
+
} & TConfig & ValidateSetupDelayReferences<TConfig, TSetupDelays> & ValidateRegistryKeys<TConfig, TSystemRegistry, MergeImplementationMaps<TSetupActorMap, TActorMap>>): StateMachine<SetupContext<TSchemas, TContextSchema>, SetupEvents<TSchemas, TEventSchemaMap> | ([RoutableStateId<Cast<TConfig, StateSchema>>] extends [never] ? never : {
|
|
392
384
|
type: 'xstate.route';
|
|
393
385
|
to: RoutableStateId<Cast<TConfig, StateSchema>>;
|
|
394
386
|
}), Cast<MergeChildren<SetupChildren<TSchemas, TChildrenSchemaMap>, TActor>, Record<string, AnyActorRef | undefined>>, StateValue, TTag & string, [
|
|
@@ -41,7 +41,10 @@ export type InferActions<TActionSchemaMap extends ActionSchemas> = string extend
|
|
|
41
41
|
export type InferGuards<TGuardSchemaMap extends GuardSchemas> = string extends keyof TGuardSchemaMap ? {} : {
|
|
42
42
|
[K in keyof TGuardSchemaMap & string]: (params: StandardSchemaV1.InferOutput<TGuardSchemaMap[K]['params']>) => boolean;
|
|
43
43
|
};
|
|
44
|
-
type
|
|
44
|
+
type OutputMapper<TContext extends MachineContext, TEvent extends EventObject, TResult, TInput = Record<string, unknown> | undefined> = (args: Parameters<Mapper<TContext, TEvent, TResult, TEvent>>[0] & {
|
|
45
|
+
input: TInput;
|
|
46
|
+
}) => TResult;
|
|
47
|
+
type OutputConfig<TContext extends MachineContext, TEvent extends EventObject, TOutput, TInput = Record<string, unknown> | undefined> = unknown extends TOutput ? OutputMapper<TContext, TEvent, NonReducibleUnknown, TInput> | NonReducibleUnknown : OutputMapper<TContext, TEvent, TOutput, TInput> | TOutput;
|
|
45
48
|
export type ValidateTopLevelFinalOutputs<TConfig, TContext extends MachineContext, TEvent extends EventObject> = TConfig extends {
|
|
46
49
|
schemas: {
|
|
47
50
|
output: infer TOutputSchema extends StandardSchemaV1;
|
|
@@ -394,7 +397,7 @@ interface Next_RegularStateNodeConfig<TContext extends MachineContext, TEvent ex
|
|
|
394
397
|
* The output data will be evaluated with the current `context` and placed on
|
|
395
398
|
* the `.data` property of the event.
|
|
396
399
|
*/
|
|
397
|
-
output?: OutputConfig<TContext, TEvent, TOutput>;
|
|
400
|
+
output?: OutputConfig<TContext, TEvent, TOutput, TInput>;
|
|
398
401
|
/**
|
|
399
402
|
* The unique ID of the state node, which can be referenced as a transition
|
|
400
403
|
* target via the `#id` syntax.
|
|
@@ -8,7 +8,7 @@ export declare function mapValues<P, O extends Record<string, unknown>>(collecti
|
|
|
8
8
|
[key in keyof O]: P;
|
|
9
9
|
};
|
|
10
10
|
export declare function toArray<T>(value: readonly T[] | T | undefined): readonly T[];
|
|
11
|
-
export declare function resolveOutput<TContext extends MachineContext, TExpressionEvent extends EventObject>(mapper: Mapper<TContext, TExpressionEvent, unknown, EventObject> | NonReducibleUnknown, context: TContext, event: TExpressionEvent, self: AnyActor): unknown;
|
|
11
|
+
export declare function resolveOutput<TContext extends MachineContext, TExpressionEvent extends EventObject>(mapper: Mapper<TContext, TExpressionEvent, unknown, EventObject> | NonReducibleUnknown, context: TContext, event: TExpressionEvent, self: AnyActor, input?: Record<string, unknown>): unknown;
|
|
12
12
|
export declare function getEventOutput<TEvent extends EventObject>(event: TEvent): OutputArg<TEvent>['output'];
|
|
13
13
|
export declare function isErrorEvent(event: AnyEventObject): event is ErrorEvent;
|
|
14
14
|
export declare function toTransitionConfigArray(configLike: SingleOrArray<AnyTransitionConfig | TransitionConfigTarget | AnyTransitionConfigFunction>): Array<AnyTransitionConfig>;
|
|
@@ -348,6 +348,13 @@ function createSubscriptionLogic() {
|
|
|
348
348
|
// Singleton logic instance
|
|
349
349
|
const subscriptionLogic = /* #__PURE__ */createSubscriptionLogic();
|
|
350
350
|
|
|
351
|
+
const builtInExecutableAction = Symbol('xstate.builtInExecutableAction');
|
|
352
|
+
function brandBuiltInExecutableAction(action) {
|
|
353
|
+
Object.defineProperty(action, builtInExecutableAction, {
|
|
354
|
+
value: true
|
|
355
|
+
});
|
|
356
|
+
return action;
|
|
357
|
+
}
|
|
351
358
|
function mergeContextPatch(context, patch) {
|
|
352
359
|
return {
|
|
353
360
|
...context,
|
|
@@ -534,7 +541,7 @@ function getBuiltInActionFields(action, args) {
|
|
|
534
541
|
function createStartEffect(actor) {
|
|
535
542
|
const action = builtInActions['@xstate.start'];
|
|
536
543
|
const args = [actor];
|
|
537
|
-
return {
|
|
544
|
+
return brandBuiltInExecutableAction({
|
|
538
545
|
type: XSTATE_START,
|
|
539
546
|
params: {
|
|
540
547
|
action,
|
|
@@ -544,7 +551,7 @@ function createStartEffect(actor) {
|
|
|
544
551
|
exec: action.bind(null, actor),
|
|
545
552
|
actor,
|
|
546
553
|
id: actor.id
|
|
547
|
-
};
|
|
554
|
+
});
|
|
548
555
|
}
|
|
549
556
|
|
|
550
557
|
/**
|
|
@@ -573,23 +580,7 @@ function deriveDeferredStarts(effects) {
|
|
|
573
580
|
return [...attachedStarts, ...childStarts];
|
|
574
581
|
}
|
|
575
582
|
function isBuiltInExecutableAction(action) {
|
|
576
|
-
|
|
577
|
-
return false;
|
|
578
|
-
}
|
|
579
|
-
switch (action.type) {
|
|
580
|
-
case '@xstate.spawn':
|
|
581
|
-
return 'actor' in action && 'logic' in action && 'src' in action && 'input' in action;
|
|
582
|
-
case '@xstate.start':
|
|
583
|
-
case '@xstate.stop':
|
|
584
|
-
return 'actor' in action;
|
|
585
|
-
case '@xstate.raise':
|
|
586
|
-
case '@xstate.sendTo':
|
|
587
|
-
return 'event' in action;
|
|
588
|
-
case '@xstate.cancel':
|
|
589
|
-
return 'id' in action;
|
|
590
|
-
default:
|
|
591
|
-
return false;
|
|
592
|
-
}
|
|
583
|
+
return action[builtInExecutableAction] === true;
|
|
593
584
|
}
|
|
594
585
|
function resolveActionsWithContext(currentSnapshot, event, actorScope, actions) {
|
|
595
586
|
let intermediateSnapshot = currentSnapshot;
|
|
@@ -643,13 +634,14 @@ function resolveActionsWithContext(currentSnapshot, event, actorScope, actions)
|
|
|
643
634
|
}
|
|
644
635
|
if (!resolvedAction || !('resolve' in resolvedAction)) {
|
|
645
636
|
const builtInFields = typeof action === 'object' && action !== null && 'action' in action && typeof action.action === 'function' ? getBuiltInActionFields(action.action, action.args) : undefined;
|
|
646
|
-
|
|
637
|
+
const executableAction = {
|
|
647
638
|
type: typeof action === 'object' ? 'action' in action && typeof action.action === 'function' ? action.action.name ?? '(anonymous)' : action.type : action.name || '(anonymous)',
|
|
648
639
|
params: actionParams,
|
|
649
640
|
args: typeof action === 'object' && 'action' in action ? action.args : [],
|
|
650
641
|
exec: resolvedAction || (typeof action === 'object' && action !== null ? () => actorScope.defer(() => actorScope.emit(action)) : undefined),
|
|
651
642
|
...builtInFields
|
|
652
|
-
}
|
|
643
|
+
};
|
|
644
|
+
executableActions.push(builtInFields ? brandBuiltInExecutableAction(executableAction) : executableAction);
|
|
653
645
|
continue;
|
|
654
646
|
}
|
|
655
647
|
}
|
|
@@ -1505,7 +1497,7 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
|
|
|
1505
1497
|
let completionOutput;
|
|
1506
1498
|
if (rootCompletionNode.output !== undefined && rootCompletionNode.parent) {
|
|
1507
1499
|
const rootDoneEvent = internalQueue.find(e => e.type === `xstate.done.state.${rootNode.id}`);
|
|
1508
|
-
completionOutput = rootDoneEvent && rootCompletionNode.parent === rootNode ? rootDoneEvent.output : resolveOutput(rootCompletionNode.output, nextState.context, event, actorScope.self);
|
|
1500
|
+
completionOutput = rootDoneEvent && rootCompletionNode.parent === rootNode ? rootDoneEvent.output : resolveOutput(rootCompletionNode.output, nextState.context, event, actorScope.self, stateInputMap[rootCompletionNode.id]);
|
|
1509
1501
|
} else if (rootCompletionNode.type === 'parallel') {
|
|
1510
1502
|
const parallelDoneType = `xstate.done.state.${rootCompletionNode.id}`;
|
|
1511
1503
|
const parallelDoneEvent = internalQueue.find(e => e.type === parallelDoneType);
|
|
@@ -1727,14 +1719,14 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
|
|
|
1727
1719
|
let ancestorMarker = parent?.type === 'parallel' ? parent : parent?.parent;
|
|
1728
1720
|
let rootCompletionNode = ancestorMarker || stateNodeToEnter;
|
|
1729
1721
|
if (parent?.type === 'compound') {
|
|
1730
|
-
internalQueue.push(createDoneStateEvent(parent.id, stateNodeToEnter.output !== undefined ? resolveOutput(stateNodeToEnter.output, nextState.context, event, actorScope.self) : undefined));
|
|
1722
|
+
internalQueue.push(createDoneStateEvent(parent.id, stateNodeToEnter.output !== undefined ? resolveOutput(stateNodeToEnter.output, nextState.context, event, actorScope.self, stateInput) : undefined));
|
|
1731
1723
|
}
|
|
1732
1724
|
while (ancestorMarker?.type === 'parallel' && !completedNodes.has(ancestorMarker) && isInFinalState(mutStateNodeSet, ancestorMarker)) {
|
|
1733
1725
|
completedNodes.add(ancestorMarker);
|
|
1734
1726
|
const regionOutput = {};
|
|
1735
1727
|
for (const region of getChildren(ancestorMarker)) {
|
|
1736
1728
|
if (region.type === 'final') {
|
|
1737
|
-
regionOutput[region.key] = region.output !== undefined ? resolveOutput(region.output, nextState.context, event, actorScope.self) : undefined;
|
|
1729
|
+
regionOutput[region.key] = region.output !== undefined ? resolveOutput(region.output, nextState.context, event, actorScope.self, stateInputMap[region.id]) : undefined;
|
|
1738
1730
|
continue;
|
|
1739
1731
|
}
|
|
1740
1732
|
if (region.type === 'parallel') {
|
|
@@ -1744,7 +1736,7 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
|
|
|
1744
1736
|
continue;
|
|
1745
1737
|
}
|
|
1746
1738
|
const finalChild = getChildren(region).find(s => s.type === 'final' && mutStateNodeSet.has(s));
|
|
1747
|
-
regionOutput[region.key] = finalChild?.output !== undefined ? resolveOutput(finalChild.output, nextState.context, event, actorScope.self) : undefined;
|
|
1739
|
+
regionOutput[region.key] = finalChild?.output !== undefined ? resolveOutput(finalChild.output, nextState.context, event, actorScope.self, stateInputMap[finalChild.id]) : undefined;
|
|
1748
1740
|
}
|
|
1749
1741
|
internalQueue.push(createDoneStateEvent(ancestorMarker.id, regionOutput));
|
|
1750
1742
|
rootCompletionNode = ancestorMarker;
|
|
@@ -2358,14 +2350,15 @@ function toArray(value) {
|
|
|
2358
2350
|
}
|
|
2359
2351
|
return toArrayStrict(value);
|
|
2360
2352
|
}
|
|
2361
|
-
function resolveOutput(mapper, context, event, self) {
|
|
2353
|
+
function resolveOutput(mapper, context, event, self, input) {
|
|
2362
2354
|
if (typeof mapper === 'function') {
|
|
2363
2355
|
const outputMapper = mapper;
|
|
2364
2356
|
const args = {
|
|
2365
2357
|
context,
|
|
2366
2358
|
event,
|
|
2367
2359
|
output: getEventOutput(event),
|
|
2368
|
-
self
|
|
2360
|
+
self,
|
|
2361
|
+
input
|
|
2369
2362
|
};
|
|
2370
2363
|
return outputMapper(args);
|
|
2371
2364
|
}
|
|
@@ -349,6 +349,13 @@ function createSubscriptionLogic() {
|
|
|
349
349
|
// Singleton logic instance
|
|
350
350
|
const subscriptionLogic = /* #__PURE__ */createSubscriptionLogic();
|
|
351
351
|
|
|
352
|
+
const builtInExecutableAction = Symbol('xstate.builtInExecutableAction');
|
|
353
|
+
function brandBuiltInExecutableAction(action) {
|
|
354
|
+
Object.defineProperty(action, builtInExecutableAction, {
|
|
355
|
+
value: true
|
|
356
|
+
});
|
|
357
|
+
return action;
|
|
358
|
+
}
|
|
352
359
|
function mergeContextPatch(context, patch) {
|
|
353
360
|
return {
|
|
354
361
|
...context,
|
|
@@ -535,7 +542,7 @@ function getBuiltInActionFields(action, args) {
|
|
|
535
542
|
function createStartEffect(actor) {
|
|
536
543
|
const action = builtInActions['@xstate.start'];
|
|
537
544
|
const args = [actor];
|
|
538
|
-
return {
|
|
545
|
+
return brandBuiltInExecutableAction({
|
|
539
546
|
type: XSTATE_START,
|
|
540
547
|
params: {
|
|
541
548
|
action,
|
|
@@ -545,7 +552,7 @@ function createStartEffect(actor) {
|
|
|
545
552
|
exec: action.bind(null, actor),
|
|
546
553
|
actor,
|
|
547
554
|
id: actor.id
|
|
548
|
-
};
|
|
555
|
+
});
|
|
549
556
|
}
|
|
550
557
|
|
|
551
558
|
/**
|
|
@@ -574,23 +581,7 @@ function deriveDeferredStarts(effects) {
|
|
|
574
581
|
return [...attachedStarts, ...childStarts];
|
|
575
582
|
}
|
|
576
583
|
function isBuiltInExecutableAction(action) {
|
|
577
|
-
|
|
578
|
-
return false;
|
|
579
|
-
}
|
|
580
|
-
switch (action.type) {
|
|
581
|
-
case '@xstate.spawn':
|
|
582
|
-
return 'actor' in action && 'logic' in action && 'src' in action && 'input' in action;
|
|
583
|
-
case '@xstate.start':
|
|
584
|
-
case '@xstate.stop':
|
|
585
|
-
return 'actor' in action;
|
|
586
|
-
case '@xstate.raise':
|
|
587
|
-
case '@xstate.sendTo':
|
|
588
|
-
return 'event' in action;
|
|
589
|
-
case '@xstate.cancel':
|
|
590
|
-
return 'id' in action;
|
|
591
|
-
default:
|
|
592
|
-
return false;
|
|
593
|
-
}
|
|
584
|
+
return action[builtInExecutableAction] === true;
|
|
594
585
|
}
|
|
595
586
|
function resolveActionsWithContext(currentSnapshot, event, actorScope, actions) {
|
|
596
587
|
let intermediateSnapshot = currentSnapshot;
|
|
@@ -644,13 +635,14 @@ function resolveActionsWithContext(currentSnapshot, event, actorScope, actions)
|
|
|
644
635
|
}
|
|
645
636
|
if (!resolvedAction || !('resolve' in resolvedAction)) {
|
|
646
637
|
const builtInFields = typeof action === 'object' && action !== null && 'action' in action && typeof action.action === 'function' ? getBuiltInActionFields(action.action, action.args) : undefined;
|
|
647
|
-
|
|
638
|
+
const executableAction = {
|
|
648
639
|
type: typeof action === 'object' ? 'action' in action && typeof action.action === 'function' ? action.action.name ?? '(anonymous)' : action.type : action.name || '(anonymous)',
|
|
649
640
|
params: actionParams,
|
|
650
641
|
args: typeof action === 'object' && 'action' in action ? action.args : [],
|
|
651
642
|
exec: resolvedAction || (typeof action === 'object' && action !== null ? () => actorScope.defer(() => actorScope.emit(action)) : undefined),
|
|
652
643
|
...builtInFields
|
|
653
|
-
}
|
|
644
|
+
};
|
|
645
|
+
executableActions.push(builtInFields ? brandBuiltInExecutableAction(executableAction) : executableAction);
|
|
654
646
|
continue;
|
|
655
647
|
}
|
|
656
648
|
}
|
|
@@ -1516,7 +1508,7 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
|
|
|
1516
1508
|
let completionOutput;
|
|
1517
1509
|
if (rootCompletionNode.output !== undefined && rootCompletionNode.parent) {
|
|
1518
1510
|
const rootDoneEvent = internalQueue.find(e => e.type === `xstate.done.state.${rootNode.id}`);
|
|
1519
|
-
completionOutput = rootDoneEvent && rootCompletionNode.parent === rootNode ? rootDoneEvent.output : resolveOutput(rootCompletionNode.output, nextState.context, event, actorScope.self);
|
|
1511
|
+
completionOutput = rootDoneEvent && rootCompletionNode.parent === rootNode ? rootDoneEvent.output : resolveOutput(rootCompletionNode.output, nextState.context, event, actorScope.self, stateInputMap[rootCompletionNode.id]);
|
|
1520
1512
|
} else if (rootCompletionNode.type === 'parallel') {
|
|
1521
1513
|
const parallelDoneType = `xstate.done.state.${rootCompletionNode.id}`;
|
|
1522
1514
|
const parallelDoneEvent = internalQueue.find(e => e.type === parallelDoneType);
|
|
@@ -1738,14 +1730,14 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
|
|
|
1738
1730
|
let ancestorMarker = parent?.type === 'parallel' ? parent : parent?.parent;
|
|
1739
1731
|
let rootCompletionNode = ancestorMarker || stateNodeToEnter;
|
|
1740
1732
|
if (parent?.type === 'compound') {
|
|
1741
|
-
internalQueue.push(createDoneStateEvent(parent.id, stateNodeToEnter.output !== undefined ? resolveOutput(stateNodeToEnter.output, nextState.context, event, actorScope.self) : undefined));
|
|
1733
|
+
internalQueue.push(createDoneStateEvent(parent.id, stateNodeToEnter.output !== undefined ? resolveOutput(stateNodeToEnter.output, nextState.context, event, actorScope.self, stateInput) : undefined));
|
|
1742
1734
|
}
|
|
1743
1735
|
while (ancestorMarker?.type === 'parallel' && !completedNodes.has(ancestorMarker) && isInFinalState(mutStateNodeSet, ancestorMarker)) {
|
|
1744
1736
|
completedNodes.add(ancestorMarker);
|
|
1745
1737
|
const regionOutput = {};
|
|
1746
1738
|
for (const region of getChildren(ancestorMarker)) {
|
|
1747
1739
|
if (region.type === 'final') {
|
|
1748
|
-
regionOutput[region.key] = region.output !== undefined ? resolveOutput(region.output, nextState.context, event, actorScope.self) : undefined;
|
|
1740
|
+
regionOutput[region.key] = region.output !== undefined ? resolveOutput(region.output, nextState.context, event, actorScope.self, stateInputMap[region.id]) : undefined;
|
|
1749
1741
|
continue;
|
|
1750
1742
|
}
|
|
1751
1743
|
if (region.type === 'parallel') {
|
|
@@ -1755,7 +1747,7 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
|
|
|
1755
1747
|
continue;
|
|
1756
1748
|
}
|
|
1757
1749
|
const finalChild = getChildren(region).find(s => s.type === 'final' && mutStateNodeSet.has(s));
|
|
1758
|
-
regionOutput[region.key] = finalChild?.output !== undefined ? resolveOutput(finalChild.output, nextState.context, event, actorScope.self) : undefined;
|
|
1750
|
+
regionOutput[region.key] = finalChild?.output !== undefined ? resolveOutput(finalChild.output, nextState.context, event, actorScope.self, stateInputMap[finalChild.id]) : undefined;
|
|
1759
1751
|
}
|
|
1760
1752
|
internalQueue.push(createDoneStateEvent(ancestorMarker.id, regionOutput));
|
|
1761
1753
|
rootCompletionNode = ancestorMarker;
|
|
@@ -2375,14 +2367,15 @@ function toArray(value) {
|
|
|
2375
2367
|
}
|
|
2376
2368
|
return toArrayStrict(value);
|
|
2377
2369
|
}
|
|
2378
|
-
function resolveOutput(mapper, context, event, self) {
|
|
2370
|
+
function resolveOutput(mapper, context, event, self, input) {
|
|
2379
2371
|
if (typeof mapper === 'function') {
|
|
2380
2372
|
const outputMapper = mapper;
|
|
2381
2373
|
const args = {
|
|
2382
2374
|
context,
|
|
2383
2375
|
event,
|
|
2384
2376
|
output: getEventOutput(event),
|
|
2385
|
-
self
|
|
2377
|
+
self,
|
|
2378
|
+
input
|
|
2386
2379
|
};
|
|
2387
2380
|
return outputMapper(args);
|
|
2388
2381
|
}
|
|
@@ -350,6 +350,13 @@ function createSubscriptionLogic() {
|
|
|
350
350
|
// Singleton logic instance
|
|
351
351
|
const subscriptionLogic = /* #__PURE__ */createSubscriptionLogic();
|
|
352
352
|
|
|
353
|
+
const builtInExecutableAction = Symbol('xstate.builtInExecutableAction');
|
|
354
|
+
function brandBuiltInExecutableAction(action) {
|
|
355
|
+
Object.defineProperty(action, builtInExecutableAction, {
|
|
356
|
+
value: true
|
|
357
|
+
});
|
|
358
|
+
return action;
|
|
359
|
+
}
|
|
353
360
|
function mergeContextPatch(context, patch) {
|
|
354
361
|
return {
|
|
355
362
|
...context,
|
|
@@ -536,7 +543,7 @@ function getBuiltInActionFields(action, args) {
|
|
|
536
543
|
function createStartEffect(actor) {
|
|
537
544
|
const action = builtInActions['@xstate.start'];
|
|
538
545
|
const args = [actor];
|
|
539
|
-
return {
|
|
546
|
+
return brandBuiltInExecutableAction({
|
|
540
547
|
type: XSTATE_START,
|
|
541
548
|
params: {
|
|
542
549
|
action,
|
|
@@ -546,7 +553,7 @@ function createStartEffect(actor) {
|
|
|
546
553
|
exec: action.bind(null, actor),
|
|
547
554
|
actor,
|
|
548
555
|
id: actor.id
|
|
549
|
-
};
|
|
556
|
+
});
|
|
550
557
|
}
|
|
551
558
|
|
|
552
559
|
/**
|
|
@@ -575,23 +582,7 @@ function deriveDeferredStarts(effects) {
|
|
|
575
582
|
return [...attachedStarts, ...childStarts];
|
|
576
583
|
}
|
|
577
584
|
function isBuiltInExecutableAction(action) {
|
|
578
|
-
|
|
579
|
-
return false;
|
|
580
|
-
}
|
|
581
|
-
switch (action.type) {
|
|
582
|
-
case '@xstate.spawn':
|
|
583
|
-
return 'actor' in action && 'logic' in action && 'src' in action && 'input' in action;
|
|
584
|
-
case '@xstate.start':
|
|
585
|
-
case '@xstate.stop':
|
|
586
|
-
return 'actor' in action;
|
|
587
|
-
case '@xstate.raise':
|
|
588
|
-
case '@xstate.sendTo':
|
|
589
|
-
return 'event' in action;
|
|
590
|
-
case '@xstate.cancel':
|
|
591
|
-
return 'id' in action;
|
|
592
|
-
default:
|
|
593
|
-
return false;
|
|
594
|
-
}
|
|
585
|
+
return action[builtInExecutableAction] === true;
|
|
595
586
|
}
|
|
596
587
|
function resolveActionsWithContext(currentSnapshot, event, actorScope, actions) {
|
|
597
588
|
let intermediateSnapshot = currentSnapshot;
|
|
@@ -645,13 +636,14 @@ function resolveActionsWithContext(currentSnapshot, event, actorScope, actions)
|
|
|
645
636
|
}
|
|
646
637
|
if (!resolvedAction || !('resolve' in resolvedAction)) {
|
|
647
638
|
const builtInFields = typeof action === 'object' && action !== null && 'action' in action && typeof action.action === 'function' ? getBuiltInActionFields(action.action, action.args) : undefined;
|
|
648
|
-
|
|
639
|
+
const executableAction = {
|
|
649
640
|
type: typeof action === 'object' ? 'action' in action && typeof action.action === 'function' ? action.action.name ?? '(anonymous)' : action.type : action.name || '(anonymous)',
|
|
650
641
|
params: actionParams,
|
|
651
642
|
args: typeof action === 'object' && 'action' in action ? action.args : [],
|
|
652
643
|
exec: resolvedAction || (typeof action === 'object' && action !== null ? () => actorScope.defer(() => actorScope.emit(action)) : undefined),
|
|
653
644
|
...builtInFields
|
|
654
|
-
}
|
|
645
|
+
};
|
|
646
|
+
executableActions.push(builtInFields ? brandBuiltInExecutableAction(executableAction) : executableAction);
|
|
655
647
|
continue;
|
|
656
648
|
}
|
|
657
649
|
}
|
|
@@ -1507,7 +1499,7 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
|
|
|
1507
1499
|
let completionOutput;
|
|
1508
1500
|
if (rootCompletionNode.output !== undefined && rootCompletionNode.parent) {
|
|
1509
1501
|
const rootDoneEvent = internalQueue.find(e => e.type === `xstate.done.state.${rootNode.id}`);
|
|
1510
|
-
completionOutput = rootDoneEvent && rootCompletionNode.parent === rootNode ? rootDoneEvent.output : resolveOutput(rootCompletionNode.output, nextState.context, event, actorScope.self);
|
|
1502
|
+
completionOutput = rootDoneEvent && rootCompletionNode.parent === rootNode ? rootDoneEvent.output : resolveOutput(rootCompletionNode.output, nextState.context, event, actorScope.self, stateInputMap[rootCompletionNode.id]);
|
|
1511
1503
|
} else if (rootCompletionNode.type === 'parallel') {
|
|
1512
1504
|
const parallelDoneType = `xstate.done.state.${rootCompletionNode.id}`;
|
|
1513
1505
|
const parallelDoneEvent = internalQueue.find(e => e.type === parallelDoneType);
|
|
@@ -1729,14 +1721,14 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
|
|
|
1729
1721
|
let ancestorMarker = parent?.type === 'parallel' ? parent : parent?.parent;
|
|
1730
1722
|
let rootCompletionNode = ancestorMarker || stateNodeToEnter;
|
|
1731
1723
|
if (parent?.type === 'compound') {
|
|
1732
|
-
internalQueue.push(createDoneStateEvent(parent.id, stateNodeToEnter.output !== undefined ? resolveOutput(stateNodeToEnter.output, nextState.context, event, actorScope.self) : undefined));
|
|
1724
|
+
internalQueue.push(createDoneStateEvent(parent.id, stateNodeToEnter.output !== undefined ? resolveOutput(stateNodeToEnter.output, nextState.context, event, actorScope.self, stateInput) : undefined));
|
|
1733
1725
|
}
|
|
1734
1726
|
while (ancestorMarker?.type === 'parallel' && !completedNodes.has(ancestorMarker) && isInFinalState(mutStateNodeSet, ancestorMarker)) {
|
|
1735
1727
|
completedNodes.add(ancestorMarker);
|
|
1736
1728
|
const regionOutput = {};
|
|
1737
1729
|
for (const region of getChildren(ancestorMarker)) {
|
|
1738
1730
|
if (region.type === 'final') {
|
|
1739
|
-
regionOutput[region.key] = region.output !== undefined ? resolveOutput(region.output, nextState.context, event, actorScope.self) : undefined;
|
|
1731
|
+
regionOutput[region.key] = region.output !== undefined ? resolveOutput(region.output, nextState.context, event, actorScope.self, stateInputMap[region.id]) : undefined;
|
|
1740
1732
|
continue;
|
|
1741
1733
|
}
|
|
1742
1734
|
if (region.type === 'parallel') {
|
|
@@ -1746,7 +1738,7 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
|
|
|
1746
1738
|
continue;
|
|
1747
1739
|
}
|
|
1748
1740
|
const finalChild = getChildren(region).find(s => s.type === 'final' && mutStateNodeSet.has(s));
|
|
1749
|
-
regionOutput[region.key] = finalChild?.output !== undefined ? resolveOutput(finalChild.output, nextState.context, event, actorScope.self) : undefined;
|
|
1741
|
+
regionOutput[region.key] = finalChild?.output !== undefined ? resolveOutput(finalChild.output, nextState.context, event, actorScope.self, stateInputMap[finalChild.id]) : undefined;
|
|
1750
1742
|
}
|
|
1751
1743
|
internalQueue.push(createDoneStateEvent(ancestorMarker.id, regionOutput));
|
|
1752
1744
|
rootCompletionNode = ancestorMarker;
|
|
@@ -2360,14 +2352,15 @@ function toArray(value) {
|
|
|
2360
2352
|
}
|
|
2361
2353
|
return toArrayStrict(value);
|
|
2362
2354
|
}
|
|
2363
|
-
function resolveOutput(mapper, context, event, self) {
|
|
2355
|
+
function resolveOutput(mapper, context, event, self, input) {
|
|
2364
2356
|
if (typeof mapper === 'function') {
|
|
2365
2357
|
const outputMapper = mapper;
|
|
2366
2358
|
const args = {
|
|
2367
2359
|
context,
|
|
2368
2360
|
event,
|
|
2369
2361
|
output: getEventOutput(event),
|
|
2370
|
-
self
|
|
2362
|
+
self,
|
|
2363
|
+
input
|
|
2371
2364
|
};
|
|
2372
2365
|
return outputMapper(args);
|
|
2373
2366
|
}
|