xstate 5.4.1 → 5.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/actions/dist/xstate-actions.cjs.js +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.map +1 -1
- package/dist/declarations/src/State.d.ts +30 -3
- package/dist/declarations/src/StateMachine.d.ts +3 -3
- package/dist/declarations/src/StateNode.d.ts +0 -4
- package/dist/declarations/src/actions/assign.d.ts +28 -1
- package/dist/declarations/src/actions/cancel.d.ts +23 -4
- package/dist/declarations/src/actions/enqueueActions.d.ts +20 -0
- package/dist/declarations/src/actions/send.d.ts +2 -2
- package/dist/declarations/src/createActor.d.ts +0 -1
- package/dist/declarations/src/createMachine.d.ts +40 -0
- package/dist/declarations/src/getNextSnapshot.d.ts +32 -0
- package/dist/declarations/src/guards.d.ts +86 -0
- package/dist/declarations/src/index.d.ts +1 -0
- package/dist/declarations/src/spawn.d.ts +2 -2
- package/dist/declarations/src/typegenTypes.d.ts +26 -1
- package/dist/declarations/src/types.d.ts +9 -29
- package/dist/{log-88b333eb.esm.js → log-22b3587f.esm.js} +67 -10
- package/dist/{log-11038f00.development.esm.js → log-285f62db.development.esm.js} +67 -10
- package/dist/{log-2580e864.cjs.js → log-742895c6.cjs.js} +67 -10
- package/dist/{log-18eb632d.development.cjs.js → log-da322832.development.cjs.js} +67 -10
- package/dist/{raise-3b380e4b.esm.js → raise-0e64ee6e.esm.js} +124 -13
- package/dist/{raise-3d3d6d51.development.cjs.js → raise-7af39710.development.cjs.js} +124 -13
- package/dist/{raise-057d17af.development.esm.js → raise-8da27ebb.development.esm.js} +124 -13
- package/dist/{raise-5c58eb8e.cjs.js → raise-ad8bb7c2.cjs.js} +124 -13
- package/dist/xstate.cjs.js +105 -4
- package/dist/xstate.cjs.mjs +1 -0
- package/dist/xstate.development.cjs.js +105 -4
- package/dist/xstate.development.cjs.mjs +1 -0
- package/dist/xstate.development.esm.js +107 -7
- package/dist/xstate.esm.js +107 -7
- package/dist/xstate.umd.min.js +1 -1
- package/dist/xstate.umd.min.js.map +1 -1
- package/guards/dist/xstate-guards.cjs.js +1 -1
- package/guards/dist/xstate-guards.development.cjs.js +1 -1
- package/guards/dist/xstate-guards.development.esm.js +1 -1
- package/guards/dist/xstate-guards.esm.js +1 -1
- package/guards/dist/xstate-guards.umd.min.js.map +1 -1
- package/package.json +1 -1
|
@@ -4,11 +4,30 @@ export interface CancelAction<TContext extends MachineContext, TExpressionEvent
|
|
|
4
4
|
(args: ActionArgs<TContext, TExpressionEvent, TEvent>, params: TParams): void;
|
|
5
5
|
}
|
|
6
6
|
/**
|
|
7
|
-
* Cancels
|
|
8
|
-
*
|
|
9
|
-
* (e.g., if `cancel(...)` is called after the `send(...)` action's `delay`).
|
|
7
|
+
* Cancels a delayed `sendTo(...)` action that is waiting to be executed. The canceled `sendTo(...)` action
|
|
8
|
+
* will not send its event or execute, unless the `delay` has already elapsed before `cancel(...)` is called.
|
|
10
9
|
*
|
|
11
|
-
* @param sendId The `id` of the `
|
|
10
|
+
* @param sendId The `id` of the `sendTo(...)` action to cancel.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
```ts
|
|
14
|
+
import { createMachine, sendTo, cancel } from 'xstate';
|
|
15
|
+
|
|
16
|
+
const machine = createMachine({
|
|
17
|
+
// ...
|
|
18
|
+
on: {
|
|
19
|
+
sendEvent: {
|
|
20
|
+
actions: sendTo('some-actor', { type: 'someEvent' }, {
|
|
21
|
+
id: 'some-id',
|
|
22
|
+
delay: 1000
|
|
23
|
+
})
|
|
24
|
+
},
|
|
25
|
+
cancelEvent: {
|
|
26
|
+
actions: cancel('some-id')
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
```
|
|
12
31
|
*/
|
|
13
32
|
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
33
|
export {};
|
|
@@ -28,5 +28,25 @@ interface CollectActionsArg<TContext extends MachineContext, TExpressionEvent ex
|
|
|
28
28
|
enqueue: ActionEnqueuer<TContext, TExpressionEvent, TEvent, TActor, TAction, TGuard, TDelay>;
|
|
29
29
|
}
|
|
30
30
|
type CollectActions<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject, TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string> = ({ context, event, check, enqueue, self }: CollectActionsArg<TContext, TExpressionEvent, TEvent, TActor, TAction, TGuard, TDelay>) => void;
|
|
31
|
+
/**
|
|
32
|
+
* Creates an action object that will execute actions that are queued by the `enqueue(action)` function.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
```ts
|
|
36
|
+
import { createMachine, enqueueActions } from 'xstate';
|
|
37
|
+
|
|
38
|
+
const machine = createMachine({
|
|
39
|
+
entry: enqueueActions(({ enqueue, check }) => {
|
|
40
|
+
enqueue.assign({ count: 0 });
|
|
41
|
+
|
|
42
|
+
if (check('someGuard')) {
|
|
43
|
+
enqueue.assign({ count: 1 });
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
enqueue('someAction');
|
|
47
|
+
})
|
|
48
|
+
})
|
|
49
|
+
```
|
|
50
|
+
*/
|
|
31
51
|
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: CollectActions<TContext, TExpressionEvent, TEvent, TActor, TAction, TGuard, TDelay>): EnqueueActionsAction<TContext, TExpressionEvent, TEvent, TActor, TAction, TGuard, TDelay>;
|
|
32
52
|
export {};
|
|
@@ -22,9 +22,9 @@ export declare function sendTo<TContext extends MachineContext, TExpressionEvent
|
|
|
22
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
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>);
|
|
24
24
|
/**
|
|
25
|
-
* Forwards (sends) an event to
|
|
25
|
+
* Forwards (sends) an event to the `target` actor.
|
|
26
26
|
*
|
|
27
|
-
* @param target The target
|
|
27
|
+
* @param target The target actor to forward the event to.
|
|
28
28
|
* @param options Options to pass into the send action creator.
|
|
29
29
|
*/
|
|
30
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>;
|
|
@@ -34,7 +34,6 @@ export declare class Actor<TLogic extends AnyActorLogic> implements ActorRef<Sna
|
|
|
34
34
|
private observers;
|
|
35
35
|
private logger;
|
|
36
36
|
_parent?: ActorRef<any, any>;
|
|
37
|
-
_syncSnapshot?: boolean;
|
|
38
37
|
ref: ActorRef<SnapshotFrom<TLogic>, EventFromLogic<TLogic>>;
|
|
39
38
|
private _actorScope;
|
|
40
39
|
private _systemId;
|
|
@@ -15,6 +15,46 @@ type FilterLeafValues<TLeafCandidate extends string, TNonLeaf extends {
|
|
|
15
15
|
type ToStateValue<TTestValue extends string | TestValue> = FilterLeafValues<GroupTestValues<TTestValue>['leafCandidates'], GroupTestValues<TTestValue>['nonLeaf']> | (IsNever<GroupTestValues<TTestValue>['nonLeaf']> extends false ? {
|
|
16
16
|
[K in keyof GroupTestValues<TTestValue>['nonLeaf']]: ToStateValue<NonNullable<GroupTestValues<TTestValue>['nonLeaf'][K]>>;
|
|
17
17
|
} : never);
|
|
18
|
+
/**
|
|
19
|
+
* Creates a state machine (statechart) with the given configuration.
|
|
20
|
+
*
|
|
21
|
+
* The state machine represents the pure logic of a state machine actor.
|
|
22
|
+
*
|
|
23
|
+
* @param config The state machine configuration.
|
|
24
|
+
* @param options DEPRECATED: use `setup({ ... })` or `machine.provide({ ... })` to provide machine implementations instead.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
```ts
|
|
28
|
+
import { createMachine } from 'xstate';
|
|
29
|
+
|
|
30
|
+
const lightMachine = createMachine({
|
|
31
|
+
id: 'light',
|
|
32
|
+
initial: 'green',
|
|
33
|
+
states: {
|
|
34
|
+
green: {
|
|
35
|
+
on: {
|
|
36
|
+
TIMER: { target: 'yellow' }
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
yellow: {
|
|
40
|
+
on: {
|
|
41
|
+
TIMER: { target: 'red' }
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
red: {
|
|
45
|
+
on: {
|
|
46
|
+
TIMER: { target: 'green' }
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
const lightActor = createActor(lightMachine);
|
|
53
|
+
lightActor.start();
|
|
54
|
+
|
|
55
|
+
lightActor.send({ type: 'TIMER' });
|
|
56
|
+
```
|
|
57
|
+
*/
|
|
18
58
|
export declare function createMachine<TContext extends MachineContext, TEvent extends AnyEventObject, // TODO: consider using a stricter `EventObject` here
|
|
19
59
|
TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string, TTag extends string, TInput, TOutput extends NonReducibleUnknown, TTypesMeta extends TypegenConstraint = TypegenDisabled>(config: MachineConfig<TContext, TEvent, TActor, TAction, TGuard, TDelay, TTag, TInput, TOutput, TTypesMeta>, implementations?: InternalMachineImplementations<TContext, ResolveTypegenMeta<TTypesMeta, TEvent, TActor, TAction, TGuard, TDelay, TTag>>): StateMachine<TContext, TEvent, Cast<ToChildren<TActor>, Record<string, AnyActorRef | undefined>>, TActor, TAction, TGuard, TDelay, 'matchesStates' extends keyof TTypesMeta ? ToStateValue<Cast<TTypesMeta['matchesStates'], TestValue>> : StateValue, Prop<ResolveTypegenMeta<TTypesMeta, TEvent, TActor, TAction, TGuard, TDelay, TTag>['resolved'], 'tags'> & string, TInput, TOutput, ResolveTypegenMeta<TTypesMeta, TEvent, TActor, TAction, TGuard, TDelay, TTag>>;
|
|
20
60
|
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { AnyActorLogic, EventFromLogic, InputFrom, SnapshotFrom } from "./types.js";
|
|
2
|
+
export declare function getInitialSnapshot<T extends AnyActorLogic>(actorLogic: T, ...[input]: undefined extends InputFrom<T> ? [input?: InputFrom<T>] : [input: InputFrom<T>]): SnapshotFrom<T>;
|
|
3
|
+
/**
|
|
4
|
+
* Determines the next snapshot for the given `actorLogic` based on
|
|
5
|
+
* the given `snapshot` and `event`.
|
|
6
|
+
*
|
|
7
|
+
* If the `snapshot` is `undefined`, the initial snapshot of the
|
|
8
|
+
* `actorLogic` is used.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
```ts
|
|
12
|
+
import { getNextSnapshot } from 'xstate';
|
|
13
|
+
import { trafficLightMachine } from './trafficLightMachine.ts';
|
|
14
|
+
|
|
15
|
+
const nextSnapshot = getNextSnapshot(
|
|
16
|
+
trafficLightMachine, // actor logic
|
|
17
|
+
undefined, // snapshot (or initial state if undefined)
|
|
18
|
+
{ type: 'TIMER' }); // event object
|
|
19
|
+
|
|
20
|
+
console.log(nextSnapshot.value);
|
|
21
|
+
// => 'yellow'
|
|
22
|
+
|
|
23
|
+
const nextSnapshot2 = getNextSnapshot(
|
|
24
|
+
trafficLightMachine, // actor logic
|
|
25
|
+
nextSnapshot, // snapshot
|
|
26
|
+
{ type: 'TIMER' }); // event object
|
|
27
|
+
|
|
28
|
+
console.log(nextSnapshot2.value);
|
|
29
|
+
// =>'red'
|
|
30
|
+
```
|
|
31
|
+
*/
|
|
32
|
+
export declare function getNextSnapshot<T extends AnyActorLogic>(actorLogic: T, snapshot: SnapshotFrom<T>, event: EventFromLogic<T>): SnapshotFrom<T>;
|
|
@@ -26,12 +26,98 @@ export type UnknownGuard = UnknownReferencedGuard | UnknownInlineGuard;
|
|
|
26
26
|
type UnknownReferencedGuard = Guard<MachineContext, EventObject, ParameterizedObject['params'], ParameterizedObject>;
|
|
27
27
|
type UnknownInlineGuard = Guard<MachineContext, EventObject, undefined, ParameterizedObject>;
|
|
28
28
|
export declare function stateIn<TContext extends MachineContext, TExpressionEvent extends EventObject, TParams extends ParameterizedObject['params'] | undefined>(stateValue: StateValue): GuardPredicate<TContext, TExpressionEvent, TParams, any>;
|
|
29
|
+
/**
|
|
30
|
+
* Higher-order guard that evaluates to `true` if the `guard` passed to it evaluates to `false`.
|
|
31
|
+
*
|
|
32
|
+
* @category Guards
|
|
33
|
+
* @example
|
|
34
|
+
```ts
|
|
35
|
+
import { setup, not } from 'xstate';
|
|
36
|
+
|
|
37
|
+
const machine = setup({
|
|
38
|
+
guards: {
|
|
39
|
+
someNamedGuard: () => false
|
|
40
|
+
}
|
|
41
|
+
}).createMachine({
|
|
42
|
+
on: {
|
|
43
|
+
someEvent: {
|
|
44
|
+
guard: not('someNamedGuard'),
|
|
45
|
+
actions: () => {
|
|
46
|
+
// will be executed if guard in `not(...)`
|
|
47
|
+
// evaluates to `false`
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
```
|
|
53
|
+
* @returns A guard
|
|
54
|
+
*/
|
|
29
55
|
export declare function not<TContext extends MachineContext, TExpressionEvent extends EventObject, TArg>(guard: SingleGuardArg<TContext, TExpressionEvent, unknown, TArg>): GuardPredicate<TContext, TExpressionEvent, unknown, NormalizeGuardArg<NoInfer<TArg>>>;
|
|
56
|
+
/**
|
|
57
|
+
* Higher-order guard that evaluates to `true` if all `guards` passed to it
|
|
58
|
+
* evaluate to `true`.
|
|
59
|
+
*
|
|
60
|
+
* @category Guards
|
|
61
|
+
* @example
|
|
62
|
+
```ts
|
|
63
|
+
import { setup, and } from 'xstate';
|
|
64
|
+
|
|
65
|
+
const machine = setup({
|
|
66
|
+
guards: {
|
|
67
|
+
someNamedGuard: () => true
|
|
68
|
+
}
|
|
69
|
+
}).createMachine({
|
|
70
|
+
on: {
|
|
71
|
+
someEvent: {
|
|
72
|
+
guard: and([
|
|
73
|
+
({ context }) => context.value > 0,
|
|
74
|
+
'someNamedGuard'
|
|
75
|
+
]),
|
|
76
|
+
actions: () => {
|
|
77
|
+
// will be executed if all guards in `and(...)`
|
|
78
|
+
// evaluate to true
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
```
|
|
84
|
+
* @returns A guard action object
|
|
85
|
+
*/
|
|
30
86
|
export declare function and<TContext extends MachineContext, TExpressionEvent extends EventObject, TArg extends unknown[]>(guards: readonly [
|
|
31
87
|
...{
|
|
32
88
|
[K in keyof TArg]: SingleGuardArg<TContext, TExpressionEvent, unknown, TArg[K]>;
|
|
33
89
|
}
|
|
34
90
|
]): GuardPredicate<TContext, TExpressionEvent, unknown, NormalizeGuardArgArray<NoInfer<TArg>>>;
|
|
91
|
+
/**
|
|
92
|
+
* Higher-order guard that evaluates to `true` if any of the `guards` passed to it
|
|
93
|
+
* evaluate to `true`.
|
|
94
|
+
*
|
|
95
|
+
* @category Guards
|
|
96
|
+
* @example
|
|
97
|
+
```ts
|
|
98
|
+
import { setup, or } from 'xstate';
|
|
99
|
+
|
|
100
|
+
const machine = setup({
|
|
101
|
+
guards: {
|
|
102
|
+
someNamedGuard: () => true
|
|
103
|
+
}
|
|
104
|
+
}).createMachine({
|
|
105
|
+
on: {
|
|
106
|
+
someEvent: {
|
|
107
|
+
guard: or([
|
|
108
|
+
({ context }) => context.value > 0,
|
|
109
|
+
'someNamedGuard'
|
|
110
|
+
]),
|
|
111
|
+
actions: () => {
|
|
112
|
+
// will be executed if any of the guards in `or(...)`
|
|
113
|
+
// evaluate to true
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
```
|
|
119
|
+
* @returns A guard action object
|
|
120
|
+
*/
|
|
35
121
|
export declare function or<TContext extends MachineContext, TExpressionEvent extends EventObject, TArg extends unknown[]>(guards: readonly [
|
|
36
122
|
...{
|
|
37
123
|
[K in keyof TArg]: SingleGuardArg<TContext, TExpressionEvent, unknown, TArg[K]>;
|
|
@@ -9,6 +9,7 @@ export * from "./typegenTypes.js";
|
|
|
9
9
|
export * from "./types.js";
|
|
10
10
|
export { waitFor } from "./waitFor.js";
|
|
11
11
|
import { createMachine } from "./createMachine.js";
|
|
12
|
+
export { getNextSnapshot } from "./getNextSnapshot.js";
|
|
12
13
|
import { Actor, createActor, interpret, Interpreter } from "./createActor.js";
|
|
13
14
|
import { StateNode } from "./StateNode.js";
|
|
14
15
|
export { and, not, or, stateIn } from "./guards.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ActorRefFrom,
|
|
1
|
+
import { ActorRefFrom, AnyActorLogic, AnyActorRef, AnyActorScope, AnyEventObject, AnyMachineSnapshot, ConditionalRequired, InputFrom, IsLiteralString, IsNotNever, ProvidedActor, RequiredActorOptions } from "./types.js";
|
|
2
2
|
type SpawnOptions<TActor extends ProvidedActor, TSrc extends TActor['src']> = TActor extends {
|
|
3
3
|
src: TSrc;
|
|
4
4
|
} ? ConditionalRequired<[
|
|
@@ -17,7 +17,7 @@ type GetConcreteLogic<TActor extends ProvidedActor, TSrc extends TActor['src']>
|
|
|
17
17
|
export type Spawner<TActor extends ProvidedActor> = IsLiteralString<TActor['src']> extends true ? <TSrc extends TActor['src']>(logic: TSrc, ...[options]: SpawnOptions<TActor, TSrc>) => ActorRefFrom<GetConcreteLogic<TActor, TSrc>> : <TLogic extends AnyActorLogic | string>(src: TLogic, options?: {
|
|
18
18
|
id?: string;
|
|
19
19
|
systemId?: string;
|
|
20
|
-
input?: unknown
|
|
20
|
+
input?: TLogic extends string ? unknown : InputFrom<TLogic>;
|
|
21
21
|
syncSnapshot?: boolean;
|
|
22
22
|
}) => TLogic extends string ? AnyActorRef : ActorRefFrom<TLogic>;
|
|
23
23
|
export declare function createSpawner(actorScope: AnyActorScope, { machine, context }: AnyMachineSnapshot, event: AnyEventObject, spawnedChildren: Record<string, AnyActorRef>): Spawner<any>;
|
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
import { EventObject, IndexByType, IsNever, Prop, ParameterizedObject, ProvidedActor, OutputFrom, AnyActorLogic, IndexByProp } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* @deprecated
|
|
4
|
+
*/
|
|
2
5
|
export interface TypegenDisabled {
|
|
3
6
|
'@@xstate/typegen': false;
|
|
4
7
|
}
|
|
8
|
+
/**
|
|
9
|
+
* @deprecated
|
|
10
|
+
*/
|
|
5
11
|
export interface TypegenEnabled {
|
|
6
12
|
'@@xstate/typegen': true;
|
|
7
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* @deprecated
|
|
16
|
+
*/
|
|
8
17
|
export interface TypegenMeta extends TypegenEnabled {
|
|
9
18
|
/**
|
|
10
19
|
* Allows you to specify all the results of state.matches
|
|
@@ -77,6 +86,9 @@ export interface TypegenMeta extends TypegenEnabled {
|
|
|
77
86
|
*/
|
|
78
87
|
eventsCausingActors: Record<string, string>;
|
|
79
88
|
}
|
|
89
|
+
/**
|
|
90
|
+
* @deprecated
|
|
91
|
+
*/
|
|
80
92
|
export interface ResolvedTypegenMeta extends TypegenMeta {
|
|
81
93
|
resolved: TypegenMeta & {
|
|
82
94
|
indexedActors: Record<string, ProvidedActor>;
|
|
@@ -86,11 +98,21 @@ export interface ResolvedTypegenMeta extends TypegenMeta {
|
|
|
86
98
|
indexedDelays: Record<string, ParameterizedObject>;
|
|
87
99
|
};
|
|
88
100
|
}
|
|
101
|
+
/**
|
|
102
|
+
* @deprecated
|
|
103
|
+
*/
|
|
89
104
|
export type TypegenConstraint = TypegenEnabled | TypegenDisabled;
|
|
90
105
|
/**
|
|
91
106
|
* @deprecated Always resolves to `true`
|
|
92
107
|
*/
|
|
93
|
-
export type AreAllImplementationsAssumedToBeProvided<_TResolvedTypesMeta, _TMissingImplementations> = true;
|
|
108
|
+
export type AreAllImplementationsAssumedToBeProvided<_TResolvedTypesMeta, _TMissingImplementations = never> = true;
|
|
109
|
+
/**
|
|
110
|
+
* @deprecated Always resolves to `never`
|
|
111
|
+
*/
|
|
112
|
+
export type MissingImplementationsError<_TResolvedTypesMeta, _TMissingImplementations = never> = never;
|
|
113
|
+
/**
|
|
114
|
+
* @deprecated
|
|
115
|
+
*/
|
|
94
116
|
interface AllImplementationsProvided {
|
|
95
117
|
missingImplementations: {
|
|
96
118
|
actions: never;
|
|
@@ -114,6 +136,9 @@ type IndexParameterizedImplementation<TParameterizedImplementation extends Param
|
|
|
114
136
|
type WrapIntoParameterizedObject<T extends string> = T extends any ? {
|
|
115
137
|
type: T;
|
|
116
138
|
} : never;
|
|
139
|
+
/**
|
|
140
|
+
* @deprecated
|
|
141
|
+
*/
|
|
117
142
|
export interface ResolveTypegenMeta<TTypesMeta extends TypegenConstraint, TEvent extends EventObject, TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string, TTag extends string> {
|
|
118
143
|
'@@xstate/typegen': TTypesMeta['@@xstate/typegen'];
|
|
119
144
|
resolved: {
|
|
@@ -3,7 +3,7 @@ import type { StateMachine } from "./StateMachine.js";
|
|
|
3
3
|
import type { StateNode } from "./StateNode.js";
|
|
4
4
|
import { AssignArgs } from "./actions/assign.js";
|
|
5
5
|
import { PromiseActorLogic } from "./actors/promise.js";
|
|
6
|
-
import { Guard,
|
|
6
|
+
import { Guard, UnknownGuard } from "./guards.js";
|
|
7
7
|
import type { Actor } from "./createActor.js";
|
|
8
8
|
import { Spawner } from "./spawn.js";
|
|
9
9
|
import { AnyActorSystem, InspectionEvent, Clock } from './system.js';
|
|
@@ -383,22 +383,8 @@ export type ActionFunctionMap<TContext extends MachineContext, TEvent extends Ev
|
|
|
383
383
|
type: K;
|
|
384
384
|
} ? TAction : never>, TActor, TAction, TGuard, TDelay>;
|
|
385
385
|
};
|
|
386
|
-
type GuardMap<TContext extends MachineContext, TEvent extends EventObject, TGuard extends ParameterizedObject> = {
|
|
387
|
-
[K in TGuard['type']]?: GuardPredicate<TContext, TEvent, GetParameterizedParams<TGuard extends {
|
|
388
|
-
type: K;
|
|
389
|
-
} ? TGuard : never>, TGuard>;
|
|
390
|
-
};
|
|
391
386
|
export type DelayFunctionMap<TContext extends MachineContext, TEvent extends EventObject, TAction extends ParameterizedObject> = Record<string, DelayConfig<TContext, TEvent, TAction['params'], TEvent>>;
|
|
392
387
|
export type DelayConfig<TContext extends MachineContext, TExpressionEvent extends EventObject, TParams extends ParameterizedObject['params'] | undefined, TEvent extends EventObject> = number | DelayExpr<TContext, TExpressionEvent, TParams, TEvent>;
|
|
393
|
-
export interface MachineImplementationsSimplified<TContext extends MachineContext, TEvent extends EventObject, TActor extends ProvidedActor = ProvidedActor, TAction extends ParameterizedObject = ParameterizedObject, TGuard extends ParameterizedObject = ParameterizedObject> {
|
|
394
|
-
guards: GuardMap<TContext, TEvent, TGuard>;
|
|
395
|
-
actions: ActionFunctionMap<TContext, TEvent, TActor, TAction>;
|
|
396
|
-
actors: Record<string, AnyActorLogic | {
|
|
397
|
-
src: AnyActorLogic;
|
|
398
|
-
input: Mapper<TContext, TEvent, unknown, TEvent> | NonReducibleUnknown;
|
|
399
|
-
}>;
|
|
400
|
-
delays: DelayFunctionMap<TContext, TEvent, TAction>;
|
|
401
|
-
}
|
|
402
388
|
type MaybeNarrowedEvent<TIndexedEvents, TCausingLookup, K> = Cast<Prop<TIndexedEvents, K extends keyof TCausingLookup ? TCausingLookup[K] : TIndexedEvents[keyof TIndexedEvents]>, EventObject>;
|
|
403
389
|
type MachineImplementationsActions<TContext extends MachineContext, TResolvedTypesMeta, TEventsCausingActions = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'eventsCausingActions'>, TIndexedEvents = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'indexedEvents'>, TIndexedActors = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'indexedActors'>, TIndexedActions = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'indexedActions'>, TIndexedGuards = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'indexedGuards'>, TIndexedDelays = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'indexedDelays'>> = {
|
|
404
390
|
[K in keyof TIndexedActions]?: ActionFunction<TContext, MaybeNarrowedEvent<TIndexedEvents, TEventsCausingActions, K>, Cast<Prop<TIndexedEvents, keyof TIndexedEvents>, EventObject>, GetParameterizedParams<Cast<TIndexedActions[K], ParameterizedObject>>, Cast<Prop<TIndexedActors, keyof TIndexedActors>, ProvidedActor>, Cast<Prop<TIndexedActions, keyof TIndexedActions>, ParameterizedObject>, Cast<Prop<TIndexedGuards, keyof TIndexedGuards>, ParameterizedObject>, Cast<Prop<TIndexedDelays, keyof TIndexedDelays>, ParameterizedObject>['type']>;
|
|
@@ -588,21 +574,20 @@ export interface ActorOptions<TLogic extends AnyActorLogic> {
|
|
|
588
574
|
*/
|
|
589
575
|
clock?: Clock;
|
|
590
576
|
/**
|
|
591
|
-
* Specifies the logger to be used for log(...) actions. Defaults to the native console.log method.
|
|
577
|
+
* Specifies the logger to be used for `log(...)` actions. Defaults to the native `console.log(...)` method.
|
|
592
578
|
*/
|
|
593
579
|
logger?: (...args: any[]) => void;
|
|
580
|
+
parent?: ActorRef<any, any>;
|
|
594
581
|
/**
|
|
595
582
|
* The custom `id` for referencing this service.
|
|
596
583
|
*/
|
|
597
584
|
id?: string;
|
|
598
585
|
/**
|
|
599
|
-
*
|
|
600
|
-
*
|
|
601
|
-
* Default: `false`
|
|
586
|
+
* @deprecated Use `inspect` instead.
|
|
602
587
|
*/
|
|
603
|
-
devTools?:
|
|
588
|
+
devTools?: never;
|
|
604
589
|
/**
|
|
605
|
-
* The system ID to register this actor under
|
|
590
|
+
* The system ID to register this actor under.
|
|
606
591
|
*/
|
|
607
592
|
systemId?: string;
|
|
608
593
|
/**
|
|
@@ -628,7 +613,7 @@ export interface ActorOptions<TLogic extends AnyActorLogic> {
|
|
|
628
613
|
*/
|
|
629
614
|
state?: Snapshot<unknown>;
|
|
630
615
|
/**
|
|
631
|
-
* The source
|
|
616
|
+
* The source actor logic.
|
|
632
617
|
*/
|
|
633
618
|
src?: string | AnyActorLogic;
|
|
634
619
|
/**
|
|
@@ -720,17 +705,12 @@ export type Observer<T> = {
|
|
|
720
705
|
export interface Subscription {
|
|
721
706
|
unsubscribe(): void;
|
|
722
707
|
}
|
|
723
|
-
export interface InteropObservable<T> {
|
|
724
|
-
[Symbol.observable]: () => InteropSubscribable<T>;
|
|
725
|
-
}
|
|
726
|
-
export interface InteropSubscribable<T> {
|
|
727
|
-
subscribe(observer: Observer<T>): Subscription;
|
|
728
|
-
}
|
|
729
708
|
export interface Subscribable<T> extends InteropSubscribable<T> {
|
|
730
709
|
subscribe(observer: Observer<T>): Subscription;
|
|
731
710
|
subscribe(next: (value: T) => void, error?: (error: any) => void, complete?: () => void): Subscription;
|
|
732
711
|
}
|
|
733
|
-
|
|
712
|
+
type EventDescriptorMatches<TEventType extends string, TNormalizedDescriptor> = TEventType extends TNormalizedDescriptor ? true : false;
|
|
713
|
+
export type ExtractEvent<TEvent extends EventObject, TDescriptor extends EventDescriptor<TEvent>> = string extends TEvent['type'] ? TEvent : NormalizeDescriptor<TDescriptor> extends infer TNormalizedDescriptor ? TEvent extends any ? true extends EventDescriptorMatches<TEvent['type'], TNormalizedDescriptor> ? TEvent : never : never : never;
|
|
734
714
|
export interface BaseActorRef<TEvent extends EventObject> {
|
|
735
715
|
send: (event: TEvent) => void;
|
|
736
716
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { R as ProcessingStatus, y as resolveReferencedActor, z as createActor, T as cloneMachineSnapshot, U as XSTATE_ERROR, V as createErrorActorEvent, e as evaluateGuard, L as cancel, M as raise, O as spawnChild, Q as stopChild } from './raise-
|
|
1
|
+
import { R as ProcessingStatus, y as resolveReferencedActor, z as createActor, T as cloneMachineSnapshot, U as XSTATE_ERROR, V as createErrorActorEvent, e as evaluateGuard, L as cancel, M as raise, O as spawnChild, Q as stopChild } from './raise-0e64ee6e.esm.js';
|
|
2
2
|
|
|
3
3
|
// it's likely-ish that `(TActor & { src: TSrc })['logic']` would be faster
|
|
4
4
|
// but it's only possible to do it since https://github.com/microsoft/TypeScript/pull/53098 (TS 5.1)
|
|
@@ -67,8 +67,8 @@ function resolveAssign(actorScope, snapshot, actionArgs, actionParams, {
|
|
|
67
67
|
context: snapshot.context,
|
|
68
68
|
event: actionArgs.event,
|
|
69
69
|
spawn: createSpawner(actorScope, snapshot, actionArgs.event, spawnedChildren),
|
|
70
|
-
self: actorScope
|
|
71
|
-
system: actorScope
|
|
70
|
+
self: actorScope.self,
|
|
71
|
+
system: actorScope.system
|
|
72
72
|
};
|
|
73
73
|
let partialUpdate = {};
|
|
74
74
|
if (typeof assignment === 'function') {
|
|
@@ -91,7 +91,34 @@ function resolveAssign(actorScope, snapshot, actionArgs, actionParams, {
|
|
|
91
91
|
/**
|
|
92
92
|
* Updates the current context of the machine.
|
|
93
93
|
*
|
|
94
|
-
* @param assignment An object that represents the partial context to update
|
|
94
|
+
* @param assignment An object that represents the partial context to update, or a
|
|
95
|
+
* function that returns an object that represents the partial context to update.
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
```ts
|
|
99
|
+
import { createMachine, assign } from 'xstate';
|
|
100
|
+
|
|
101
|
+
const countMachine = createMachine({
|
|
102
|
+
context: {
|
|
103
|
+
count: 0,
|
|
104
|
+
message: ''
|
|
105
|
+
},
|
|
106
|
+
on: {
|
|
107
|
+
inc: {
|
|
108
|
+
actions: assign({
|
|
109
|
+
count: ({ context }) => context.count + 1
|
|
110
|
+
})
|
|
111
|
+
},
|
|
112
|
+
updateMessage: {
|
|
113
|
+
actions: assign(({ context, event }) => {
|
|
114
|
+
return {
|
|
115
|
+
message: event.message.trim()
|
|
116
|
+
}
|
|
117
|
+
})
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
```
|
|
95
122
|
*/
|
|
96
123
|
function assign(assignment) {
|
|
97
124
|
function assign(args, params) {
|
|
@@ -138,7 +165,9 @@ function assign(assignment) {
|
|
|
138
165
|
/** @deprecated use `AnyMachineSnapshot` instead */
|
|
139
166
|
|
|
140
167
|
// TODO: possibly refactor this somehow, use even a simpler type, and maybe even make `machine.options` private or something
|
|
141
|
-
|
|
168
|
+
/**
|
|
169
|
+
* @internal
|
|
170
|
+
*/
|
|
142
171
|
let SpecialTargets = /*#__PURE__*/function (SpecialTargets) {
|
|
143
172
|
SpecialTargets["Parent"] = "#_parent";
|
|
144
173
|
SpecialTargets["Internal"] = "#_internal";
|
|
@@ -151,6 +180,14 @@ let SpecialTargets = /*#__PURE__*/function (SpecialTargets) {
|
|
|
151
180
|
|
|
152
181
|
// Based on RxJS types
|
|
153
182
|
|
|
183
|
+
/**
|
|
184
|
+
* @internal
|
|
185
|
+
*/
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* @internal
|
|
189
|
+
*/
|
|
190
|
+
|
|
154
191
|
/**
|
|
155
192
|
* @deprecated Use `Actor<T>` instead.
|
|
156
193
|
*/
|
|
@@ -188,9 +225,9 @@ function resolveSendTo(actorScope, snapshot, args, actionParams, {
|
|
|
188
225
|
let targetActorRef;
|
|
189
226
|
if (typeof resolvedTarget === 'string') {
|
|
190
227
|
if (resolvedTarget === SpecialTargets.Parent) {
|
|
191
|
-
targetActorRef = actorScope
|
|
228
|
+
targetActorRef = actorScope.self._parent;
|
|
192
229
|
} else if (resolvedTarget === SpecialTargets.Internal) {
|
|
193
|
-
targetActorRef = actorScope
|
|
230
|
+
targetActorRef = actorScope.self;
|
|
194
231
|
} else if (resolvedTarget.startsWith('#_')) {
|
|
195
232
|
// SCXML compatibility: https://www.w3.org/TR/scxml/#SCXMLEventProcessor
|
|
196
233
|
// #_invokeid. If the target is the special term '#_invokeid', where invokeid is the invokeid of an SCXML session that the sending session has created by <invoke>, the Processor must add the event to the external queue of that session.
|
|
@@ -202,7 +239,7 @@ function resolveSendTo(actorScope, snapshot, args, actionParams, {
|
|
|
202
239
|
throw new Error(`Unable to send event to actor '${resolvedTarget}' from machine '${snapshot.machine.id}'.`);
|
|
203
240
|
}
|
|
204
241
|
} else {
|
|
205
|
-
targetActorRef = resolvedTarget || actorScope
|
|
242
|
+
targetActorRef = resolvedTarget || actorScope.self;
|
|
206
243
|
}
|
|
207
244
|
return [snapshot, {
|
|
208
245
|
to: targetActorRef,
|
|
@@ -269,9 +306,9 @@ function sendParent(event, options) {
|
|
|
269
306
|
return sendTo(SpecialTargets.Parent, event, options);
|
|
270
307
|
}
|
|
271
308
|
/**
|
|
272
|
-
* Forwards (sends) an event to
|
|
309
|
+
* Forwards (sends) an event to the `target` actor.
|
|
273
310
|
*
|
|
274
|
-
* @param target The target
|
|
311
|
+
* @param target The target actor to forward the event to.
|
|
275
312
|
* @param options Options to pass into the send action creator.
|
|
276
313
|
*/
|
|
277
314
|
function forwardTo(target, options) {
|
|
@@ -315,6 +352,26 @@ function resolveEnqueueActions(actorScope, snapshot, args, _actionParams, {
|
|
|
315
352
|
});
|
|
316
353
|
return [snapshot, undefined, actions];
|
|
317
354
|
}
|
|
355
|
+
/**
|
|
356
|
+
* Creates an action object that will execute actions that are queued by the `enqueue(action)` function.
|
|
357
|
+
*
|
|
358
|
+
* @example
|
|
359
|
+
```ts
|
|
360
|
+
import { createMachine, enqueueActions } from 'xstate';
|
|
361
|
+
|
|
362
|
+
const machine = createMachine({
|
|
363
|
+
entry: enqueueActions(({ enqueue, check }) => {
|
|
364
|
+
enqueue.assign({ count: 0 });
|
|
365
|
+
|
|
366
|
+
if (check('someGuard')) {
|
|
367
|
+
enqueue.assign({ count: 1 });
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
enqueue('someAction');
|
|
371
|
+
})
|
|
372
|
+
})
|
|
373
|
+
```
|
|
374
|
+
*/
|
|
318
375
|
function enqueueActions(collect) {
|
|
319
376
|
function enqueueActions(args, params) {
|
|
320
377
|
}
|