xstate 5.14.0 → 5.15.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.
Files changed (58) hide show
  1. package/actions/dist/xstate-actions.cjs.js +2 -2
  2. package/actions/dist/xstate-actions.development.cjs.js +2 -2
  3. package/actions/dist/xstate-actions.development.esm.js +2 -2
  4. package/actions/dist/xstate-actions.esm.js +2 -2
  5. package/actions/dist/xstate-actions.umd.min.js.map +1 -1
  6. package/actors/dist/xstate-actors.cjs.js +272 -65
  7. package/actors/dist/xstate-actors.development.cjs.js +272 -65
  8. package/actors/dist/xstate-actors.development.esm.js +272 -65
  9. package/actors/dist/xstate-actors.esm.js +272 -65
  10. package/actors/dist/xstate-actors.umd.min.js.map +1 -1
  11. package/dist/declarations/src/State.d.ts +21 -25
  12. package/dist/declarations/src/StateMachine.d.ts +18 -30
  13. package/dist/declarations/src/StateNode.d.ts +29 -51
  14. package/dist/declarations/src/actions/assign.d.ts +29 -27
  15. package/dist/declarations/src/actions/cancel.d.ts +28 -22
  16. package/dist/declarations/src/actions/emit.d.ts +33 -33
  17. package/dist/declarations/src/actions/enqueueActions.d.ts +18 -16
  18. package/dist/declarations/src/actions/log.d.ts +5 -4
  19. package/dist/declarations/src/actions/send.d.ts +5 -3
  20. package/dist/declarations/src/actors/callback.d.ts +65 -26
  21. package/dist/declarations/src/actors/index.d.ts +4 -4
  22. package/dist/declarations/src/actors/observable.d.ts +65 -22
  23. package/dist/declarations/src/actors/promise.d.ts +86 -9
  24. package/dist/declarations/src/actors/transition.d.ts +89 -15
  25. package/dist/declarations/src/assert.d.ts +21 -20
  26. package/dist/declarations/src/createActor.d.ts +51 -42
  27. package/dist/declarations/src/createMachine.d.ts +40 -54
  28. package/dist/declarations/src/getNextSnapshot.d.ts +27 -24
  29. package/dist/declarations/src/guards.d.ts +67 -66
  30. package/dist/declarations/src/index.d.ts +0 -1
  31. package/dist/declarations/src/inspection.d.ts +1 -0
  32. package/dist/declarations/src/setup.d.ts +1 -2
  33. package/dist/declarations/src/spawn.d.ts +2 -5
  34. package/dist/declarations/src/stateUtils.d.ts +5 -10
  35. package/dist/declarations/src/toPromise.d.ts +1 -0
  36. package/dist/declarations/src/types.d.ts +162 -188
  37. package/dist/declarations/src/waitFor.d.ts +9 -9
  38. package/dist/{log-b87cb6bd.esm.js → log-63de2429.esm.js} +112 -117
  39. package/dist/{log-7ae0ddf8.cjs.js → log-b8c93ee3.cjs.js} +112 -117
  40. package/dist/{log-505687fd.development.cjs.js → log-d2c282d6.development.cjs.js} +112 -117
  41. package/dist/{log-c943e6aa.development.esm.js → log-e9953143.development.esm.js} +112 -117
  42. package/dist/{raise-4e39e875.esm.js → raise-2cfe6b8f.esm.js} +164 -154
  43. package/dist/{raise-0f400094.development.esm.js → raise-7d030497.development.esm.js} +164 -154
  44. package/dist/{raise-f79d2832.cjs.js → raise-a6298350.cjs.js} +164 -154
  45. package/dist/{raise-0cd7e521.development.cjs.js → raise-bad6a97b.development.cjs.js} +164 -154
  46. package/dist/xstate.cjs.js +134 -157
  47. package/dist/xstate.development.cjs.js +134 -157
  48. package/dist/xstate.development.esm.js +136 -159
  49. package/dist/xstate.esm.js +136 -159
  50. package/dist/xstate.umd.min.js +1 -1
  51. package/dist/xstate.umd.min.js.map +1 -1
  52. package/guards/dist/xstate-guards.cjs.js +1 -1
  53. package/guards/dist/xstate-guards.development.cjs.js +1 -1
  54. package/guards/dist/xstate-guards.development.esm.js +1 -1
  55. package/guards/dist/xstate-guards.esm.js +1 -1
  56. package/guards/dist/xstate-guards.umd.min.js.map +1 -1
  57. package/package.json +1 -1
  58. package/dist/declarations/src/typegenTypes.d.ts +0 -168
@@ -1,22 +1,17 @@
1
1
  import { MachineSnapshot } from "./State.js";
2
2
  import { StateNode } from "./StateNode.js";
3
3
  import { AnyActorSystem } from "./system.js";
4
- import { ResolveTypegenMeta, TypegenDisabled } from "./typegenTypes.js";
5
- import type { ActorLogic, ActorScope, AnyActorRef, AnyActorScope, DoNotInfer, Equals, EventDescriptor, EventObject, HistoryValue, InternalMachineImplementations, MachineConfig, MachineContext, MachineImplementationsSimplified, MetaObject, ParameterizedObject, ProvidedActor, Snapshot, StateMachineDefinition, StateValue, TransitionDefinition } from "./types.js";
4
+ import type { ActorLogic, ActorScope, AnyActorRef, AnyActorScope, DoNotInfer, Equals, EventDescriptor, EventObject, HistoryValue, InternalMachineImplementations, MachineConfig, MachineContext, MachineImplementationsSimplified, MetaObject, ParameterizedObject, ProvidedActor, Snapshot, StateMachineDefinition, StateValue, TransitionDefinition, ResolvedStateMachineTypes } from "./types.js";
6
5
  export declare const STATE_IDENTIFIER = "#";
7
6
  export declare const WILDCARD = "*";
8
7
  export declare class StateMachine<TContext extends MachineContext, TEvent extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string, TStateValue extends StateValue, TTag extends string, TInput, TOutput, TEmitted extends EventObject = EventObject, // TODO: remove default
9
- TMeta extends MetaObject = MetaObject, TResolvedTypesMeta = ResolveTypegenMeta<TypegenDisabled, DoNotInfer<TEvent>, TActor, TAction, TGuard, TDelay, TTag, TEmitted>> implements ActorLogic<MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta>, TEvent, TInput, AnyActorSystem, TEmitted> {
10
- /**
11
- * The raw config used to create the machine.
12
- */
8
+ TMeta extends MetaObject = MetaObject> implements ActorLogic<MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta>, TEvent, TInput, AnyActorSystem, TEmitted> {
9
+ /** The raw config used to create the machine. */
13
10
  config: MachineConfig<TContext, TEvent, any, any, any, any, any, any, TOutput, any, // TEmitted
14
11
  any> & {
15
12
  schemas?: unknown;
16
13
  };
17
- /**
18
- * The machine's own version.
19
- */
14
+ /** The machine's own version. */
20
15
  version?: string;
21
16
  schemas: unknown;
22
17
  implementations: MachineImplementationsSimplified<TContext, TEvent>;
@@ -25,24 +20,20 @@ TMeta extends MetaObject = MetaObject, TResolvedTypesMeta = ResolveTypegenMeta<T
25
20
  states: StateNode<TContext, TEvent>['states'];
26
21
  events: Array<EventDescriptor<TEvent>>;
27
22
  constructor(
28
- /**
29
- * The raw config used to create the machine.
30
- */
23
+ /** The raw config used to create the machine. */
31
24
  config: MachineConfig<TContext, TEvent, any, any, any, any, any, any, TOutput, any, // TEmitted
32
25
  any> & {
33
26
  schemas?: unknown;
34
27
  }, implementations?: MachineImplementationsSimplified<TContext, TEvent>);
35
28
  /**
36
- * Clones this state machine with the provided implementations
37
- * and merges the `context` (if provided).
38
- *
39
- * @param implementations Options (`actions`, `guards`, `actors`, `delays`, `context`)
40
- * to recursively merge with the existing options.
29
+ * Clones this state machine with the provided implementations and merges the
30
+ * `context` (if provided).
41
31
  *
32
+ * @param implementations Options (`actions`, `guards`, `actors`, `delays`,
33
+ * `context`) to recursively merge with the existing options.
42
34
  * @returns A new `StateMachine` instance with the provided implementations.
43
35
  */
44
- provide(implementations: InternalMachineImplementations<TContext, TResolvedTypesMeta, true>): StateMachine<TContext, TEvent, TChildren, TActor, TAction, TGuard, TDelay, TStateValue, TTag, TInput, TOutput, TEmitted, TMeta, // TMeta
45
- TResolvedTypesMeta>;
36
+ provide(implementations: InternalMachineImplementations<ResolvedStateMachineTypes<TContext, DoNotInfer<TEvent>, TActor, TAction, TGuard, TDelay, TTag, TEmitted>>): StateMachine<TContext, TEvent, TChildren, TActor, TAction, TGuard, TDelay, TStateValue, TTag, TInput, TOutput, TEmitted, TMeta>;
46
37
  resolveState(config: {
47
38
  value: StateValue;
48
39
  context?: TContext;
@@ -54,16 +45,16 @@ TMeta extends MetaObject = MetaObject, TResolvedTypesMeta = ResolveTypegenMeta<T
54
45
  context: unknown;
55
46
  } : {})): MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta>;
56
47
  /**
57
- * Determines the next snapshot given the current `snapshot` and received `event`.
58
- * Calculates a full macrostep from all microsteps.
48
+ * Determines the next snapshot given the current `snapshot` and received
49
+ * `event`. Calculates a full macrostep from all microsteps.
59
50
  *
60
51
  * @param snapshot The current snapshot
61
52
  * @param event The received event
62
53
  */
63
54
  transition(snapshot: MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta>, event: TEvent, actorScope: ActorScope<typeof snapshot, TEvent, AnyActorSystem, TEmitted>): MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta>;
64
55
  /**
65
- * Determines the next state given the current `state` and `event`.
66
- * Calculates a microstep.
56
+ * Determines the next state given the current `state` and `event`. Calculates
57
+ * a microstep.
67
58
  *
68
59
  * @param state The current state
69
60
  * @param event The received event
@@ -71,12 +62,13 @@ TMeta extends MetaObject = MetaObject, TResolvedTypesMeta = ResolveTypegenMeta<T
71
62
  microstep(snapshot: MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta>, event: TEvent, actorScope: AnyActorScope): Array<MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta>>;
72
63
  getTransitionData(snapshot: MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta>, event: TEvent): Array<TransitionDefinition<TContext, TEvent>>;
73
64
  /**
74
- * The initial state _before_ evaluating any microsteps.
75
- * This "pre-initial" state is provided to initial actions executed in the initial state.
65
+ * The initial state _before_ evaluating any microsteps. This "pre-initial"
66
+ * state is provided to initial actions executed in the initial state.
76
67
  */
77
68
  private getPreInitialState;
78
69
  /**
79
- * Returns the initial `State` instance, with reference to `self` as an `ActorRef`.
70
+ * Returns the initial `State` instance, with reference to `self` as an
71
+ * `ActorRef`.
80
72
  */
81
73
  getInitialSnapshot(actorScope: ActorScope<MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta>, TEvent, AnyActorSystem, TEmitted>, input?: TInput): MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta>;
82
74
  start(snapshot: MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta>): void;
@@ -85,8 +77,4 @@ TMeta extends MetaObject = MetaObject, TResolvedTypesMeta = ResolveTypegenMeta<T
85
77
  toJSON(): StateMachineDefinition<TContext, TEvent>;
86
78
  getPersistedSnapshot(snapshot: MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta>, options?: unknown): Snapshot<unknown>;
87
79
  restoreSnapshot(snapshot: Snapshot<unknown>, _actorScope: ActorScope<MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta>, TEvent, AnyActorSystem, TEmitted>): MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta>;
88
- /**
89
- * @deprecated an internal property that was acting as a "phantom" type, it's not used by anything right now but it's kept around for compatibility reasons
90
- **/
91
- __TResolvedTypesMeta: TResolvedTypesMeta;
92
80
  }
@@ -6,9 +6,7 @@ interface StateNodeOptions<TContext extends MachineContext, TEvent extends Event
6
6
  _machine: AnyStateMachine;
7
7
  }
8
8
  export declare class StateNode<TContext extends MachineContext = MachineContext, TEvent extends EventObject = EventObject> {
9
- /**
10
- * The raw config used to create the machine.
11
- */
9
+ /** The raw config used to create the machine. */
12
10
  config: StateNodeConfig<TContext, TEvent, TODO, // actors
13
11
  TODO, // actions
14
12
  TODO, // guards
@@ -18,74 +16,64 @@ export declare class StateNode<TContext extends MachineContext = MachineContext,
18
16
  TODO, // emitted
19
17
  TODO>;
20
18
  /**
21
- * The relative key of the state node, which represents its location in the overall state value.
19
+ * The relative key of the state node, which represents its location in the
20
+ * overall state value.
22
21
  */
23
22
  key: string;
24
- /**
25
- * The unique ID of the state node.
26
- */
23
+ /** The unique ID of the state node. */
27
24
  id: string;
28
25
  /**
29
26
  * The type of this state node:
30
27
  *
31
- * - `'atomic'` - no child state nodes
32
- * - `'compound'` - nested child state nodes (XOR)
33
- * - `'parallel'` - orthogonal nested child state nodes (AND)
34
- * - `'history'` - history state node
35
- * - `'final'` - final state node
28
+ * - `'atomic'` - no child state nodes
29
+ * - `'compound'` - nested child state nodes (XOR)
30
+ * - `'parallel'` - orthogonal nested child state nodes (AND)
31
+ * - `'history'` - history state node
32
+ * - `'final'` - final state node
36
33
  */
37
34
  type: 'atomic' | 'compound' | 'parallel' | 'final' | 'history';
38
- /**
39
- * The string path from the root machine node to this node.
40
- */
35
+ /** The string path from the root machine node to this node. */
41
36
  path: string[];
42
- /**
43
- * The child state nodes.
44
- */
37
+ /** The child state nodes. */
45
38
  states: StateNodesConfig<TContext, TEvent>;
46
39
  /**
47
40
  * The type of history on this state node. Can be:
48
41
  *
49
- * - `'shallow'` - recalls only top-level historical state value
50
- * - `'deep'` - recalls historical state value at all levels
42
+ * - `'shallow'` - recalls only top-level historical state value
43
+ * - `'deep'` - recalls historical state value at all levels
51
44
  */
52
45
  history: false | 'shallow' | 'deep';
53
- /**
54
- * The action(s) to be executed upon entering the state node.
55
- */
46
+ /** The action(s) to be executed upon entering the state node. */
56
47
  entry: UnknownAction[];
57
- /**
58
- * The action(s) to be executed upon exiting the state node.
59
- */
48
+ /** The action(s) to be executed upon exiting the state node. */
60
49
  exit: UnknownAction[];
61
- /**
62
- * The parent state node.
63
- */
50
+ /** The parent state node. */
64
51
  parent?: StateNode<TContext, TEvent>;
65
- /**
66
- * The root machine node.
67
- */
52
+ /** The root machine node. */
68
53
  machine: StateMachine<TContext, TEvent, any, // children
69
54
  any, // actor
70
55
  any, // action
71
56
  any, // guard
72
57
  any, // delay
58
+ any, // state value
73
59
  any, // tag
74
60
  any, // input
75
61
  any, // output
76
62
  any, // emitted
77
- any, // TMeta
78
63
  any>;
79
64
  /**
80
- * The meta data associated with this state node, which will be returned in State instances.
65
+ * The meta data associated with this state node, which will be returned in
66
+ * State instances.
81
67
  */
82
68
  meta?: any;
83
69
  /**
84
- * The output data sent with the "xstate.done.state._id_" event if this is a final state node.
70
+ * The output data sent with the "xstate.done.state._id_" event if this is a
71
+ * final state node.
85
72
  */
86
73
  output?: Mapper<MachineContext, EventObject, unknown, EventObject> | NonReducibleUnknown;
87
74
  /**
88
- * The order this state node appears. Corresponds to the implicit document order.
75
+ * The order this state node appears. Corresponds to the implicit document
76
+ * order.
89
77
  */
90
78
  order: number;
91
79
  description?: string;
@@ -93,9 +81,7 @@ export declare class StateNode<TContext extends MachineContext = MachineContext,
93
81
  transitions: Map<string, TransitionDefinition<TContext, TEvent>[]>;
94
82
  always?: Array<TransitionDefinition<TContext, TEvent>>;
95
83
  constructor(
96
- /**
97
- * The raw config used to create the machine.
98
- */
84
+ /** The raw config used to create the machine. */
99
85
  config: StateNodeConfig<TContext, TEvent, TODO, // actors
100
86
  TODO, // actions
101
87
  TODO, // guards
@@ -104,24 +90,16 @@ export declare class StateNode<TContext extends MachineContext = MachineContext,
104
90
  TODO, // output
105
91
  TODO, // emitted
106
92
  TODO>, options: StateNodeOptions<TContext, TEvent>);
107
- /**
108
- * The well-structured state node definition.
109
- */
93
+ /** The well-structured state node definition. */
110
94
  get definition(): StateNodeDefinition<TContext, TEvent>;
111
- /**
112
- * The logic invoked as actors by this state node.
113
- */
95
+ /** The logic invoked as actors by this state node. */
114
96
  get invoke(): Array<InvokeDefinition<TContext, TEvent, ProvidedActor, ParameterizedObject, ParameterizedObject, string, TODO, // TEmitted
115
97
  TODO>>;
116
- /**
117
- * The mapping of events to transitions.
118
- */
98
+ /** The mapping of events to transitions. */
119
99
  get on(): TransitionDefinitionMap<TContext, TEvent>;
120
100
  get after(): Array<DelayedTransitionDefinition<TContext, TEvent>>;
121
101
  get initial(): InitialTransitionDefinition<TContext, TEvent>;
122
- /**
123
- * All the event types accepted by this state node and its descendants.
124
- */
102
+ /** All the event types accepted by this state node and its descendants. */
125
103
  get events(): Array<EventDescriptor<TEvent>>;
126
104
  /**
127
105
  * All the events that have transitions directly from this state node.
@@ -10,34 +10,36 @@ export interface AssignAction<TContext extends MachineContext, TExpressionEvent
10
10
  /**
11
11
  * Updates the current context of the machine.
12
12
  *
13
- * @param assignment An object that represents the partial context to update, or a
14
- * function that returns an object that represents the partial context to update.
15
- *
16
13
  * @example
17
- ```ts
18
- import { createMachine, assign } from 'xstate';
19
-
20
- const countMachine = createMachine({
21
- context: {
22
- count: 0,
23
- message: ''
24
- },
25
- on: {
26
- inc: {
27
- actions: assign({
28
- count: ({ context }) => context.count + 1
29
- })
30
- },
31
- updateMessage: {
32
- actions: assign(({ context, event }) => {
33
- return {
34
- message: event.message.trim()
35
- }
36
- })
37
- }
38
- }
39
- });
40
- ```
14
+ *
15
+ * ```ts
16
+ * import { createMachine, assign } from 'xstate';
17
+ *
18
+ * const countMachine = createMachine({
19
+ * context: {
20
+ * count: 0,
21
+ * message: ''
22
+ * },
23
+ * on: {
24
+ * inc: {
25
+ * actions: assign({
26
+ * count: ({ context }) => context.count + 1
27
+ * })
28
+ * },
29
+ * updateMessage: {
30
+ * actions: assign(({ context, event }) => {
31
+ * return {
32
+ * message: event.message.trim()
33
+ * };
34
+ * })
35
+ * }
36
+ * }
37
+ * });
38
+ * ```
39
+ *
40
+ * @param assignment An object that represents the partial context to update, or
41
+ * a function that returns an object that represents the partial context to
42
+ * update.
41
43
  */
42
44
  export declare function assign<TContext extends MachineContext, TExpressionEvent extends AnyEventObject, // TODO: consider using a stricter `EventObject` here
43
45
  TParams extends ParameterizedObject['params'] | undefined, TEvent extends EventObject, TActor extends ProvidedActor>(assignment: Assigner<LowInfer<TContext>, TExpressionEvent, TParams, TEvent, TActor> | PropertyAssigner<LowInfer<TContext>, TExpressionEvent, TParams, TEvent, TActor>): ActionFunction<TContext, TExpressionEvent, TEvent, TParams, TActor, never, never, never, never>;
@@ -4,30 +4,36 @@ export interface CancelAction<TContext extends MachineContext, TExpressionEvent
4
4
  (args: ActionArgs<TContext, TExpressionEvent, TEvent>, params: TParams): void;
5
5
  }
6
6
  /**
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.
9
- *
10
- * @param sendId The `id` of the `sendTo(...)` action to cancel.
7
+ * Cancels a delayed `sendTo(...)` action that is waiting to be executed. The
8
+ * canceled `sendTo(...)` action will not send its event or execute, unless the
9
+ * `delay` has already elapsed before `cancel(...)` is called.
11
10
  *
12
11
  * @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
+ *
13
+ * ```ts
14
+ * import { createMachine, sendTo, cancel } from 'xstate';
15
+ *
16
+ * const machine = createMachine({
17
+ * // ...
18
+ * on: {
19
+ * sendEvent: {
20
+ * actions: sendTo(
21
+ * 'some-actor',
22
+ * { type: 'someEvent' },
23
+ * {
24
+ * id: 'some-id',
25
+ * delay: 1000
26
+ * }
27
+ * )
28
+ * },
29
+ * cancelEvent: {
30
+ * actions: cancel('some-id')
31
+ * }
32
+ * }
33
+ * });
34
+ * ```
35
+ *
36
+ * @param sendId The `id` of the `sendTo(...)` action to cancel.
31
37
  */
32
38
  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>;
33
39
  export {};
@@ -4,41 +4,41 @@ export interface EmitAction<TContext extends MachineContext, TExpressionEvent ex
4
4
  _out_TEmitted?: TEmitted;
5
5
  }
6
6
  /**
7
- * Emits an event to event handlers registered on the actor via `actor.on(event, handler)`.
7
+ * Emits an event to event handlers registered on the actor via `actor.on(event,
8
+ * handler)`.
8
9
  *
9
10
  * @example
10
- ```ts
11
- import { emit } from 'xstate';
12
-
13
- const machine = createMachine({
14
- // ...
15
- on: {
16
- something: {
17
- actions: emit({
18
- type: 'emitted',
19
- some: 'data'
20
- })
21
- }
22
- }
23
- // ...
24
- });
25
-
26
- const actor = createActor(machine).start();
27
-
28
- actor.on('emitted', (event) => {
29
- console.log(event);
30
- });
31
-
32
- actor.send({ type: 'something' });
33
- // logs:
34
- // {
35
- // type: 'emitted',
36
- // some: 'data'
37
- // }
38
- ```
11
+ *
12
+ * ```ts
13
+ * import { emit } from 'xstate';
14
+ *
15
+ * const machine = createMachine({
16
+ * // ...
17
+ * on: {
18
+ * something: {
19
+ * actions: emit({
20
+ * type: 'emitted',
21
+ * some: 'data'
22
+ * })
23
+ * }
24
+ * }
25
+ * // ...
26
+ * });
27
+ *
28
+ * const actor = createActor(machine).start();
29
+ *
30
+ * actor.on('emitted', (event) => {
31
+ * console.log(event);
32
+ * });
33
+ *
34
+ * actor.send({ type: 'something' });
35
+ * // logs:
36
+ * // {
37
+ * // type: 'emitted',
38
+ * // some: 'data'
39
+ * // }
40
+ * ```
39
41
  */
40
42
  export declare function emit<TContext extends MachineContext, TExpressionEvent extends EventObject, TParams extends ParameterizedObject['params'] | undefined, TEvent extends EventObject, TEmitted extends EventObject>(
41
- /**
42
- * The event to emit, or an expression that returns an event to emit.
43
- */
43
+ /** The event to emit, or an expression that returns an event to emit. */
44
44
  eventOrExpr: TEmitted | SendExpr<TContext, TExpressionEvent, TParams, TEmitted, TEvent>): ActionFunction<TContext, TExpressionEvent, TEvent, TParams, never, never, never, never, TEmitted>;
@@ -31,24 +31,26 @@ interface CollectActionsArg<TContext extends MachineContext, TExpressionEvent ex
31
31
  }
32
32
  type CollectActions<TContext extends MachineContext, TExpressionEvent extends EventObject, TParams extends ParameterizedObject['params'] | undefined, TEvent extends EventObject, TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string, TEmitted extends EventObject> = ({ context, event, check, enqueue, self }: CollectActionsArg<TContext, TExpressionEvent, TEvent, TActor, TAction, TGuard, TDelay, TEmitted>, params: TParams) => void;
33
33
  /**
34
- * Creates an action object that will execute actions that are queued by the `enqueue(action)` function.
34
+ * Creates an action object that will execute actions that are queued by the
35
+ * `enqueue(action)` function.
35
36
  *
36
37
  * @example
37
- ```ts
38
- import { createMachine, enqueueActions } from 'xstate';
39
-
40
- const machine = createMachine({
41
- entry: enqueueActions(({ enqueue, check }) => {
42
- enqueue.assign({ count: 0 });
43
-
44
- if (check('someGuard')) {
45
- enqueue.assign({ count: 1 });
46
- }
47
-
48
- enqueue('someAction');
49
- })
50
- })
51
- ```
38
+ *
39
+ * ```ts
40
+ * import { createMachine, enqueueActions } from 'xstate';
41
+ *
42
+ * const machine = createMachine({
43
+ * entry: enqueueActions(({ enqueue, check }) => {
44
+ * enqueue.assign({ count: 0 });
45
+ *
46
+ * if (check('someGuard')) {
47
+ * enqueue.assign({ count: 1 });
48
+ * }
49
+ *
50
+ * enqueue('someAction');
51
+ * })
52
+ * });
53
+ * ```
52
54
  */
53
55
  export declare function enqueueActions<TContext extends MachineContext, TExpressionEvent extends EventObject, TParams extends ParameterizedObject['params'] | undefined, TEvent extends EventObject = TExpressionEvent, TActor extends ProvidedActor = ProvidedActor, TAction extends ParameterizedObject = ParameterizedObject, TGuard extends ParameterizedObject = ParameterizedObject, TDelay extends string = never, TEmitted extends EventObject = EventObject>(collect: CollectActions<TContext, TExpressionEvent, TParams, TEvent, TActor, TAction, TGuard, TDelay, TEmitted>): ActionFunction<TContext, TExpressionEvent, TEvent, TParams, TActor, TAction, TGuard, TDelay, TEmitted>;
54
56
  export {};
@@ -4,11 +4,12 @@ export interface LogAction<TContext extends MachineContext, TExpressionEvent ext
4
4
  (args: ActionArgs<TContext, TExpressionEvent, TEvent>, params: TParams): void;
5
5
  }
6
6
  /**
7
+ * @param expr The expression function to evaluate which will be logged. Takes
8
+ * in 2 arguments:
9
+ *
10
+ * - `ctx` - the current state context
11
+ * - `event` - the event that caused this action to be executed.
7
12
  *
8
- * @param expr The expression function to evaluate which will be logged.
9
- * Takes in 2 arguments:
10
- * - `ctx` - the current state context
11
- * - `event` - the event that caused this action to be executed.
12
13
  * @param label The label to give to the logged expression.
13
14
  */
14
15
  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>;
@@ -7,10 +7,12 @@ export interface SendToAction<TContext extends MachineContext, TExpressionEvent
7
7
  * Sends an event to an actor.
8
8
  *
9
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
10
+ * @param event The event to send, or an expression that evaluates to the event
11
+ * to send
11
12
  * @param options Send action options
12
- * - `id` - The unique send event identifier (used with `cancel()`).
13
- * - `delay` - The number of milliseconds to delay the sending of the event.
13
+ *
14
+ * - `id` - The unique send event identifier (used with `cancel()`).
15
+ * - `delay` - The number of milliseconds to delay the sending of the event.
14
16
  */
15
17
  export declare function sendTo<TContext extends MachineContext, TExpressionEvent extends EventObject, TParams extends ParameterizedObject['params'] | undefined, TTargetActor extends AnyActorRef, TEvent extends EventObject, TDelay extends string = never, TUsedDelay extends TDelay = never>(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, DoNotInfer<TEvent>, TUsedDelay>): ActionFunction<TContext, TExpressionEvent, TEvent, TParams, never, never, never, TDelay, never>;
16
18
  /**