xstate 5.18.2 → 5.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/actions/dist/xstate-actions.cjs.js +2 -2
- package/actions/dist/xstate-actions.development.cjs.js +2 -2
- package/actions/dist/xstate-actions.development.esm.js +2 -2
- package/actions/dist/xstate-actions.esm.js +2 -2
- package/actions/dist/xstate-actions.umd.min.js +1 -1
- package/actions/dist/xstate-actions.umd.min.js.map +1 -1
- package/actors/dist/xstate-actors.cjs.js +1 -1
- package/actors/dist/xstate-actors.development.cjs.js +1 -1
- package/actors/dist/xstate-actors.development.esm.js +1 -1
- package/actors/dist/xstate-actors.esm.js +1 -1
- package/actors/dist/xstate-actors.umd.min.js +1 -1
- package/actors/dist/xstate-actors.umd.min.js.map +1 -1
- package/dev/dist/xstate-dev.cjs.js +1 -1
- package/dev/dist/xstate-dev.development.cjs.js +1 -1
- package/dev/dist/xstate-dev.development.esm.js +1 -1
- package/dev/dist/xstate-dev.esm.js +1 -1
- package/dev/dist/xstate-dev.umd.min.js.map +1 -1
- package/dist/declarations/src/State.d.ts +1 -1
- package/dist/declarations/src/actions/raise.d.ts +9 -1
- package/dist/declarations/src/actions/send.d.ts +10 -1
- package/dist/declarations/src/createActor.d.ts +2 -1
- package/dist/declarations/src/getNextSnapshot.d.ts +2 -0
- package/dist/declarations/src/index.d.ts +1 -0
- package/dist/declarations/src/inspection.d.ts +1 -1
- package/dist/declarations/src/stateUtils.d.ts +17 -7
- package/dist/declarations/src/transition.d.ts +16 -0
- package/dist/declarations/src/types.d.ts +47 -14
- package/dist/declarations/src/utils.d.ts +1 -1
- package/dist/{log-b7ed1b61.development.cjs.js → log-17337367.development.cjs.js} +22 -19
- package/dist/{log-15d0f775.esm.js → log-2a773d37.esm.js} +21 -15
- package/dist/{log-98fcce74.cjs.js → log-b0ee96de.cjs.js} +21 -15
- package/dist/{log-38475d87.development.esm.js → log-ef30c65f.development.esm.js} +22 -19
- package/dist/{raise-5ea71f04.development.esm.js → raise-1db27a82.development.esm.js} +98 -72
- package/dist/{raise-e919c5d4.development.cjs.js → raise-4acdb210.development.cjs.js} +98 -72
- package/dist/{raise-b1e0b9a9.cjs.js → raise-60cebf03.cjs.js} +94 -70
- package/dist/{raise-0f7cf128.esm.js → raise-c17ec2bc.esm.js} +94 -70
- package/dist/xstate.cjs.js +57 -15
- package/dist/xstate.cjs.mjs +2 -0
- package/dist/xstate.development.cjs.js +57 -15
- package/dist/xstate.development.cjs.mjs +2 -0
- package/dist/xstate.development.esm.js +58 -18
- package/dist/xstate.esm.js +58 -18
- package/dist/xstate.umd.min.js +1 -1
- package/dist/xstate.umd.min.js.map +1 -1
- package/guards/dist/xstate-guards.cjs.js +1 -1
- package/guards/dist/xstate-guards.development.cjs.js +1 -1
- package/guards/dist/xstate-guards.development.esm.js +1 -1
- package/guards/dist/xstate-guards.esm.js +1 -1
- package/guards/dist/xstate-guards.umd.min.js +1 -1
- package/guards/dist/xstate-guards.umd.min.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"xstate-dev.umd.min.js","sources":["../../src/dev/index.ts"],"sourcesContent":["import isDevelopment from '#is-development';\nimport { AnyActor, DevToolsAdapter } from '../types.ts';\n\ninterface DevInterface {\n services: Set<AnyActor>;\n register(service: AnyActor): void;\n onRegister(listener: ServiceListener): void;\n}\ntype ServiceListener = (service: AnyActor) => void;\n\nexport interface XStateDevInterface {\n register: (service: AnyActor) => void;\n unregister: (service: AnyActor) => void;\n onRegister: (listener: ServiceListener) => {\n unsubscribe: () => void;\n };\n services: Set<AnyActor>;\n}\n\n// From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis\nexport function getGlobal(): typeof globalThis | undefined {\n if (typeof globalThis !== 'undefined') {\n return globalThis;\n }\n if (typeof self !== 'undefined') {\n return self;\n }\n if (typeof window !== 'undefined') {\n return window;\n }\n if (typeof global !== 'undefined') {\n return global;\n }\n if (isDevelopment) {\n console.warn(\n 'XState could not find a global object in this environment. Please let the maintainers know and raise an issue here: https://github.com/statelyai/xstate/issues'\n );\n }\n}\n\nfunction getDevTools(): DevInterface | undefined {\n const w = getGlobal();\n if (
|
|
1
|
+
{"version":3,"file":"xstate-dev.umd.min.js","sources":["../../src/dev/index.ts"],"sourcesContent":["import isDevelopment from '#is-development';\nimport { AnyActor, DevToolsAdapter } from '../types.ts';\n\ninterface DevInterface {\n services: Set<AnyActor>;\n register(service: AnyActor): void;\n onRegister(listener: ServiceListener): void;\n}\ntype ServiceListener = (service: AnyActor) => void;\n\nexport interface XStateDevInterface {\n register: (service: AnyActor) => void;\n unregister: (service: AnyActor) => void;\n onRegister: (listener: ServiceListener) => {\n unsubscribe: () => void;\n };\n services: Set<AnyActor>;\n}\n\n// From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis\nexport function getGlobal(): typeof globalThis | undefined {\n if (typeof globalThis !== 'undefined') {\n return globalThis;\n }\n if (typeof self !== 'undefined') {\n return self;\n }\n if (typeof window !== 'undefined') {\n return window;\n }\n if (typeof global !== 'undefined') {\n return global;\n }\n if (isDevelopment) {\n console.warn(\n 'XState could not find a global object in this environment. Please let the maintainers know and raise an issue here: https://github.com/statelyai/xstate/issues'\n );\n }\n}\n\nfunction getDevTools(): DevInterface | undefined {\n const w = getGlobal();\n if ((w as any).__xstate__) {\n return (w as any).__xstate__;\n }\n\n return undefined;\n}\n\nexport function registerService(service: AnyActor) {\n if (typeof window === 'undefined') {\n return;\n }\n\n const devTools = getDevTools();\n\n if (devTools) {\n devTools.register(service);\n }\n}\n\nexport const devToolsAdapter: DevToolsAdapter = (service) => {\n if (typeof window === 'undefined') {\n return;\n }\n\n const devTools = getDevTools();\n\n if (devTools) {\n devTools.register(service);\n }\n};\n"],"names":["getGlobal","globalThis","self","window","getDevTools","w","__xstate__","service","devTools","register"],"mappings":"iPAoBO,SAASA,IACd,MAA0B,oBAAfC,WACFA,WAEW,oBAATC,KACFA,KAGAC,MAUX,CAEA,SAASC,IACP,MAAMC,EAAIL,IACV,GAAKK,EAAUC,WACb,OAAQD,EAAUC,UAItB,mBAciDC,IAK/C,MAAMC,EAAWJ,IAEbI,GACFA,EAASC,SAASF,EACpB,kCArBK,SAAyBA,GAK9B,MAAMC,EAAWJ,IAEbI,GACFA,EAASC,SAASF,EAEtB"}
|
|
@@ -4,7 +4,7 @@ import type { ProvidedActor, AnyMachineSnapshot, AnyStateMachine, EventObject, H
|
|
|
4
4
|
type ToTestStateValue<TStateValue extends StateValue> = TStateValue extends string ? TStateValue : IsNever<keyof TStateValue> extends true ? never : keyof TStateValue | {
|
|
5
5
|
[K in keyof TStateValue]?: ToTestStateValue<NonNullable<TStateValue[K]>>;
|
|
6
6
|
};
|
|
7
|
-
export declare function isMachineSnapshot
|
|
7
|
+
export declare function isMachineSnapshot(value: unknown): value is AnyMachineSnapshot;
|
|
8
8
|
interface MachineSnapshotBase<TContext extends MachineContext, TEvent extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TStateValue extends StateValue, TTag extends string, TOutput, TMeta, TStateSchema extends StateSchema = StateSchema> {
|
|
9
9
|
/** The state machine that produced this state snapshot. */
|
|
10
10
|
machine: StateMachine<TContext, TEvent, TChildren, ProvidedActor, ParameterizedObject, ParameterizedObject, string, TStateValue, TTag, unknown, TOutput, EventObject, // TEmitted
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ActionArgs, ActionFunction, DoNotInfer, EventObject, MachineContext, ParameterizedObject, RaiseActionOptions, SendExpr } from "../types.js";
|
|
1
|
+
import { ActionArgs, ActionFunction, DoNotInfer, EventObject, ExecutableActionObject, MachineContext, ParameterizedObject, RaiseActionOptions, SendExpr } from "../types.js";
|
|
2
2
|
export interface RaiseAction<TContext extends MachineContext, TExpressionEvent extends EventObject, TParams extends ParameterizedObject['params'] | undefined, TEvent extends EventObject, TDelay extends string> {
|
|
3
3
|
(args: ActionArgs<TContext, TExpressionEvent, TEvent>, params: TParams): void;
|
|
4
4
|
_out_TEvent?: TEvent;
|
|
@@ -11,3 +11,11 @@ export interface RaiseAction<TContext extends MachineContext, TExpressionEvent e
|
|
|
11
11
|
* @param eventType The event to raise.
|
|
12
12
|
*/
|
|
13
13
|
export declare function raise<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject, TParams extends ParameterizedObject['params'] | undefined, TDelay extends string = never, TUsedDelay extends TDelay = never>(eventOrExpr: DoNotInfer<TEvent> | SendExpr<TContext, TExpressionEvent, TParams, DoNotInfer<TEvent>, TEvent>, options?: RaiseActionOptions<TContext, TExpressionEvent, TParams, DoNotInfer<TEvent>, TUsedDelay>): ActionFunction<TContext, TExpressionEvent, TEvent, TParams, never, never, never, TDelay, never>;
|
|
14
|
+
export interface ExecutableRaiseAction extends ExecutableActionObject {
|
|
15
|
+
type: 'xstate.raise';
|
|
16
|
+
params: {
|
|
17
|
+
event: EventObject;
|
|
18
|
+
id: string | undefined;
|
|
19
|
+
delay: number | undefined;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ActionArgs, ActionFunction, AnyActorRef, AnyEventObject, Cast, DoNotInfer, EventFrom, EventObject, InferEvent, MachineContext, ParameterizedObject, SendExpr, SendToActionOptions } from "../types.js";
|
|
1
|
+
import { ActionArgs, ActionFunction, AnyActorRef, AnyEventObject, Cast, DoNotInfer, EventFrom, EventObject, ExecutableActionObject, InferEvent, MachineContext, ParameterizedObject, SendExpr, SendToActionOptions } from "../types.js";
|
|
2
2
|
export interface SendToAction<TContext extends MachineContext, TExpressionEvent extends EventObject, TParams extends ParameterizedObject['params'] | undefined, TEvent extends EventObject, TDelay extends string> {
|
|
3
3
|
(args: ActionArgs<TContext, TExpressionEvent, TEvent>, params: TParams): void;
|
|
4
4
|
_out_TDelay?: TDelay;
|
|
@@ -30,4 +30,13 @@ type Target<TContext extends MachineContext, TExpressionEvent extends EventObjec
|
|
|
30
30
|
* @param options Options to pass into the send action creator.
|
|
31
31
|
*/
|
|
32
32
|
export declare function forwardTo<TContext extends MachineContext, TExpressionEvent extends EventObject, TParams extends ParameterizedObject['params'] | undefined, TEvent extends EventObject, TDelay extends string = never, TUsedDelay extends TDelay = never>(target: Target<TContext, TExpressionEvent, TParams, TEvent>, options?: SendToActionOptions<TContext, TExpressionEvent, TParams, TEvent, TUsedDelay>): ActionFunction<TContext, TExpressionEvent, TEvent, TParams, never, never, never, TDelay, never>;
|
|
33
|
+
export interface ExecutableSendToAction extends ExecutableActionObject {
|
|
34
|
+
type: 'xstate.sendTo';
|
|
35
|
+
params: {
|
|
36
|
+
event: EventObject;
|
|
37
|
+
id: string | undefined;
|
|
38
|
+
delay: number | undefined;
|
|
39
|
+
to: AnyActorRef;
|
|
40
|
+
};
|
|
41
|
+
}
|
|
33
42
|
export {};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { symbolObservable } from "./symbolObservable.js";
|
|
2
2
|
import { AnyActorSystem, Clock } from "./system.js";
|
|
3
|
+
export declare let executingCustomAction: boolean;
|
|
3
4
|
import type { AnyActorLogic, AnyActorRef, ConditionalRequired, EmittedFrom, EventFromLogic, InputFrom, IsNotNever, Snapshot, SnapshotFrom } from "./types.js";
|
|
4
5
|
import { ActorOptions, ActorRef, InteropSubscribable, Observer, Subscription } from "./types.js";
|
|
5
6
|
export declare const $$ACTOR_TYPE = 1;
|
|
@@ -111,7 +112,7 @@ export declare class Actor<TLogic extends AnyActorLogic> implements ActorRef<Sna
|
|
|
111
112
|
*/
|
|
112
113
|
subscribe(observer: Observer<SnapshotFrom<TLogic>>): Subscription;
|
|
113
114
|
subscribe(nextListener?: (snapshot: SnapshotFrom<TLogic>) => void, errorListener?: (error: any) => void, completeListener?: () => void): Subscription;
|
|
114
|
-
on<TType extends EmittedFrom<TLogic>['type'] | '*'>(type: TType, handler: (emitted: EmittedFrom<TLogic> & (TType extends '*' ?
|
|
115
|
+
on<TType extends EmittedFrom<TLogic>['type'] | '*'>(type: TType, handler: (emitted: EmittedFrom<TLogic> & (TType extends '*' ? unknown : {
|
|
115
116
|
type: TType;
|
|
116
117
|
})) => void): Subscription;
|
|
117
118
|
/** Starts the Actor from the initial state */
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AnyActorLogic, EventFromLogic, InputFrom, SnapshotFrom } from "./types.js";
|
|
2
|
+
/** @deprecated Use `initialTransition(…)` instead. */
|
|
2
3
|
export declare function getInitialSnapshot<T extends AnyActorLogic>(actorLogic: T, ...[input]: undefined extends InputFrom<T> ? [input?: InputFrom<T>] : [input: InputFrom<T>]): SnapshotFrom<T>;
|
|
3
4
|
/**
|
|
4
5
|
* Determines the next snapshot for the given `actorLogic` based on the given
|
|
@@ -7,6 +8,7 @@ export declare function getInitialSnapshot<T extends AnyActorLogic>(actorLogic:
|
|
|
7
8
|
* If the `snapshot` is `undefined`, the initial snapshot of the `actorLogic` is
|
|
8
9
|
* used.
|
|
9
10
|
*
|
|
11
|
+
* @deprecated Use `transition(…)` instead.
|
|
10
12
|
* @example
|
|
11
13
|
*
|
|
12
14
|
* ```ts
|
|
@@ -17,6 +17,7 @@ export type { ActorSystem } from "./system.js";
|
|
|
17
17
|
export { toPromise } from "./toPromise.js";
|
|
18
18
|
export * from "./types.js";
|
|
19
19
|
export { getAllOwnEventDescriptors as __unsafe_getAllOwnEventDescriptors, matchesState, pathToStateValue, toObserver } from "./utils.js";
|
|
20
|
+
export { transition, initialTransition } from "./transition.js";
|
|
20
21
|
export { waitFor } from "./waitFor.js";
|
|
21
22
|
declare global {
|
|
22
23
|
interface SymbolConstructor {
|
|
@@ -26,7 +26,7 @@ export interface InspectedActionEvent extends BaseInspectionEventProperties {
|
|
|
26
26
|
type: '@xstate.action';
|
|
27
27
|
action: {
|
|
28
28
|
type: string;
|
|
29
|
-
params:
|
|
29
|
+
params: unknown;
|
|
30
30
|
};
|
|
31
31
|
}
|
|
32
32
|
export interface InspectedEventEvent extends BaseInspectionEventProperties {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { MachineSnapshot } from "./State.js";
|
|
2
2
|
import type { StateNode } from "./StateNode.js";
|
|
3
|
-
import { AnyEventObject, AnyMachineSnapshot, AnyStateNode, AnyTransitionDefinition, DelayedTransitionDefinition, EventObject, InitialTransitionConfig, InitialTransitionDefinition, MachineContext, StateValue, TransitionDefinition, TODO, UnknownAction,
|
|
3
|
+
import { ActionArgs, AnyEventObject, AnyMachineSnapshot, AnyStateNode, AnyTransitionDefinition, DelayedTransitionDefinition, EventObject, InitialTransitionConfig, InitialTransitionDefinition, MachineContext, StateValue, TransitionDefinition, TODO, UnknownAction, ParameterizedObject, AnyTransitionConfig, AnyActorScope } from "./types.js";
|
|
4
4
|
type StateNodeIterable<TContext extends MachineContext, TE extends EventObject> = Iterable<StateNode<TContext, TE>>;
|
|
5
5
|
type AnyStateNodeIterable = StateNodeIterable<any, any>;
|
|
6
6
|
export declare function getAllStateNodes(stateNodes: Iterable<AnyStateNode>): Set<AnyStateNode>;
|
|
@@ -10,7 +10,7 @@ export declare const isStateId: (str: string) => boolean;
|
|
|
10
10
|
export declare function getCandidates<TEvent extends EventObject>(stateNode: StateNode<any, TEvent>, receivedEventType: TEvent['type']): Array<TransitionDefinition<any, TEvent>>;
|
|
11
11
|
/** All delayed transitions from the config. */
|
|
12
12
|
export declare function getDelayedTransitions(stateNode: AnyStateNode): Array<DelayedTransitionDefinition<MachineContext, EventObject>>;
|
|
13
|
-
export declare function formatTransition
|
|
13
|
+
export declare function formatTransition(stateNode: AnyStateNode, descriptor: string, transitionConfig: AnyTransitionConfig): AnyTransitionDefinition;
|
|
14
14
|
export declare function formatTransitions<TContext extends MachineContext, TEvent extends EventObject>(stateNode: AnyStateNode): Map<string, TransitionDefinition<TContext, TEvent>[]>;
|
|
15
15
|
export declare function formatInitialTransition<TContext extends MachineContext, TEvent extends EventObject>(stateNode: AnyStateNode, _target: string | undefined | InitialTransitionConfig<TContext, TEvent, TODO, TODO, TODO, TODO>): InitialTransitionDefinition<TContext, TEvent>;
|
|
16
16
|
export declare function getInitialStateNodes(stateNode: AnyStateNode): Set<AnyStateNode>;
|
|
@@ -25,13 +25,23 @@ export declare function getStateNodeByPath(stateNode: AnyStateNode, statePath: s
|
|
|
25
25
|
*
|
|
26
26
|
* @param stateValue The state value or State instance
|
|
27
27
|
*/
|
|
28
|
-
export declare function getStateNodes
|
|
28
|
+
export declare function getStateNodes(stateNode: AnyStateNode, stateValue: StateValue): Array<AnyStateNode>;
|
|
29
29
|
export declare function transitionNode<TContext extends MachineContext, TEvent extends EventObject>(stateNode: AnyStateNode, stateValue: StateValue, snapshot: MachineSnapshot<TContext, TEvent, any, any, any, any, any, any>, event: TEvent): Array<TransitionDefinition<TContext, TEvent>> | undefined;
|
|
30
30
|
/** https://www.w3.org/TR/scxml/#microstepProcedure */
|
|
31
|
-
export declare function microstep
|
|
32
|
-
export
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
export declare function microstep(transitions: Array<AnyTransitionDefinition>, currentSnapshot: AnyMachineSnapshot, actorScope: AnyActorScope, event: AnyEventObject, isInitial: boolean, internalQueue: Array<AnyEventObject>): AnyMachineSnapshot;
|
|
32
|
+
export interface BuiltinAction {
|
|
33
|
+
(): void;
|
|
34
|
+
type: `xstate.${string}`;
|
|
35
|
+
resolve: (actorScope: AnyActorScope, snapshot: AnyMachineSnapshot, actionArgs: ActionArgs<any, any, any>, actionParams: ParameterizedObject['params'] | undefined, action: unknown, extra: unknown) => [
|
|
36
|
+
newState: AnyMachineSnapshot,
|
|
37
|
+
params: unknown,
|
|
38
|
+
actions?: UnknownAction[]
|
|
39
|
+
];
|
|
40
|
+
retryResolve: (actorScope: AnyActorScope, snapshot: AnyMachineSnapshot, params: unknown) => void;
|
|
41
|
+
execute: (actorScope: AnyActorScope, params: unknown) => void;
|
|
42
|
+
}
|
|
43
|
+
export declare function resolveActionsAndContext(currentSnapshot: AnyMachineSnapshot, event: AnyEventObject, actorScope: AnyActorScope, actions: UnknownAction[], internalQueue: AnyEventObject[], deferredActorIds: string[] | undefined): AnyMachineSnapshot;
|
|
44
|
+
export declare function macrostep(snapshot: AnyMachineSnapshot, event: EventObject, actorScope: AnyActorScope, internalQueue: AnyEventObject[]): {
|
|
35
45
|
snapshot: typeof snapshot;
|
|
36
46
|
microstates: Array<typeof snapshot>;
|
|
37
47
|
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { AnyActorLogic, EventFromLogic, InputFrom, SnapshotFrom, ExecutableActionsFrom } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Given actor `logic`, a `snapshot`, and an `event`, returns a tuple of the
|
|
4
|
+
* `nextSnapshot` and `actions` to execute.
|
|
5
|
+
*
|
|
6
|
+
* This is a pure function that does not execute `actions`.
|
|
7
|
+
*/
|
|
8
|
+
export declare function transition<T extends AnyActorLogic>(logic: T, snapshot: SnapshotFrom<T>, event: EventFromLogic<T>): [nextSnapshot: SnapshotFrom<T>, actions: ExecutableActionsFrom<T>[]];
|
|
9
|
+
/**
|
|
10
|
+
* Given actor `logic` and optional `input`, returns a tuple of the
|
|
11
|
+
* `nextSnapshot` and `actions` to execute from the initial transition (no
|
|
12
|
+
* previous state).
|
|
13
|
+
*
|
|
14
|
+
* This is a pure function that does not execute `actions`.
|
|
15
|
+
*/
|
|
16
|
+
export declare function initialTransition<T extends AnyActorLogic>(logic: T, ...[input]: undefined extends InputFrom<T> ? [input?: InputFrom<T>] : [input: InputFrom<T>]): [SnapshotFrom<T>, ExecutableActionsFrom<T>[]];
|
|
@@ -8,6 +8,8 @@ import type { Actor } from "./createActor.js";
|
|
|
8
8
|
import { Spawner } from "./spawn.js";
|
|
9
9
|
import { AnyActorSystem, Clock } from './system.js';
|
|
10
10
|
import { InspectionEvent } from "./inspection.js";
|
|
11
|
+
import { ExecutableRaiseAction } from "./actions/raise.js";
|
|
12
|
+
import { ExecutableSendToAction } from "./actions/send.js";
|
|
11
13
|
export type Identity<T> = {
|
|
12
14
|
[K in keyof T]: T[K];
|
|
13
15
|
};
|
|
@@ -42,7 +44,7 @@ export type AnyFunction = (...args: any[]) => any;
|
|
|
42
44
|
type ReturnTypeOrValue<T> = T extends AnyFunction ? ReturnType<T> : T;
|
|
43
45
|
export type IsNever<T> = [T] extends [never] ? true : false;
|
|
44
46
|
export type IsNotNever<T> = [T] extends [never] ? false : true;
|
|
45
|
-
export type Compute<A
|
|
47
|
+
export type Compute<A> = {
|
|
46
48
|
[K in keyof A]: A[K];
|
|
47
49
|
} & unknown;
|
|
48
50
|
export type Prop<T, K> = K extends keyof T ? T[K] : never;
|
|
@@ -55,13 +57,13 @@ export type IndexByProp<T extends Record<P, string>, P extends keyof T> = {
|
|
|
55
57
|
export type IndexByType<T extends {
|
|
56
58
|
type: string;
|
|
57
59
|
}> = IndexByProp<T, 'type'>;
|
|
58
|
-
export type Equals<A1
|
|
60
|
+
export type Equals<A1, A2> = (<A>() => A extends A2 ? true : false) extends <A>() => A extends A1 ? true : false ? true : false;
|
|
59
61
|
export type IsAny<T> = Equals<T, any>;
|
|
60
62
|
export type Cast<A, B> = A extends B ? A : B;
|
|
61
63
|
export type DoNotInfer<T> = [T][T extends any ? 0 : any];
|
|
62
64
|
/** @deprecated Use the built-in `NoInfer` type instead */
|
|
63
65
|
export type NoInfer<T> = DoNotInfer<T>;
|
|
64
|
-
export type LowInfer<T> = T &
|
|
66
|
+
export type LowInfer<T> = T & NonNullable<unknown>;
|
|
65
67
|
export type MetaObject = Record<string, any>;
|
|
66
68
|
export type Lazy<T> = () => T;
|
|
67
69
|
export type MaybeLazy<T> = T | Lazy<T>;
|
|
@@ -175,7 +177,7 @@ export type DelayedTransitions<TContext extends MachineContext, TEvent extends E
|
|
|
175
177
|
[K in Delay<TDelay>]?: string | SingleOrArray<TransitionConfig<TContext, TEvent, TEvent, TActor, TAction, TGuard, TDelay, TODO, // TEmitted
|
|
176
178
|
TODO>>;
|
|
177
179
|
};
|
|
178
|
-
export type StateTypes = 'atomic' | 'compound' | 'parallel' | 'final' | 'history' | string;
|
|
180
|
+
export type StateTypes = 'atomic' | 'compound' | 'parallel' | 'final' | 'history' | ({} & string);
|
|
179
181
|
export type SingleOrArray<T> = readonly T[] | T;
|
|
180
182
|
export type StateNodesConfig<TContext extends MachineContext, TEvent extends EventObject> = {
|
|
181
183
|
[K in string]: StateNode<TContext, TEvent>;
|
|
@@ -246,14 +248,14 @@ export type InvokeConfig<TContext extends MachineContext, TEvent extends EventOb
|
|
|
246
248
|
onDone?: string | SingleOrArray<TransitionConfigOrTarget<TContext, DoneActorEvent<any>, // TODO: consider replacing with `unknown`
|
|
247
249
|
TEvent, TActor, TAction, TGuard, TDelay, TEmitted, TMeta>>;
|
|
248
250
|
/**
|
|
249
|
-
* The transition to take upon the invoked child machine sending an
|
|
250
|
-
* event.
|
|
251
|
+
* The transition to take upon the invoked child machine sending an
|
|
252
|
+
* error event.
|
|
251
253
|
*/
|
|
252
254
|
onError?: string | SingleOrArray<TransitionConfigOrTarget<TContext, ErrorActorEvent, TEvent, TActor, TAction, TGuard, TDelay, TEmitted, TMeta>>;
|
|
253
255
|
onSnapshot?: string | SingleOrArray<TransitionConfigOrTarget<TContext, SnapshotEvent, TEvent, TActor, TAction, TGuard, TDelay, TEmitted, TMeta>>;
|
|
254
256
|
};
|
|
255
257
|
export type AnyInvokeConfig = InvokeConfig<any, any, any, any, any, any, any, any>;
|
|
256
|
-
export interface StateNodeConfig<TContext extends MachineContext, TEvent extends EventObject, TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string, TTag extends string,
|
|
258
|
+
export interface StateNodeConfig<TContext extends MachineContext, TEvent extends EventObject, TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string, TTag extends string, _TOutput, TEmitted extends EventObject, TMeta extends MetaObject> {
|
|
257
259
|
/** The initial state transition. */
|
|
258
260
|
initial?: InitialTransitionConfig<TContext, TEvent, TActor, TAction, TGuard, TDelay> | string | undefined;
|
|
259
261
|
/**
|
|
@@ -755,11 +757,12 @@ export interface ActorRef<TSnapshot extends Snapshot<unknown>, TEvent extends Ev
|
|
|
755
757
|
_parent?: AnyActorRef;
|
|
756
758
|
system: AnyActorSystem;
|
|
757
759
|
src: string | AnyActorLogic;
|
|
758
|
-
on: <TType extends TEmitted['type'] | '*'>(type: TType, handler: (emitted: TEmitted & (TType extends '*' ?
|
|
760
|
+
on: <TType extends TEmitted['type'] | '*'>(type: TType, handler: (emitted: TEmitted & (TType extends '*' ? unknown : {
|
|
759
761
|
type: TType;
|
|
760
762
|
})) => void) => Subscription;
|
|
761
763
|
}
|
|
762
|
-
export type AnyActorRef = ActorRef<any, any,
|
|
764
|
+
export type AnyActorRef = ActorRef<any, any, // TODO: shouldn't this be AnyEventObject?
|
|
765
|
+
any>;
|
|
763
766
|
export type ActorRefLike = Pick<AnyActorRef, 'sessionId' | 'send' | 'getSnapshot'>;
|
|
764
767
|
export type UnknownActorRef = ActorRef<Snapshot<unknown>, EventObject>;
|
|
765
768
|
export type ActorLogicFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<any, any, any, any, any, any, any, any, any, any, any, any, any, // TMeta
|
|
@@ -779,6 +782,7 @@ export interface ActorScope<TSnapshot extends Snapshot<unknown>, TEvent extends
|
|
|
779
782
|
emit: (event: TEmitted) => void;
|
|
780
783
|
system: TSystem;
|
|
781
784
|
stopChild: (child: AnyActorRef) => void;
|
|
785
|
+
actionExecutor: ActionExecutor;
|
|
782
786
|
}
|
|
783
787
|
export type AnyActorScope = ActorScope<any, // TSnapshot
|
|
784
788
|
any, // TEvent
|
|
@@ -815,15 +819,15 @@ in TInput = NonReducibleUnknown, TSystem extends AnyActorSystem = AnyActorSystem
|
|
|
815
819
|
/** The initial setup/configuration used to create the actor logic. */
|
|
816
820
|
config?: unknown;
|
|
817
821
|
/**
|
|
818
|
-
* Transition function that processes the current state and an incoming
|
|
819
|
-
*
|
|
822
|
+
* Transition function that processes the current state and an incoming event
|
|
823
|
+
* to produce a new state.
|
|
820
824
|
*
|
|
821
825
|
* @param snapshot - The current state.
|
|
822
|
-
* @param
|
|
826
|
+
* @param event - The incoming event.
|
|
823
827
|
* @param actorScope - The actor scope.
|
|
824
828
|
* @returns The new state.
|
|
825
829
|
*/
|
|
826
|
-
transition: (snapshot: TSnapshot,
|
|
830
|
+
transition: (snapshot: TSnapshot, event: TEvent, actorScope: ActorScope<TSnapshot, TEvent, TSystem, TEmitted>) => TSnapshot;
|
|
827
831
|
/**
|
|
828
832
|
* Called to provide the initial state of the actor.
|
|
829
833
|
*
|
|
@@ -895,7 +899,7 @@ export type ToChildren<TActor extends ProvidedActor> = string extends TActor['sr
|
|
|
895
899
|
include: {
|
|
896
900
|
[id: string]: TActor extends any ? ActorRefFromLogic<TActor['logic']> | undefined : never;
|
|
897
901
|
};
|
|
898
|
-
exclude:
|
|
902
|
+
exclude: unknown;
|
|
899
903
|
}[undefined extends TActor['id'] ? 'include' : string extends TActor['id'] ? 'include' : 'exclude']>;
|
|
900
904
|
export type StateSchema = {
|
|
901
905
|
id?: string;
|
|
@@ -960,4 +964,33 @@ export type ToStateValue<T extends StateSchema> = T extends {
|
|
|
960
964
|
[StateKey in K]: ToStateValue<T['states'][K]>;
|
|
961
965
|
};
|
|
962
966
|
}>> : never) : {};
|
|
967
|
+
export interface ExecutableActionObject {
|
|
968
|
+
type: string;
|
|
969
|
+
info: ActionArgs<MachineContext, EventObject, EventObject>;
|
|
970
|
+
params: NonReducibleUnknown;
|
|
971
|
+
exec: ((info: ActionArgs<any, any, any>, params: unknown) => void) | undefined;
|
|
972
|
+
}
|
|
973
|
+
export interface ToExecutableAction<T extends ParameterizedObject> extends ExecutableActionObject {
|
|
974
|
+
type: T['type'];
|
|
975
|
+
params: T['params'];
|
|
976
|
+
exec: undefined;
|
|
977
|
+
}
|
|
978
|
+
export interface ExecutableSpawnAction extends ExecutableActionObject {
|
|
979
|
+
type: 'xstate.spawnChild';
|
|
980
|
+
info: ActionArgs<MachineContext, EventObject, EventObject>;
|
|
981
|
+
params: {
|
|
982
|
+
id: string;
|
|
983
|
+
actorRef: AnyActorRef | undefined;
|
|
984
|
+
src: string | AnyActorLogic;
|
|
985
|
+
};
|
|
986
|
+
}
|
|
987
|
+
export type SpecialExecutableAction = ExecutableSpawnAction | ExecutableRaiseAction | ExecutableSendToAction;
|
|
988
|
+
export type ExecutableActionsFrom<T extends AnyActorLogic> = T extends StateMachine<infer _TContext, infer _TEvent, infer _TChildren, infer _TActor, infer TAction, infer _TGuard, infer _TDelay, infer _TStateValue, infer _TTag, infer _TInput, infer _TOutput, infer _TEmitted, infer _TMeta, infer _TConfig> ? SpecialExecutableAction | (string extends TAction['type'] ? never : ToExecutableAction<TAction>) : never;
|
|
989
|
+
export type ActionExecutor = (actionToExecute: ExecutableActionObject) => void;
|
|
990
|
+
export type BuiltinActionResolution = [
|
|
991
|
+
AnyMachineSnapshot,
|
|
992
|
+
NonReducibleUnknown,
|
|
993
|
+
// params
|
|
994
|
+
UnknownAction[] | undefined
|
|
995
|
+
];
|
|
963
996
|
export {};
|
|
@@ -9,7 +9,7 @@ export declare function mapValues<P, O extends Record<string, unknown>>(collecti
|
|
|
9
9
|
export declare function toArray<T>(value: readonly T[] | T | undefined): readonly T[];
|
|
10
10
|
export declare function resolveOutput<TContext extends MachineContext, TExpressionEvent extends EventObject>(mapper: Mapper<TContext, TExpressionEvent, unknown, EventObject> | NonReducibleUnknown, context: TContext, event: TExpressionEvent, self: AnyActorRef): unknown;
|
|
11
11
|
export declare function isErrorActorEvent(event: AnyEventObject): event is ErrorActorEvent;
|
|
12
|
-
export declare function toTransitionConfigArray
|
|
12
|
+
export declare function toTransitionConfigArray(configLike: SingleOrArray<AnyTransitionConfig | TransitionConfigTarget>): Array<AnyTransitionConfig>;
|
|
13
13
|
export declare function normalizeTarget<TContext extends MachineContext, TEvent extends EventObject>(target: SingleOrArray<string | StateNode<TContext, TEvent>> | undefined): ReadonlyArray<string | StateNode<TContext, TEvent>> | undefined;
|
|
14
14
|
export declare function toObserver<T>(nextHandler?: Observer<T> | ((value: T) => void), errorHandler?: (error: any) => void, completionHandler?: () => void): Observer<T>;
|
|
15
15
|
export declare function createInvokeId(stateNodeId: string, index: number): string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var guards_dist_xstateGuards = require('./raise-
|
|
3
|
+
var guards_dist_xstateGuards = require('./raise-4acdb210.development.cjs.js');
|
|
4
4
|
|
|
5
5
|
function createSpawner(actorScope, {
|
|
6
6
|
machine,
|
|
@@ -85,7 +85,7 @@ function resolveAssign(actorScope, snapshot, actionArgs, actionParams, {
|
|
|
85
85
|
...snapshot.children,
|
|
86
86
|
...spawnedChildren
|
|
87
87
|
} : snapshot.children
|
|
88
|
-
})];
|
|
88
|
+
}), undefined, undefined];
|
|
89
89
|
}
|
|
90
90
|
/**
|
|
91
91
|
* Updates the current context of the machine.
|
|
@@ -125,7 +125,7 @@ function assign(assignment) {
|
|
|
125
125
|
if (guards_dist_xstateGuards.executingCustomAction) {
|
|
126
126
|
console.warn('Custom actions should not call `assign()` directly, as it is not imperative. See https://stately.ai/docs/actions#built-in-actions for more details.');
|
|
127
127
|
}
|
|
128
|
-
function assign(
|
|
128
|
+
function assign(_args, _params) {
|
|
129
129
|
{
|
|
130
130
|
throw new Error(`This isn't supposed to be called`);
|
|
131
131
|
}
|
|
@@ -139,13 +139,10 @@ function assign(assignment) {
|
|
|
139
139
|
function resolveEmit(_, snapshot, args, actionParams, {
|
|
140
140
|
event: eventOrExpr
|
|
141
141
|
}) {
|
|
142
|
-
if (typeof eventOrExpr === 'string') {
|
|
143
|
-
throw new Error(`Only event objects may be used with emit; use emit({ type: "${eventOrExpr}" }) instead`);
|
|
144
|
-
}
|
|
145
142
|
const resolvedEvent = typeof eventOrExpr === 'function' ? eventOrExpr(args, actionParams) : eventOrExpr;
|
|
146
143
|
return [snapshot, {
|
|
147
144
|
event: resolvedEvent
|
|
148
|
-
}];
|
|
145
|
+
}, undefined];
|
|
149
146
|
}
|
|
150
147
|
function executeEmit(actorScope, {
|
|
151
148
|
event
|
|
@@ -193,7 +190,7 @@ eventOrExpr) {
|
|
|
193
190
|
if (guards_dist_xstateGuards.executingCustomAction) {
|
|
194
191
|
console.warn('Custom actions should not call `emit()` directly, as it is not imperative. See https://stately.ai/docs/actions#built-in-actions for more details.');
|
|
195
192
|
}
|
|
196
|
-
function emit(
|
|
193
|
+
function emit(_args, _params) {
|
|
197
194
|
{
|
|
198
195
|
throw new Error(`This isn't supposed to be called`);
|
|
199
196
|
}
|
|
@@ -241,8 +238,6 @@ eventOrExpr) {
|
|
|
241
238
|
* "someChildState" }`.
|
|
242
239
|
*/
|
|
243
240
|
|
|
244
|
-
// TODO: remove once TS fixes this type-widening issue
|
|
245
|
-
|
|
246
241
|
/** @deprecated Use `AnyMachineSnapshot` instead */
|
|
247
242
|
|
|
248
243
|
// TODO: possibly refactor this somehow, use even a simpler type, and maybe even make `machine.options` private or something
|
|
@@ -273,6 +268,8 @@ let SpecialTargets = /*#__PURE__*/function (SpecialTargets) {
|
|
|
273
268
|
|
|
274
269
|
/** @deprecated */
|
|
275
270
|
|
|
271
|
+
// TODO: cover all that can be actually returned
|
|
272
|
+
|
|
276
273
|
function resolveSendTo(actorScope, snapshot, args, actionParams, {
|
|
277
274
|
to,
|
|
278
275
|
event: eventOrExpr,
|
|
@@ -281,7 +278,9 @@ function resolveSendTo(actorScope, snapshot, args, actionParams, {
|
|
|
281
278
|
}, extra) {
|
|
282
279
|
const delaysMap = snapshot.machine.implementations.delays;
|
|
283
280
|
if (typeof eventOrExpr === 'string') {
|
|
284
|
-
throw new Error(
|
|
281
|
+
throw new Error(
|
|
282
|
+
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
283
|
+
`Only event objects may be used with sendTo; use sendTo({ type: "${eventOrExpr}" }) instead`);
|
|
285
284
|
}
|
|
286
285
|
const resolvedEvent = typeof eventOrExpr === 'function' ? eventOrExpr(args, actionParams) : eventOrExpr;
|
|
287
286
|
let resolvedDelay;
|
|
@@ -294,9 +293,12 @@ function resolveSendTo(actorScope, snapshot, args, actionParams, {
|
|
|
294
293
|
const resolvedTarget = typeof to === 'function' ? to(args, actionParams) : to;
|
|
295
294
|
let targetActorRef;
|
|
296
295
|
if (typeof resolvedTarget === 'string') {
|
|
296
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison
|
|
297
297
|
if (resolvedTarget === SpecialTargets.Parent) {
|
|
298
298
|
targetActorRef = actorScope.self._parent;
|
|
299
|
-
}
|
|
299
|
+
}
|
|
300
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison
|
|
301
|
+
else if (resolvedTarget === SpecialTargets.Internal) {
|
|
300
302
|
targetActorRef = actorScope.self;
|
|
301
303
|
} else if (resolvedTarget.startsWith('#_')) {
|
|
302
304
|
// SCXML compatibility: https://www.w3.org/TR/scxml/#SCXMLEventProcessor
|
|
@@ -313,10 +315,11 @@ function resolveSendTo(actorScope, snapshot, args, actionParams, {
|
|
|
313
315
|
}
|
|
314
316
|
return [snapshot, {
|
|
315
317
|
to: targetActorRef,
|
|
318
|
+
targetId: typeof resolvedTarget === 'string' ? resolvedTarget : undefined,
|
|
316
319
|
event: resolvedEvent,
|
|
317
320
|
id,
|
|
318
321
|
delay: resolvedDelay
|
|
319
|
-
}];
|
|
322
|
+
}, undefined];
|
|
320
323
|
}
|
|
321
324
|
function retryResolveSendTo(_, snapshot, params) {
|
|
322
325
|
if (typeof params.to === 'string') {
|
|
@@ -356,14 +359,14 @@ function executeSendTo(actorScope, params) {
|
|
|
356
359
|
*/
|
|
357
360
|
function sendTo(to, eventOrExpr, options) {
|
|
358
361
|
if (guards_dist_xstateGuards.executingCustomAction) {
|
|
359
|
-
console.warn('Custom actions should not call `
|
|
362
|
+
console.warn('Custom actions should not call `sendTo()` directly, as it is not imperative. See https://stately.ai/docs/actions#built-in-actions for more details.');
|
|
360
363
|
}
|
|
361
|
-
function sendTo(
|
|
364
|
+
function sendTo(_args, _params) {
|
|
362
365
|
{
|
|
363
366
|
throw new Error(`This isn't supposed to be called`);
|
|
364
367
|
}
|
|
365
368
|
}
|
|
366
|
-
sendTo.type = '
|
|
369
|
+
sendTo.type = 'xstate.sendTo';
|
|
367
370
|
sendTo.to = to;
|
|
368
371
|
sendTo.event = eventOrExpr;
|
|
369
372
|
sendTo.id = options?.id;
|
|
@@ -473,7 +476,7 @@ function resolveEnqueueActions(actorScope, snapshot, args, actionParams, {
|
|
|
473
476
|
* ```
|
|
474
477
|
*/
|
|
475
478
|
function enqueueActions(collect) {
|
|
476
|
-
function enqueueActions(
|
|
479
|
+
function enqueueActions(_args, _params) {
|
|
477
480
|
{
|
|
478
481
|
throw new Error(`This isn't supposed to be called`);
|
|
479
482
|
}
|
|
@@ -491,7 +494,7 @@ function resolveLog(_, snapshot, actionArgs, actionParams, {
|
|
|
491
494
|
return [snapshot, {
|
|
492
495
|
value: typeof value === 'function' ? value(actionArgs, actionParams) : value,
|
|
493
496
|
label
|
|
494
|
-
}];
|
|
497
|
+
}, undefined];
|
|
495
498
|
}
|
|
496
499
|
function executeLog({
|
|
497
500
|
logger
|
|
@@ -521,7 +524,7 @@ function log(value = ({
|
|
|
521
524
|
context,
|
|
522
525
|
event
|
|
523
526
|
}), label) {
|
|
524
|
-
function log(
|
|
527
|
+
function log(_args, _params) {
|
|
525
528
|
{
|
|
526
529
|
throw new Error(`This isn't supposed to be called`);
|
|
527
530
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { T as ProcessingStatus, z as resolveReferencedActor, A as createActor, U as cloneMachineSnapshot, V as XSTATE_ERROR, W as createErrorActorEvent, e as evaluateGuard, M as cancel, O as raise, P as spawnChild, R as stopChild } from './raise-
|
|
1
|
+
import { T as ProcessingStatus, z as resolveReferencedActor, A as createActor, U as cloneMachineSnapshot, V as XSTATE_ERROR, W as createErrorActorEvent, e as evaluateGuard, M as cancel, O as raise, P as spawnChild, R as stopChild } from './raise-c17ec2bc.esm.js';
|
|
2
2
|
|
|
3
3
|
function createSpawner(actorScope, {
|
|
4
4
|
machine,
|
|
@@ -83,7 +83,7 @@ function resolveAssign(actorScope, snapshot, actionArgs, actionParams, {
|
|
|
83
83
|
...snapshot.children,
|
|
84
84
|
...spawnedChildren
|
|
85
85
|
} : snapshot.children
|
|
86
|
-
})];
|
|
86
|
+
}), undefined, undefined];
|
|
87
87
|
}
|
|
88
88
|
/**
|
|
89
89
|
* Updates the current context of the machine.
|
|
@@ -120,7 +120,7 @@ function resolveAssign(actorScope, snapshot, actionArgs, actionParams, {
|
|
|
120
120
|
* update.
|
|
121
121
|
*/
|
|
122
122
|
function assign(assignment) {
|
|
123
|
-
function assign(
|
|
123
|
+
function assign(_args, _params) {
|
|
124
124
|
}
|
|
125
125
|
assign.type = 'xstate.assign';
|
|
126
126
|
assign.assignment = assignment;
|
|
@@ -134,7 +134,7 @@ function resolveEmit(_, snapshot, args, actionParams, {
|
|
|
134
134
|
const resolvedEvent = typeof eventOrExpr === 'function' ? eventOrExpr(args, actionParams) : eventOrExpr;
|
|
135
135
|
return [snapshot, {
|
|
136
136
|
event: resolvedEvent
|
|
137
|
-
}];
|
|
137
|
+
}, undefined];
|
|
138
138
|
}
|
|
139
139
|
function executeEmit(actorScope, {
|
|
140
140
|
event
|
|
@@ -179,7 +179,7 @@ function executeEmit(actorScope, {
|
|
|
179
179
|
*/
|
|
180
180
|
function emit(/** The event to emit, or an expression that returns an event to emit. */
|
|
181
181
|
eventOrExpr) {
|
|
182
|
-
function emit(
|
|
182
|
+
function emit(_args, _params) {
|
|
183
183
|
}
|
|
184
184
|
emit.type = 'xstate.emit';
|
|
185
185
|
emit.event = eventOrExpr;
|
|
@@ -224,8 +224,6 @@ eventOrExpr) {
|
|
|
224
224
|
* "someChildState" }`.
|
|
225
225
|
*/
|
|
226
226
|
|
|
227
|
-
// TODO: remove once TS fixes this type-widening issue
|
|
228
|
-
|
|
229
227
|
/** @deprecated Use `AnyMachineSnapshot` instead */
|
|
230
228
|
|
|
231
229
|
// TODO: possibly refactor this somehow, use even a simpler type, and maybe even make `machine.options` private or something
|
|
@@ -256,6 +254,8 @@ let SpecialTargets = /*#__PURE__*/function (SpecialTargets) {
|
|
|
256
254
|
|
|
257
255
|
/** @deprecated */
|
|
258
256
|
|
|
257
|
+
// TODO: cover all that can be actually returned
|
|
258
|
+
|
|
259
259
|
function resolveSendTo(actorScope, snapshot, args, actionParams, {
|
|
260
260
|
to,
|
|
261
261
|
event: eventOrExpr,
|
|
@@ -264,7 +264,9 @@ function resolveSendTo(actorScope, snapshot, args, actionParams, {
|
|
|
264
264
|
}, extra) {
|
|
265
265
|
const delaysMap = snapshot.machine.implementations.delays;
|
|
266
266
|
if (typeof eventOrExpr === 'string') {
|
|
267
|
-
throw new Error(
|
|
267
|
+
throw new Error(
|
|
268
|
+
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
269
|
+
`Only event objects may be used with sendTo; use sendTo({ type: "${eventOrExpr}" }) instead`);
|
|
268
270
|
}
|
|
269
271
|
const resolvedEvent = typeof eventOrExpr === 'function' ? eventOrExpr(args, actionParams) : eventOrExpr;
|
|
270
272
|
let resolvedDelay;
|
|
@@ -277,9 +279,12 @@ function resolveSendTo(actorScope, snapshot, args, actionParams, {
|
|
|
277
279
|
const resolvedTarget = typeof to === 'function' ? to(args, actionParams) : to;
|
|
278
280
|
let targetActorRef;
|
|
279
281
|
if (typeof resolvedTarget === 'string') {
|
|
282
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison
|
|
280
283
|
if (resolvedTarget === SpecialTargets.Parent) {
|
|
281
284
|
targetActorRef = actorScope.self._parent;
|
|
282
|
-
}
|
|
285
|
+
}
|
|
286
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison
|
|
287
|
+
else if (resolvedTarget === SpecialTargets.Internal) {
|
|
283
288
|
targetActorRef = actorScope.self;
|
|
284
289
|
} else if (resolvedTarget.startsWith('#_')) {
|
|
285
290
|
// SCXML compatibility: https://www.w3.org/TR/scxml/#SCXMLEventProcessor
|
|
@@ -296,10 +301,11 @@ function resolveSendTo(actorScope, snapshot, args, actionParams, {
|
|
|
296
301
|
}
|
|
297
302
|
return [snapshot, {
|
|
298
303
|
to: targetActorRef,
|
|
304
|
+
targetId: typeof resolvedTarget === 'string' ? resolvedTarget : undefined,
|
|
299
305
|
event: resolvedEvent,
|
|
300
306
|
id,
|
|
301
307
|
delay: resolvedDelay
|
|
302
|
-
}];
|
|
308
|
+
}, undefined];
|
|
303
309
|
}
|
|
304
310
|
function retryResolveSendTo(_, snapshot, params) {
|
|
305
311
|
if (typeof params.to === 'string') {
|
|
@@ -338,9 +344,9 @@ function executeSendTo(actorScope, params) {
|
|
|
338
344
|
* - `delay` - The number of milliseconds to delay the sending of the event.
|
|
339
345
|
*/
|
|
340
346
|
function sendTo(to, eventOrExpr, options) {
|
|
341
|
-
function sendTo(
|
|
347
|
+
function sendTo(_args, _params) {
|
|
342
348
|
}
|
|
343
|
-
sendTo.type = '
|
|
349
|
+
sendTo.type = 'xstate.sendTo';
|
|
344
350
|
sendTo.to = to;
|
|
345
351
|
sendTo.event = eventOrExpr;
|
|
346
352
|
sendTo.id = options?.id;
|
|
@@ -440,7 +446,7 @@ function resolveEnqueueActions(actorScope, snapshot, args, actionParams, {
|
|
|
440
446
|
* ```
|
|
441
447
|
*/
|
|
442
448
|
function enqueueActions(collect) {
|
|
443
|
-
function enqueueActions(
|
|
449
|
+
function enqueueActions(_args, _params) {
|
|
444
450
|
}
|
|
445
451
|
enqueueActions.type = 'xstate.enqueueActions';
|
|
446
452
|
enqueueActions.collect = collect;
|
|
@@ -455,7 +461,7 @@ function resolveLog(_, snapshot, actionArgs, actionParams, {
|
|
|
455
461
|
return [snapshot, {
|
|
456
462
|
value: typeof value === 'function' ? value(actionArgs, actionParams) : value,
|
|
457
463
|
label
|
|
458
|
-
}];
|
|
464
|
+
}, undefined];
|
|
459
465
|
}
|
|
460
466
|
function executeLog({
|
|
461
467
|
logger
|
|
@@ -485,7 +491,7 @@ function log(value = ({
|
|
|
485
491
|
context,
|
|
486
492
|
event
|
|
487
493
|
}), label) {
|
|
488
|
-
function log(
|
|
494
|
+
function log(_args, _params) {
|
|
489
495
|
}
|
|
490
496
|
log.type = 'xstate.log';
|
|
491
497
|
log.value = value;
|