xstate 5.0.0-beta.9 → 5.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -8
- package/actions/dist/xstate-actions.cjs.js +19 -5
- package/actions/dist/xstate-actions.cjs.mjs +3 -15
- package/actions/dist/xstate-actions.development.cjs.js +21 -0
- package/actions/dist/xstate-actions.development.cjs.mjs +13 -0
- package/actions/dist/xstate-actions.development.esm.js +3 -0
- package/actions/dist/xstate-actions.esm.js +3 -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 +621 -4
- package/actors/dist/xstate-actors.cjs.mjs +1 -8
- package/actors/dist/xstate-actors.development.cjs.js +624 -0
- package/actors/dist/xstate-actors.development.cjs.mjs +8 -0
- package/actors/dist/xstate-actors.development.esm.js +615 -0
- package/actors/dist/xstate-actors.esm.js +615 -2
- 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 +45 -4
- package/{dist/index-0f3fdf0c.cjs.prod.js → dev/dist/xstate-dev.development.cjs.js} +6 -7
- package/dev/dist/xstate-dev.development.cjs.mjs +5 -0
- package/{dist/index-50bd0aff.esm.js → dev/dist/xstate-dev.development.esm.js} +6 -8
- package/dev/dist/xstate-dev.esm.js +42 -1
- package/dev/dist/xstate-dev.umd.min.js +1 -1
- package/dev/dist/xstate-dev.umd.min.js.map +1 -1
- package/dist/declarations/src/SimulatedClock.d.ts +1 -1
- package/dist/declarations/src/State.d.ts +47 -73
- package/dist/declarations/src/StateMachine.d.ts +29 -57
- package/dist/declarations/src/StateNode.d.ts +36 -33
- package/dist/declarations/src/actions/assign.d.ts +11 -2
- package/dist/declarations/src/actions/cancel.d.ts +7 -3
- package/dist/declarations/src/actions/enqueueActions.d.ts +32 -0
- package/dist/declarations/src/actions/log.d.ts +7 -3
- package/dist/declarations/src/actions/raise.d.ts +7 -2
- package/dist/declarations/src/actions/send.d.ts +14 -36
- package/dist/declarations/src/actions/spawnChild.d.ts +29 -0
- package/dist/declarations/src/actions/stopChild.d.ts +18 -0
- package/dist/declarations/src/actions.d.ts +8 -48
- package/dist/declarations/src/actors/callback.d.ts +91 -8
- package/dist/declarations/src/actors/index.d.ts +6 -28
- package/dist/declarations/src/actors/observable.d.ts +101 -18
- package/dist/declarations/src/actors/promise.d.ts +80 -10
- package/dist/declarations/src/actors/transition.d.ts +64 -9
- package/dist/declarations/src/constants.d.ts +3 -0
- package/dist/declarations/src/createMachine.d.ts +20 -0
- package/dist/declarations/src/dev/index.d.ts +6 -6
- package/dist/declarations/src/guards.d.ts +41 -8
- package/dist/declarations/src/index.d.ts +18 -23
- package/dist/declarations/src/interpreter.d.ts +149 -41
- package/dist/declarations/src/setup.d.ts +51 -0
- package/dist/declarations/src/spawn.d.ts +23 -2
- package/dist/declarations/src/stateUtils.d.ts +30 -45
- package/dist/declarations/src/system.d.ts +26 -2
- package/dist/declarations/src/typegenTypes.d.ts +34 -22
- package/dist/declarations/src/types.d.ts +527 -669
- package/dist/declarations/src/utils.d.ts +15 -52
- package/dist/declarations/src/waitFor.d.ts +2 -2
- package/dist/log-22e678c5.esm.js +364 -0
- package/dist/log-5e226275.cjs.js +372 -0
- package/dist/log-641cd926.development.cjs.js +394 -0
- package/dist/log-f196f85f.development.esm.js +386 -0
- package/dist/raise-34e25c2c.cjs.js +2368 -0
- package/dist/raise-62704519.development.cjs.js +2422 -0
- package/dist/raise-89c581c4.development.esm.js +2371 -0
- package/dist/raise-8bc422d1.esm.js +2317 -0
- package/dist/xstate.cjs.js +728 -4
- package/dist/xstate.cjs.mjs +9 -9
- package/dist/xstate.development.cjs.js +737 -0
- package/dist/xstate.development.cjs.mjs +39 -0
- package/dist/xstate.development.esm.js +699 -0
- package/dist/xstate.esm.js +561 -770
- package/dist/xstate.umd.min.js +1 -1
- package/dist/xstate.umd.min.js.map +1 -1
- package/guards/dist/xstate-guards.cjs.js +12 -5
- package/guards/dist/xstate-guards.cjs.mjs +1 -2
- package/guards/dist/xstate-guards.development.cjs.js +14 -0
- package/guards/dist/xstate-guards.development.cjs.mjs +7 -0
- package/guards/dist/xstate-guards.development.esm.js +2 -0
- package/guards/dist/xstate-guards.esm.js +2 -2
- package/guards/dist/xstate-guards.umd.min.js +1 -1
- package/guards/dist/xstate-guards.umd.min.js.map +1 -1
- package/package.json +53 -1
- package/actions/dist/xstate-actions.cjs.dev.js +0 -32
- package/actions/dist/xstate-actions.cjs.prod.js +0 -32
- package/actions/dynamicAction.ts +0 -42
- package/actors/dist/xstate-actors.cjs.dev.js +0 -22
- package/actors/dist/xstate-actors.cjs.prod.js +0 -22
- package/dev/dist/xstate-dev.cjs.dev.js +0 -11
- package/dev/dist/xstate-dev.cjs.prod.js +0 -11
- package/dist/actions-b6357569.cjs.dev.js +0 -4437
- package/dist/actions-bd4a184d.cjs.prod.js +0 -4423
- package/dist/actions-de434a04.esm.js +0 -4348
- package/dist/declarations/actions/dynamicAction.d.ts +0 -5
- package/dist/declarations/src/Machine.d.ts +0 -4
- package/dist/declarations/src/Mailbox.d.ts +0 -12
- package/dist/declarations/src/actionTypes.d.ts +0 -16
- package/dist/declarations/src/actions/choose.d.ts +0 -3
- package/dist/declarations/src/actions/invoke.d.ts +0 -3
- package/dist/declarations/src/actions/pure.d.ts +0 -6
- package/dist/declarations/src/actions/stop.d.ts +0 -7
- package/dist/declarations/src/environment.d.ts +0 -1
- package/dist/declarations/src/mapState.d.ts +0 -3
- package/dist/declarations/src/memo.d.ts +0 -2
- package/dist/index-ebaab3c9.cjs.dev.js +0 -52
- package/dist/xstate.cjs.dev.js +0 -950
- package/dist/xstate.cjs.prod.js +0 -947
- package/guards/dist/xstate-guards.cjs.dev.js +0 -15
- package/guards/dist/xstate-guards.cjs.prod.js +0 -15
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import { EventObject,
|
|
2
|
-
|
|
1
|
+
import { EventObject, MachineContext, ActionArgs, ParameterizedObject } from "../types.js";
|
|
2
|
+
type ResolvableSendId<TContext extends MachineContext, TExpressionEvent extends EventObject, TParams extends ParameterizedObject['params'] | undefined, TEvent extends EventObject> = string | ((args: ActionArgs<TContext, TExpressionEvent, TEvent>, params: TParams) => string);
|
|
3
|
+
export interface CancelAction<TContext extends MachineContext, TExpressionEvent extends EventObject, TParams extends ParameterizedObject['params'] | undefined, TEvent extends EventObject> {
|
|
4
|
+
(args: ActionArgs<TContext, TExpressionEvent, TEvent>, params: TParams): void;
|
|
5
|
+
}
|
|
3
6
|
/**
|
|
4
7
|
* Cancels an in-flight `send(...)` action. A canceled sent action will not
|
|
5
8
|
* be executed, nor will its event be sent, unless it has already been sent
|
|
@@ -7,4 +10,5 @@ import { BaseDynamicActionObject, CancelActionObject, DynamicCancelActionObject
|
|
|
7
10
|
*
|
|
8
11
|
* @param sendId The `id` of the `send(...)` action to cancel.
|
|
9
12
|
*/
|
|
10
|
-
export declare function cancel<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject>(sendId:
|
|
13
|
+
export declare function cancel<TContext extends MachineContext, TExpressionEvent extends EventObject, TParams extends ParameterizedObject['params'] | undefined, TEvent extends EventObject>(sendId: ResolvableSendId<TContext, TExpressionEvent, TParams, TEvent>): CancelAction<TContext, TExpressionEvent, TParams, TEvent>;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Guard } from "../guards.js";
|
|
2
|
+
import { Action, ActionArgs, AnyActorRef, EventObject, MachineContext, ParameterizedObject, ProvidedActor } from "../types.js";
|
|
3
|
+
import { assign } from "./assign.js";
|
|
4
|
+
import { cancel } from "./cancel.js";
|
|
5
|
+
import { raise } from "./raise.js";
|
|
6
|
+
import { sendTo } from "./send.js";
|
|
7
|
+
import { spawnChild } from "./spawnChild.js";
|
|
8
|
+
import { stopChild } from "./stopChild.js";
|
|
9
|
+
interface ActionEnqueuer<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject, TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string> {
|
|
10
|
+
(action: Action<TContext, TExpressionEvent, TEvent, undefined, TActor, TAction, TGuard, TDelay>): void;
|
|
11
|
+
assign: (...args: Parameters<typeof assign<TContext, TExpressionEvent, undefined, TEvent, TActor>>) => void;
|
|
12
|
+
cancel: (...args: Parameters<typeof cancel<TContext, TExpressionEvent, undefined, TEvent>>) => void;
|
|
13
|
+
raise: (...args: Parameters<typeof raise<TContext, TExpressionEvent, TEvent, undefined, TDelay>>) => void;
|
|
14
|
+
sendTo: <TTargetActor extends AnyActorRef>(...args: Parameters<typeof sendTo<TContext, TExpressionEvent, undefined, TTargetActor, TEvent, TDelay>>) => void;
|
|
15
|
+
spawnChild: (...args: Parameters<typeof spawnChild<TContext, TExpressionEvent, undefined, TEvent, TActor>>) => void;
|
|
16
|
+
stopChild: (...args: Parameters<typeof stopChild<TContext, TExpressionEvent, undefined, TEvent>>) => void;
|
|
17
|
+
}
|
|
18
|
+
export interface EnqueueActionsAction<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject, TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string> {
|
|
19
|
+
(args: ActionArgs<TContext, TExpressionEvent, TEvent>, params: unknown): void;
|
|
20
|
+
_out_TEvent?: TEvent;
|
|
21
|
+
_out_TActor?: TActor;
|
|
22
|
+
_out_TAction?: TAction;
|
|
23
|
+
_out_TGuard?: TGuard;
|
|
24
|
+
_out_TDelay?: TDelay;
|
|
25
|
+
}
|
|
26
|
+
export declare function enqueueActions<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject = TExpressionEvent, TActor extends ProvidedActor = ProvidedActor, TAction extends ParameterizedObject = ParameterizedObject, TGuard extends ParameterizedObject = ParameterizedObject, TDelay extends string = string>(collect: ({ context, event, check, enqueue }: {
|
|
27
|
+
context: TContext;
|
|
28
|
+
event: TExpressionEvent;
|
|
29
|
+
check: (guard: Guard<TContext, TExpressionEvent, undefined, TGuard>) => boolean;
|
|
30
|
+
enqueue: ActionEnqueuer<TContext, TExpressionEvent, TEvent, TActor, TAction, TGuard, TDelay>;
|
|
31
|
+
}) => void): EnqueueActionsAction<TContext, TExpressionEvent, TEvent, TActor, TAction, TGuard, TDelay>;
|
|
32
|
+
export {};
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import { EventObject, LogExpr, MachineContext,
|
|
2
|
-
|
|
1
|
+
import { ActionArgs, EventObject, LogExpr, MachineContext, ParameterizedObject } from "../types.js";
|
|
2
|
+
type ResolvableLogValue<TContext extends MachineContext, TExpressionEvent extends EventObject, TParams extends ParameterizedObject['params'] | undefined, TEvent extends EventObject> = string | LogExpr<TContext, TExpressionEvent, TParams, TEvent>;
|
|
3
|
+
export interface LogAction<TContext extends MachineContext, TExpressionEvent extends EventObject, TParams extends ParameterizedObject['params'] | undefined, TEvent extends EventObject> {
|
|
4
|
+
(args: ActionArgs<TContext, TExpressionEvent, TEvent>, params: TParams): void;
|
|
5
|
+
}
|
|
3
6
|
/**
|
|
4
7
|
*
|
|
5
8
|
* @param expr The expression function to evaluate which will be logged.
|
|
@@ -8,4 +11,5 @@ import { BaseDynamicActionObject, DynamicLogAction } from '../index.ts';
|
|
|
8
11
|
* - `event` - the event that caused this action to be executed.
|
|
9
12
|
* @param label The label to give to the logged expression.
|
|
10
13
|
*/
|
|
11
|
-
export declare function log<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject
|
|
14
|
+
export declare function log<TContext extends MachineContext, TExpressionEvent extends EventObject, TParams extends ParameterizedObject['params'] | undefined, TEvent extends EventObject>(value?: ResolvableLogValue<TContext, TExpressionEvent, TParams, TEvent>, label?: string): LogAction<TContext, TExpressionEvent, TParams, TEvent>;
|
|
15
|
+
export {};
|
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
import { EventObject, MachineContext,
|
|
1
|
+
import { ActionArgs, EventObject, MachineContext, NoInfer, RaiseActionOptions, SendExpr, ParameterizedObject } from "../types.js";
|
|
2
|
+
export interface RaiseAction<TContext extends MachineContext, TExpressionEvent extends EventObject, TParams extends ParameterizedObject['params'] | undefined, TEvent extends EventObject, TDelay extends string> {
|
|
3
|
+
(args: ActionArgs<TContext, TExpressionEvent, TEvent>, params: TParams): void;
|
|
4
|
+
_out_TEvent?: TEvent;
|
|
5
|
+
_out_TDelay?: TDelay;
|
|
6
|
+
}
|
|
2
7
|
/**
|
|
3
8
|
* Raises an event. This places the event in the internal event queue, so that
|
|
4
9
|
* the event is immediately consumed by the machine in the current step.
|
|
5
10
|
*
|
|
6
11
|
* @param eventType The event to raise.
|
|
7
12
|
*/
|
|
8
|
-
export declare function raise<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject = TExpressionEvent>(eventOrExpr: NoInfer<TEvent> | SendExpr<TContext, TExpressionEvent, NoInfer<TEvent
|
|
13
|
+
export declare function raise<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject = TExpressionEvent, TParams extends ParameterizedObject['params'] | undefined = ParameterizedObject['params'] | undefined, TDelay extends string = string>(eventOrExpr: NoInfer<TEvent> | SendExpr<TContext, TExpressionEvent, TParams, NoInfer<TEvent>, TEvent>, options?: RaiseActionOptions<TContext, TExpressionEvent, TParams, NoInfer<TEvent>, NoInfer<TDelay>>): RaiseAction<TContext, TExpressionEvent, TParams, TEvent, TDelay>;
|
|
@@ -1,53 +1,31 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { ActionArgs, ActorRef, AnyActorRef, AnyEventObject, Cast, EventFrom, EventObject, InferEvent, MachineContext, SendExpr, SendToActionOptions, ParameterizedObject, NoInfer } from "../types.js";
|
|
2
|
+
export interface SendToAction<TContext extends MachineContext, TExpressionEvent extends EventObject, TParams extends ParameterizedObject['params'] | undefined, TEvent extends EventObject, TDelay extends string> {
|
|
3
|
+
(args: ActionArgs<TContext, TExpressionEvent, TEvent>, params: TParams): void;
|
|
4
|
+
_out_TDelay?: TDelay;
|
|
5
|
+
}
|
|
3
6
|
/**
|
|
4
|
-
* Sends an event
|
|
5
|
-
* send the event in the next step, after the current step is finished executing.
|
|
6
|
-
*
|
|
7
|
-
* @deprecated Use the `sendTo(...)` action creator instead.
|
|
7
|
+
* Sends an event to an actor.
|
|
8
8
|
*
|
|
9
|
-
* @param
|
|
10
|
-
* @param
|
|
9
|
+
* @param actor The `ActorRef` to send the event to.
|
|
10
|
+
* @param event The event to send, or an expression that evaluates to the event to send
|
|
11
|
+
* @param options Send action options
|
|
11
12
|
* - `id` - The unique send event identifier (used with `cancel()`).
|
|
12
13
|
* - `delay` - The number of milliseconds to delay the sending of the event.
|
|
13
|
-
* - `to` - The target of this event (by default, the machine the event was sent from).
|
|
14
14
|
*/
|
|
15
|
-
export declare function
|
|
15
|
+
export declare function sendTo<TContext extends MachineContext, TExpressionEvent extends EventObject, TParams extends ParameterizedObject['params'] | undefined, TTargetActor extends AnyActorRef, TEvent extends EventObject, TDelay extends string>(to: TTargetActor | string | ((args: ActionArgs<TContext, TExpressionEvent, TEvent>, params: TParams) => TTargetActor | string), eventOrExpr: EventFrom<TTargetActor> | SendExpr<TContext, TExpressionEvent, TParams, InferEvent<Cast<EventFrom<TTargetActor>, EventObject>>, TEvent>, options?: SendToActionOptions<TContext, TExpressionEvent, TParams, NoInfer<TEvent>, NoInfer<TDelay>>): SendToAction<TContext, TExpressionEvent, TParams, TEvent, TDelay>;
|
|
16
16
|
/**
|
|
17
17
|
* Sends an event to this machine's parent.
|
|
18
18
|
*
|
|
19
19
|
* @param event The event to send to the parent machine.
|
|
20
20
|
* @param options Options to pass into the send event.
|
|
21
21
|
*/
|
|
22
|
-
export declare function sendParent<TContext extends MachineContext,
|
|
23
|
-
|
|
24
|
-
* Sends an event back to the sender of the original event.
|
|
25
|
-
*
|
|
26
|
-
* @param event The event to send back to the sender
|
|
27
|
-
* @param options Options to pass into the send event
|
|
28
|
-
*/
|
|
29
|
-
export declare function respond<TContext extends MachineContext, TEvent extends EventObject, TSentEvent extends EventObject = AnyEventObject>(event: TEvent | SendExpr<TContext, TEvent, TSentEvent>, options?: SendActionOptions<TContext, TEvent>): BaseDynamicActionObject<TContext, TEvent, TEvent, SendActionObject<AnyEventObject>, SendActionParams<TContext, TEvent, EventObject>>;
|
|
22
|
+
export declare function sendParent<TContext extends MachineContext, TExpressionEvent extends EventObject, TParams extends ParameterizedObject['params'] | undefined, TSentEvent extends EventObject = AnyEventObject, TEvent extends EventObject = AnyEventObject, TDelay extends string = string>(event: TSentEvent | SendExpr<TContext, TExpressionEvent, TParams, TSentEvent, TEvent>, options?: SendToActionOptions<TContext, TExpressionEvent, TParams, TEvent, TDelay>): SendToAction<TContext, TExpressionEvent, TParams, TEvent, TDelay>;
|
|
23
|
+
type Target<TContext extends MachineContext, TExpressionEvent extends EventObject, TParams extends ParameterizedObject['params'] | undefined, TEvent extends EventObject> = string | ActorRef<any, any> | ((args: ActionArgs<TContext, TExpressionEvent, TEvent>, params: TParams) => string | ActorRef<any, any>);
|
|
30
24
|
/**
|
|
31
25
|
* Forwards (sends) an event to a specified service.
|
|
32
26
|
*
|
|
33
27
|
* @param target The target service to forward the event to.
|
|
34
28
|
* @param options Options to pass into the send action creator.
|
|
35
29
|
*/
|
|
36
|
-
export declare function forwardTo<TContext extends MachineContext, TEvent extends EventObject>(target:
|
|
37
|
-
|
|
38
|
-
* Escalates an error by sending it as an event to this machine's parent.
|
|
39
|
-
*
|
|
40
|
-
* @param errorData The error data to send, or the expression function that
|
|
41
|
-
* takes in the `context`, `event`, and `meta`, and returns the error data to send.
|
|
42
|
-
* @param options Options to pass into the send action creator.
|
|
43
|
-
*/
|
|
44
|
-
export declare function escalate<TContext extends MachineContext, TEvent extends EventObject, TErrorData = any>(errorData: TErrorData | ExprWithMeta<TContext, TEvent, TErrorData>, options?: SendActionParams<TContext, TEvent>): BaseDynamicActionObject<TContext, TEvent, TEvent, SendActionObject<AnyEventObject>, SendActionParams<TContext, TEvent, EventObject>>;
|
|
45
|
-
/**
|
|
46
|
-
* Sends an event to an actor.
|
|
47
|
-
*
|
|
48
|
-
* @param actor The `ActorRef` to send the event to.
|
|
49
|
-
* @param event The event to send, or an expression that evaluates to the event to send
|
|
50
|
-
* @param options Send action options
|
|
51
|
-
* @returns An XState send action object
|
|
52
|
-
*/
|
|
53
|
-
export declare function sendTo<TContext extends MachineContext, TEvent extends EventObject, TActor extends AnyActorRef>(actor: TActor | string | ExprWithMeta<TContext, TEvent, TActor | string>, event: EventFrom<TActor> | SendExpr<TContext, TEvent, InferEvent<Cast<EventFrom<TActor>, EventObject>>>, options?: SendActionOptions<TContext, TEvent>): BaseDynamicActionObject<TContext, TEvent, TEvent, SendActionObject<AnyEventObject>, SendActionParams<TContext, TEvent, EventObject>>;
|
|
30
|
+
export declare function forwardTo<TContext extends MachineContext, TExpressionEvent extends EventObject, TParams extends ParameterizedObject['params'] | undefined, TEvent extends EventObject, TDelay extends string>(target: Target<TContext, TExpressionEvent, TParams, TEvent>, options?: SendToActionOptions<TContext, TExpressionEvent, TParams, TEvent, TDelay>): SendToAction<TContext, TExpressionEvent, TParams, TEvent, TDelay>;
|
|
31
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { ActionArgs, EventObject, MachineContext, ParameterizedObject, AnyActorLogic, ProvidedActor, IsLiteralString, InputFrom, UnifiedArg, Mapper, RequiredActorOptions, ConditionalRequired, IsNotNever } from "../types.js";
|
|
2
|
+
type ResolvableActorId<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject, TId extends string | undefined> = TId | ((args: UnifiedArg<TContext, TExpressionEvent, TEvent>) => TId);
|
|
3
|
+
export interface SpawnAction<TContext extends MachineContext, TExpressionEvent extends EventObject, TParams extends ParameterizedObject['params'] | undefined, TEvent extends EventObject, TActor extends ProvidedActor> {
|
|
4
|
+
(args: ActionArgs<TContext, TExpressionEvent, TEvent>, params: TParams): void;
|
|
5
|
+
_out_TActor?: TActor;
|
|
6
|
+
}
|
|
7
|
+
interface SpawnActionOptions<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject, TActor extends ProvidedActor> {
|
|
8
|
+
id?: ResolvableActorId<TContext, TExpressionEvent, TEvent, TActor['id']>;
|
|
9
|
+
systemId?: string;
|
|
10
|
+
input?: Mapper<TContext, TEvent, InputFrom<TActor['logic']>, TEvent> | InputFrom<TActor['logic']>;
|
|
11
|
+
syncSnapshot?: boolean;
|
|
12
|
+
}
|
|
13
|
+
type DistributeActors<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject, TActor extends ProvidedActor> = TActor extends any ? ConditionalRequired<[
|
|
14
|
+
src: TActor['src'],
|
|
15
|
+
options?: SpawnActionOptions<TContext, TExpressionEvent, TEvent, TActor> & {
|
|
16
|
+
[K in RequiredActorOptions<TActor>]: unknown;
|
|
17
|
+
}
|
|
18
|
+
], IsNotNever<RequiredActorOptions<TActor>>> : never;
|
|
19
|
+
type SpawnArguments<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject, TActor extends ProvidedActor> = IsLiteralString<TActor['src']> extends true ? DistributeActors<TContext, TExpressionEvent, TEvent, TActor> : [
|
|
20
|
+
src: string | AnyActorLogic,
|
|
21
|
+
options?: {
|
|
22
|
+
id?: ResolvableActorId<TContext, TExpressionEvent, TEvent, string>;
|
|
23
|
+
systemId?: string;
|
|
24
|
+
input?: unknown;
|
|
25
|
+
syncSnapshot?: boolean;
|
|
26
|
+
}
|
|
27
|
+
];
|
|
28
|
+
export declare function spawnChild<TContext extends MachineContext, TExpressionEvent extends EventObject, TParams extends ParameterizedObject['params'] | undefined, TEvent extends EventObject, TActor extends ProvidedActor>(...[src, { id, systemId, input, syncSnapshot }]: SpawnArguments<TContext, TExpressionEvent, TEvent, TActor>): SpawnAction<TContext, TExpressionEvent, TParams, TEvent, TActor>;
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ActionArgs, ActorRef, EventObject, MachineContext, ParameterizedObject } from "../types.js";
|
|
2
|
+
type ResolvableActorRef<TContext extends MachineContext, TExpressionEvent extends EventObject, TParams extends ParameterizedObject['params'] | undefined, TEvent extends EventObject> = string | ActorRef<any, any> | ((args: ActionArgs<TContext, TExpressionEvent, TEvent>, params: TParams) => ActorRef<any, any> | string);
|
|
3
|
+
export interface StopAction<TContext extends MachineContext, TExpressionEvent extends EventObject, TParams extends ParameterizedObject['params'] | undefined, TEvent extends EventObject> {
|
|
4
|
+
(args: ActionArgs<TContext, TExpressionEvent, TEvent>, params: TParams): void;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Stops a child actor.
|
|
8
|
+
*
|
|
9
|
+
* @param actorRef The actor to stop.
|
|
10
|
+
*/
|
|
11
|
+
export declare function stopChild<TContext extends MachineContext, TExpressionEvent extends EventObject, TParams extends ParameterizedObject['params'] | undefined, TEvent extends EventObject>(actorRef: ResolvableActorRef<TContext, TExpressionEvent, TParams, TEvent>): StopAction<TContext, TExpressionEvent, TParams, TEvent>;
|
|
12
|
+
/**
|
|
13
|
+
* Stops a child actor.
|
|
14
|
+
*
|
|
15
|
+
* @deprecated Use `stopChild(...)` instead
|
|
16
|
+
*/
|
|
17
|
+
export declare const stop: typeof stopChild;
|
|
18
|
+
export {};
|
|
@@ -1,48 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
6
|
-
export {
|
|
7
|
-
export {
|
|
8
|
-
export {
|
|
9
|
-
export { choose } from './actions/choose.ts';
|
|
10
|
-
export { pure } from './actions/pure.ts';
|
|
11
|
-
export { actionTypes };
|
|
12
|
-
export declare const initEvent: SCXML.Event<{
|
|
13
|
-
type: ActionTypes;
|
|
14
|
-
}>;
|
|
15
|
-
export declare function resolveActionObject(actionObject: BaseActionObject, actionFunctionMap: ActionFunctionMap<any, any>): BaseActionObject;
|
|
16
|
-
export declare function toActionObject<TContext extends MachineContext, TEvent extends EventObject>(action: BaseActionObject | ActionFunction<TContext, TEvent> | string): BaseActionObject;
|
|
17
|
-
export declare const toActionObjects: <TContext extends MachineContext, TEvent extends EventObject>(action?: SingleOrArray<Action<TContext, TEvent>> | undefined) => BaseActionObject[];
|
|
18
|
-
/**
|
|
19
|
-
* Returns an event type that represents an implicit event that
|
|
20
|
-
* is sent after the specified `delay`.
|
|
21
|
-
*
|
|
22
|
-
* @param delayRef The delay in milliseconds
|
|
23
|
-
* @param id The state node ID where this event is handled
|
|
24
|
-
*/
|
|
25
|
-
export declare function after(delayRef: number | string, id?: string): string;
|
|
26
|
-
/**
|
|
27
|
-
* Returns an event that represents that a final state node
|
|
28
|
-
* has been reached in the parent state node.
|
|
29
|
-
*
|
|
30
|
-
* @param id The final state node's parent state node `id`
|
|
31
|
-
* @param output The data to pass into the event
|
|
32
|
-
*/
|
|
33
|
-
export declare function done(id: string, output?: any): DoneEventObject;
|
|
34
|
-
/**
|
|
35
|
-
* Returns an event that represents that an invoked service has terminated.
|
|
36
|
-
*
|
|
37
|
-
* An invoked service is terminated when it has reached a top-level final state node,
|
|
38
|
-
* but not when it is canceled.
|
|
39
|
-
*
|
|
40
|
-
* @param invokeId The invoked service ID
|
|
41
|
-
* @param output The data to pass into the event
|
|
42
|
-
*/
|
|
43
|
-
export declare function doneInvoke(invokeId: string, output?: any): DoneEvent;
|
|
44
|
-
export declare function error(id: string, data?: any): ErrorPlatformEvent & string;
|
|
45
|
-
export declare function createInitEvent(input: any): SCXML.Event<{
|
|
46
|
-
type: ActionTypes.Init;
|
|
47
|
-
input: any;
|
|
48
|
-
}>;
|
|
1
|
+
export { assign, type AssignAction, type AssignArgs } from "./actions/assign.js";
|
|
2
|
+
export { cancel, type CancelAction } from "./actions/cancel.js";
|
|
3
|
+
export { enqueueActions, type EnqueueActionsAction } from "./actions/enqueueActions.js";
|
|
4
|
+
export { log, type LogAction } from "./actions/log.js";
|
|
5
|
+
export { raise, type RaiseAction } from "./actions/raise.js";
|
|
6
|
+
export { forwardTo, sendParent, sendTo, type SendToAction } from "./actions/send.js";
|
|
7
|
+
export { spawnChild, type SpawnAction } from "./actions/spawnChild.js";
|
|
8
|
+
export { stop, stopChild, type StopAction } from "./actions/stopChild.js";
|
|
@@ -1,8 +1,91 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { ActorLogic, EventObject, AnyActorSystem, AnyEventObject, ActorSystem, ActorRefFrom, Snapshot, NonReducibleUnknown } from "../types.js";
|
|
2
|
+
export type CallbackSnapshot<TInput> = Snapshot<undefined> & {
|
|
3
|
+
input: TInput;
|
|
4
|
+
};
|
|
5
|
+
export type CallbackActorLogic<TEvent extends EventObject, TInput = NonReducibleUnknown> = ActorLogic<CallbackSnapshot<TInput>, TEvent, TInput, ActorSystem<any>>;
|
|
6
|
+
export type CallbackActorRef<TEvent extends EventObject, TInput = NonReducibleUnknown> = ActorRefFrom<CallbackActorLogic<TEvent, TInput>>;
|
|
7
|
+
export type Receiver<TEvent extends EventObject> = (listener: {
|
|
8
|
+
bivarianceHack(event: TEvent): void;
|
|
9
|
+
}['bivarianceHack']) => void;
|
|
10
|
+
export type InvokeCallback<TEvent extends EventObject = AnyEventObject, TSentEvent extends EventObject = AnyEventObject, TInput = NonReducibleUnknown> = ({ input, system, self, sendBack, receive }: {
|
|
11
|
+
/**
|
|
12
|
+
* Data that was provided to the callback actor
|
|
13
|
+
* @see {@link https://stately.ai/docs/input | Input docs}
|
|
14
|
+
*/
|
|
15
|
+
input: TInput;
|
|
16
|
+
/**
|
|
17
|
+
* The actor system to which the callback actor belongs
|
|
18
|
+
*/
|
|
19
|
+
system: AnyActorSystem;
|
|
20
|
+
/**
|
|
21
|
+
* The parent actor of the callback actor
|
|
22
|
+
*/
|
|
23
|
+
self: CallbackActorRef<TEvent>;
|
|
24
|
+
/**
|
|
25
|
+
* A function that can send events back to the parent actor
|
|
26
|
+
*/
|
|
27
|
+
sendBack: (event: TSentEvent) => void;
|
|
28
|
+
/**
|
|
29
|
+
* A function that can be called with a listener function argument;
|
|
30
|
+
* the listener is then called whenever events are received by the callback actor
|
|
31
|
+
*/
|
|
32
|
+
receive: Receiver<TEvent>;
|
|
33
|
+
}) => (() => void) | void;
|
|
34
|
+
/**
|
|
35
|
+
* An actor logic creator which returns callback logic as defined by a callback function.
|
|
36
|
+
*
|
|
37
|
+
* @remarks
|
|
38
|
+
* Useful for subscription-based or other free-form logic that can send events back to the parent actor.
|
|
39
|
+
*
|
|
40
|
+
* Actors created from callback logic (“callback actors”) can:
|
|
41
|
+
* - Receive events via the `receive` function
|
|
42
|
+
* - Send events to the parent actor via the `sendBack` function
|
|
43
|
+
*
|
|
44
|
+
* Callback actors are a bit different from other actors in that they:
|
|
45
|
+
* - Do not work with `onDone`
|
|
46
|
+
* - Do not produce a snapshot using `.getSnapshot()`
|
|
47
|
+
* - Do not emit values when used with `.subscribe()`
|
|
48
|
+
* - Can not be stopped with `.stop()`
|
|
49
|
+
*
|
|
50
|
+
* @param invokeCallback - The callback function used to describe the callback logic
|
|
51
|
+
* The callback function is passed an object with the following properties:
|
|
52
|
+
* - `receive` - A function that can send events back to the parent actor; the listener is then called whenever events are received by the callback actor
|
|
53
|
+
* - `sendBack` - A function that can send events back to the parent actor
|
|
54
|
+
* - `input` - Data that was provided to the callback actor
|
|
55
|
+
* - `self` - The parent actor of the callback actor
|
|
56
|
+
* - `system` - The actor system to which the callback actor belongs
|
|
57
|
+
* The callback function can (optionally) return a cleanup function, which is called when the actor is stopped.
|
|
58
|
+
* @see {@link InvokeCallback} for more information about the callback function and its object argument
|
|
59
|
+
* @see {@link https://stately.ai/docs/input | Input docs} for more information about how input is passed
|
|
60
|
+
|
|
61
|
+
* @returns Callback logic
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```typescript
|
|
65
|
+
* const callbackLogic = fromCallback(({ sendBack, receive }) => {
|
|
66
|
+
* let lockStatus = 'unlocked';
|
|
67
|
+
*
|
|
68
|
+
* const handler = (event) => {
|
|
69
|
+
* if (lockStatus === 'locked') {
|
|
70
|
+
* return;
|
|
71
|
+
* }
|
|
72
|
+
* sendBack(event);
|
|
73
|
+
* };
|
|
74
|
+
*
|
|
75
|
+
* receive((event) => {
|
|
76
|
+
* if (event.type === 'lock') {
|
|
77
|
+
* lockStatus = 'locked';
|
|
78
|
+
* } else if (event.type === 'unlock') {
|
|
79
|
+
* lockStatus = 'unlocked';
|
|
80
|
+
* }
|
|
81
|
+
* });
|
|
82
|
+
*
|
|
83
|
+
* document.body.addEventListener('click', handler);
|
|
84
|
+
*
|
|
85
|
+
* return () => {
|
|
86
|
+
* document.body.removeEventListener('click', handler);
|
|
87
|
+
* };
|
|
88
|
+
* });
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
export declare function fromCallback<TEvent extends EventObject, TInput = NonReducibleUnknown>(invokeCallback: InvokeCallback<TEvent, AnyEventObject, TInput>): CallbackActorLogic<TEvent, TInput>;
|
|
@@ -1,28 +1,6 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
6
|
-
export declare
|
|
7
|
-
export declare const stopSignalType = "xstate.stop";
|
|
8
|
-
export declare const startSignal: StartSignal;
|
|
9
|
-
export declare const stopSignal: StopSignal;
|
|
10
|
-
export interface StartSignal {
|
|
11
|
-
type: 'xstate.init';
|
|
12
|
-
}
|
|
13
|
-
export interface StopSignal {
|
|
14
|
-
type: 'xstate.stop';
|
|
15
|
-
}
|
|
16
|
-
export type LifecycleSignal = StartSignal | StopSignal;
|
|
17
|
-
export type LifecycleSignalType = typeof startSignalType | typeof stopSignalType;
|
|
18
|
-
/**
|
|
19
|
-
* An object that expresses the behavior of an actor in reaction to received events,
|
|
20
|
-
* as well as an optionally emitted stream of values.
|
|
21
|
-
*
|
|
22
|
-
* @template TReceived The received event
|
|
23
|
-
* @template TSnapshot The emitted value
|
|
24
|
-
*/
|
|
25
|
-
export declare function isSignal(eventType: string): eventType is LifecycleSignalType;
|
|
26
|
-
export declare function isActorRef(item: any): item is ActorRef<any>;
|
|
27
|
-
export declare function toActorRef<TEvent extends EventObject, TSnapshot = any, TActorRefLike extends BaseActorRef<TEvent> = BaseActorRef<TEvent>>(actorRefLike: TActorRefLike): ActorRef<TEvent, TSnapshot> & Omit<TActorRefLike, keyof ActorRef<any, any>>;
|
|
28
|
-
export declare function createEmptyActor(): ActorRef<AnyEventObject, undefined>;
|
|
1
|
+
import type { ActorRef, AnyEventObject, Snapshot } from "../types.js";
|
|
2
|
+
export { fromCallback, type CallbackActorLogic, type CallbackSnapshot } from "./callback.js";
|
|
3
|
+
export { fromEventObservable, fromObservable, type ObservableActorLogic, type ObservableSnapshot } from "./observable.js";
|
|
4
|
+
export { fromPromise, type PromiseActorLogic, type PromiseSnapshot } from "./promise.js";
|
|
5
|
+
export { fromTransition, type TransitionActorLogic, type TransitionSnapshot } from "./transition.js";
|
|
6
|
+
export declare function createEmptyActor(): ActorRef<Snapshot<undefined>, AnyEventObject>;
|
|
@@ -1,22 +1,105 @@
|
|
|
1
|
-
import { Subscribable,
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
import { Subscribable, ActorLogic, EventObject, Subscription, AnyActorSystem, ActorRefFrom, Snapshot, NonReducibleUnknown } from "../types.js";
|
|
2
|
+
export type ObservableSnapshot<TContext, TInput extends NonReducibleUnknown> = Snapshot<undefined> & {
|
|
3
|
+
context: TContext | undefined;
|
|
4
|
+
input: TInput | undefined;
|
|
5
|
+
_subscription: Subscription | undefined;
|
|
6
|
+
};
|
|
7
|
+
export type ObservableActorLogic<TContext, TInput extends NonReducibleUnknown> = ActorLogic<ObservableSnapshot<TContext, TInput>, {
|
|
8
|
+
type: string;
|
|
9
|
+
[k: string]: unknown;
|
|
10
|
+
}, TInput, AnyActorSystem>;
|
|
11
|
+
export type ObservableActorRef<TContext> = ActorRefFrom<ObservableActorLogic<TContext, any>>;
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
14
|
-
* that delivers event objects.
|
|
13
|
+
* Observable actor logic is described by an observable stream of values. Actors created from observable logic (“observable actors”) can:
|
|
15
14
|
*
|
|
15
|
+
* - Emit snapshots of the observable’s emitted value
|
|
16
16
|
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
17
|
+
* The observable’s emitted value is used as its observable actor’s `context`.
|
|
18
|
+
*
|
|
19
|
+
* Sending events to observable actors will have no effect.
|
|
20
|
+
*
|
|
21
|
+
* @param observableCreator A function that creates an observable. It receives one argument, an object with the following properties:
|
|
22
|
+
* - `input` - Data that was provided to the observable actor
|
|
23
|
+
* - `self` - The parent actor
|
|
24
|
+
* - `system` - The actor system to which the observable actor belongs
|
|
25
|
+
*
|
|
26
|
+
* It should return a {@link Subscribable}, which is compatible with an RxJS Observable, although RxJS is not required to create them.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* import { fromObservable, createActor } from 'xstate'
|
|
31
|
+
* import { interval } from 'rxjs';
|
|
32
|
+
*
|
|
33
|
+
* const logic = fromObservable((obj) => interval(1000));
|
|
34
|
+
*
|
|
35
|
+
* const actor = createActor(logic);
|
|
36
|
+
*
|
|
37
|
+
* actor.subscribe((snapshot) => {
|
|
38
|
+
* console.log(snapshot.context);
|
|
39
|
+
* });
|
|
40
|
+
*
|
|
41
|
+
* actor.start();
|
|
42
|
+
* // At every second:
|
|
43
|
+
* // Logs 0
|
|
44
|
+
* // Logs 1
|
|
45
|
+
* // Logs 2
|
|
46
|
+
* // ...
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* @see {@link https://rxjs.dev} for documentation on RxJS Observable and observable creators.
|
|
50
|
+
* @see {@link Subscribable} interface in XState, which is based on and compatible with RxJS Observable.
|
|
51
|
+
*/
|
|
52
|
+
export declare function fromObservable<TContext, TInput extends NonReducibleUnknown>(observableCreator: ({ input, system }: {
|
|
53
|
+
input: TInput;
|
|
54
|
+
system: AnyActorSystem;
|
|
55
|
+
self: ObservableActorRef<TContext>;
|
|
56
|
+
}) => Subscribable<TContext>): ObservableActorLogic<TContext, TInput>;
|
|
57
|
+
/**
|
|
58
|
+
* Creates event observable logic that listens to an observable that delivers event objects.
|
|
59
|
+
*
|
|
60
|
+
* Event observable actor logic is described by an observable stream of {@link https://stately.ai/docs/transitions#event-objects | event objects}. Actors created from event observable logic (“event observable actors”) can:
|
|
61
|
+
*
|
|
62
|
+
* - Implicitly send events to its parent actor
|
|
63
|
+
* - Emit snapshots of its emitted event objects
|
|
64
|
+
*
|
|
65
|
+
* Sending events to event observable actors will have no effect.
|
|
66
|
+
*
|
|
67
|
+
* @param lazyObservable A function that creates an observable that delivers event objects. It receives one argument, an object with the following properties:
|
|
68
|
+
*
|
|
69
|
+
* - `input` - Data that was provided to the event observable actor
|
|
70
|
+
* - `self` - The parent actor
|
|
71
|
+
* - `system` - The actor system to which the event observable actor belongs.
|
|
72
|
+
*
|
|
73
|
+
* It should return a {@link Subscribable}, which is compatible with an RxJS Observable, although RxJS is not required to create them.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```ts
|
|
77
|
+
* import {
|
|
78
|
+
* fromEventObservable,
|
|
79
|
+
* Subscribable,
|
|
80
|
+
* EventObject,
|
|
81
|
+
* createMachine,
|
|
82
|
+
* createActor
|
|
83
|
+
* } from 'xstate';
|
|
84
|
+
* import { fromEvent } from 'rxjs';
|
|
85
|
+
*
|
|
86
|
+
* const mouseClickLogic = fromEventObservable(() =>
|
|
87
|
+
* fromEvent(document.body, 'click') as Subscribable<EventObject>
|
|
88
|
+
* );
|
|
89
|
+
*
|
|
90
|
+
* const canvasMachine = createMachine({
|
|
91
|
+
* invoke: {
|
|
92
|
+
* // Will send mouse `click` events to the canvas actor
|
|
93
|
+
* src: mouseClickLogic,
|
|
94
|
+
* }
|
|
95
|
+
* });
|
|
96
|
+
*
|
|
97
|
+
* const canvasActor = createActor(canvasMachine);
|
|
98
|
+
* canvasActor.start();
|
|
99
|
+
* ```
|
|
19
100
|
*/
|
|
20
|
-
export declare function fromEventObservable<T extends EventObject>(lazyObservable: ({ input }: {
|
|
21
|
-
input:
|
|
22
|
-
|
|
101
|
+
export declare function fromEventObservable<T extends EventObject, TInput extends NonReducibleUnknown>(lazyObservable: ({ input, system }: {
|
|
102
|
+
input: TInput;
|
|
103
|
+
system: AnyActorSystem;
|
|
104
|
+
self: ObservableActorRef<T>;
|
|
105
|
+
}) => Subscribable<T>): ObservableActorLogic<T, TInput>;
|
|
@@ -1,11 +1,81 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import { XSTATE_STOP } from "../constants.js";
|
|
2
|
+
import { ActorLogic, ActorRefFrom, ActorSystem, AnyActorSystem, NonReducibleUnknown, Snapshot } from "../types.js";
|
|
3
|
+
export type PromiseSnapshot<TOutput, TInput> = Snapshot<TOutput> & {
|
|
4
|
+
input: TInput | undefined;
|
|
5
|
+
};
|
|
6
|
+
declare const XSTATE_PROMISE_RESOLVE = "xstate.promise.resolve";
|
|
7
|
+
declare const XSTATE_PROMISE_REJECT = "xstate.promise.reject";
|
|
8
|
+
export type PromiseActorEvents<T> = {
|
|
9
|
+
type: typeof XSTATE_PROMISE_RESOLVE;
|
|
10
|
+
data: T;
|
|
11
|
+
} | {
|
|
12
|
+
type: typeof XSTATE_PROMISE_REJECT;
|
|
13
|
+
data: any;
|
|
14
|
+
} | {
|
|
15
|
+
type: typeof XSTATE_STOP;
|
|
16
|
+
};
|
|
17
|
+
export type PromiseActorLogic<TOutput, TInput = unknown> = ActorLogic<PromiseSnapshot<TOutput, TInput>, {
|
|
10
18
|
type: string;
|
|
11
|
-
|
|
19
|
+
[k: string]: unknown;
|
|
20
|
+
}, TInput, // input
|
|
21
|
+
ActorSystem<any>>;
|
|
22
|
+
export type PromiseActorRef<TOutput> = ActorRefFrom<PromiseActorLogic<TOutput, unknown>>;
|
|
23
|
+
/**
|
|
24
|
+
* An actor logic creator which returns promise logic as defined by an async process that resolves or rejects after some time.
|
|
25
|
+
*
|
|
26
|
+
* Actors created from promise actor logic (“promise actors”) can:
|
|
27
|
+
* - Emit the resolved value of the promise
|
|
28
|
+
* - Output the resolved value of the promise
|
|
29
|
+
*
|
|
30
|
+
* Sending events to promise actors will have no effect.
|
|
31
|
+
*
|
|
32
|
+
* @param promiseCreator
|
|
33
|
+
* A function which returns a Promise, and accepts an object with the following properties:
|
|
34
|
+
* - `input` - Data that was provided to the promise actor
|
|
35
|
+
* - `self` - The parent actor of the promise actor
|
|
36
|
+
* - `system` - The actor system to which the promise actor belongs
|
|
37
|
+
* @see {@link https://stately.ai/docs/input | Input docs} for more information about how input is passed
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```ts
|
|
41
|
+
* const promiseLogic = fromPromise(async () => {
|
|
42
|
+
* const result = await fetch('https://example.com/...')
|
|
43
|
+
* .then((data) => data.json());
|
|
44
|
+
*
|
|
45
|
+
* return result;
|
|
46
|
+
* });
|
|
47
|
+
*
|
|
48
|
+
* const promiseActor = createActor(promiseLogic);
|
|
49
|
+
* promiseActor.subscribe((snapshot) => {
|
|
50
|
+
* console.log(snapshot);
|
|
51
|
+
* });
|
|
52
|
+
* promiseActor.start();
|
|
53
|
+
* // => {
|
|
54
|
+
* // output: undefined,
|
|
55
|
+
* // status: 'active'
|
|
56
|
+
* // ...
|
|
57
|
+
* // }
|
|
58
|
+
*
|
|
59
|
+
* // After promise resolves
|
|
60
|
+
* // => {
|
|
61
|
+
* // output: { ... },
|
|
62
|
+
* // status: 'done',
|
|
63
|
+
* // ...
|
|
64
|
+
* // }
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
export declare function fromPromise<TOutput, TInput = NonReducibleUnknown>(promiseCreator: ({ input, system }: {
|
|
68
|
+
/**
|
|
69
|
+
* Data that was provided to the promise actor
|
|
70
|
+
*/
|
|
71
|
+
input: TInput;
|
|
72
|
+
/**
|
|
73
|
+
* The actor system to which the promise actor belongs
|
|
74
|
+
*/
|
|
75
|
+
system: AnyActorSystem;
|
|
76
|
+
/**
|
|
77
|
+
* The parent actor of the promise actor
|
|
78
|
+
*/
|
|
79
|
+
self: PromiseActorRef<TOutput>;
|
|
80
|
+
}) => PromiseLike<TOutput>): PromiseActorLogic<TOutput, TInput>;
|
|
81
|
+
export {};
|