xstate 5.4.0 → 5.5.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 (48) 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 +1 -1
  6. package/actions/dist/xstate-actions.umd.min.js.map +1 -1
  7. package/actors/dist/xstate-actors.cjs.js +1 -1
  8. package/actors/dist/xstate-actors.development.cjs.js +1 -1
  9. package/actors/dist/xstate-actors.development.esm.js +1 -1
  10. package/actors/dist/xstate-actors.esm.js +1 -1
  11. package/actors/dist/xstate-actors.umd.min.js.map +1 -1
  12. package/dist/declarations/src/State.d.ts +43 -17
  13. package/dist/declarations/src/StateMachine.d.ts +16 -15
  14. package/dist/declarations/src/StateNode.d.ts +0 -4
  15. package/dist/declarations/src/actions/assign.d.ts +28 -1
  16. package/dist/declarations/src/actions/cancel.d.ts +23 -4
  17. package/dist/declarations/src/actions/enqueueActions.d.ts +20 -0
  18. package/dist/declarations/src/actions/send.d.ts +2 -2
  19. package/dist/declarations/src/{interpreter.d.ts → createActor.d.ts} +2 -4
  20. package/dist/declarations/src/createMachine.d.ts +40 -0
  21. package/dist/declarations/src/getNextSnapshot.d.ts +32 -0
  22. package/dist/declarations/src/guards.d.ts +86 -0
  23. package/dist/declarations/src/index.d.ts +2 -1
  24. package/dist/declarations/src/spawn.d.ts +2 -2
  25. package/dist/declarations/src/typegenTypes.d.ts +26 -14
  26. package/dist/declarations/src/types.d.ts +17 -36
  27. package/dist/{log-e870aec8.esm.js → log-22b3587f.esm.js} +67 -10
  28. package/dist/{log-580765a2.development.esm.js → log-285f62db.development.esm.js} +67 -10
  29. package/dist/{log-a32b44b3.cjs.js → log-742895c6.cjs.js} +67 -10
  30. package/dist/{log-cd3d7c14.development.cjs.js → log-da322832.development.cjs.js} +67 -10
  31. package/dist/{raise-7df513e7.esm.js → raise-0e64ee6e.esm.js} +125 -16
  32. package/dist/{raise-e3ff3de1.development.cjs.js → raise-7af39710.development.cjs.js} +125 -16
  33. package/dist/{raise-0fc3a80c.development.esm.js → raise-8da27ebb.development.esm.js} +125 -16
  34. package/dist/{raise-c3bbdd3a.cjs.js → raise-ad8bb7c2.cjs.js} +125 -16
  35. package/dist/xstate.cjs.js +105 -4
  36. package/dist/xstate.cjs.mjs +1 -0
  37. package/dist/xstate.development.cjs.js +105 -4
  38. package/dist/xstate.development.cjs.mjs +1 -0
  39. package/dist/xstate.development.esm.js +107 -7
  40. package/dist/xstate.esm.js +107 -7
  41. package/dist/xstate.umd.min.js +1 -1
  42. package/dist/xstate.umd.min.js.map +1 -1
  43. package/guards/dist/xstate-guards.cjs.js +1 -1
  44. package/guards/dist/xstate-guards.development.cjs.js +1 -1
  45. package/guards/dist/xstate-guards.development.esm.js +1 -1
  46. package/guards/dist/xstate-guards.esm.js +1 -1
  47. package/guards/dist/xstate-guards.umd.min.js.map +1 -1
  48. package/package.json +1 -1
@@ -3,11 +3,11 @@ 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, GuardPredicate, UnknownGuard } from "./guards.js";
7
- import type { Actor } from "./interpreter.js";
6
+ import { Guard, UnknownGuard } from "./guards.js";
7
+ import type { Actor } from "./createActor.js";
8
8
  import { Spawner } from "./spawn.js";
9
9
  import { AnyActorSystem, InspectionEvent, Clock } from './system.js';
10
- import { AreAllImplementationsAssumedToBeProvided, MarkAllImplementationsAsProvided, ResolveTypegenMeta, TypegenConstraint, TypegenDisabled } from "./typegenTypes.js";
10
+ import { ResolveTypegenMeta, TypegenConstraint, TypegenDisabled } from "./typegenTypes.js";
11
11
  export type Identity<T> = {
12
12
  [K in keyof T]: T[K];
13
13
  };
@@ -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
- * If `true`, states and events will be logged to Redux DevTools.
600
- *
601
- * Default: `false`
586
+ * @deprecated Use `inspect` instead.
602
587
  */
603
- devTools?: boolean | DevToolsAdapter;
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 definition.
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
- export type ExtractEvent<TEvent extends EventObject, TDescriptor extends EventDescriptor<TEvent>> = string extends TEvent['type'] ? TEvent : NormalizeDescriptor<TDescriptor> extends infer TNormalizedDescriptor ? TEvent extends any ? TEvent['type'] extends TNormalizedDescriptor ? TEvent : never : never : never;
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
  }
@@ -754,13 +734,13 @@ export interface ActorRef<TSnapshot extends Snapshot<unknown>, TEvent extends Ev
754
734
  src: string | AnyActorLogic;
755
735
  }
756
736
  export type AnyActorRef = ActorRef<any, any>;
757
- export type ActorLogicFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<any, any, any, any, any, any, any, any, any, any, any> ? R : R extends Promise<infer U> ? PromiseActorLogic<U> : never : never;
758
- export type ActorRefFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<infer TContext, infer TEvent, infer TChildren, infer _TActor, infer _TAction, infer _TGuard, infer _TDelay, infer TStateValue, infer TTag, infer _TInput, infer TOutput, infer TResolvedTypesMeta> ? ActorRef<MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, AreAllImplementationsAssumedToBeProvided<TResolvedTypesMeta> extends false ? MarkAllImplementationsAsProvided<TResolvedTypesMeta> : TResolvedTypesMeta>, TEvent> : R extends Promise<infer U> ? ActorRefFrom<PromiseActorLogic<U>> : R extends ActorLogic<infer TSnapshot, infer TEvent, infer _TInput, infer _TSystem> ? ActorRef<TSnapshot, TEvent> : never : never;
737
+ export type ActorLogicFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<any, any, any, any, any, any, any, any, any, any, any, any> ? R : R extends Promise<infer U> ? PromiseActorLogic<U> : never : never;
738
+ export type ActorRefFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<infer TContext, infer TEvent, infer TChildren, infer _TActor, infer _TAction, infer _TGuard, infer _TDelay, infer TStateValue, infer TTag, infer _TInput, infer TOutput, infer _TResolvedTypesMeta> ? ActorRef<MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput>, TEvent> : R extends Promise<infer U> ? ActorRefFrom<PromiseActorLogic<U>> : R extends ActorLogic<infer TSnapshot, infer TEvent, infer _TInput, infer _TSystem> ? ActorRef<TSnapshot, TEvent> : never : never;
759
739
  export type DevToolsAdapter = (service: AnyActor) => void;
760
740
  /**
761
741
  * @deprecated Use `Actor<T>` instead.
762
742
  */
763
- export type InterpreterFrom<T extends AnyStateMachine | ((...args: any[]) => AnyStateMachine)> = ReturnTypeOrValue<T> extends StateMachine<infer TContext, infer TEvent, infer TChildren, infer _TActor, infer _TAction, infer _TGuard, infer _TDelay, infer TStateValue, infer TTag, infer TInput, infer TOutput, infer TResolvedTypesMeta> ? Actor<ActorLogic<MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TResolvedTypesMeta>, TEvent, TInput, AnyActorSystem>> : never;
743
+ export type InterpreterFrom<T extends AnyStateMachine | ((...args: any[]) => AnyStateMachine)> = ReturnTypeOrValue<T> extends StateMachine<infer TContext, infer TEvent, infer TChildren, infer _TActor, infer _TAction, infer _TGuard, infer _TDelay, infer TStateValue, infer TTag, infer TInput, infer TOutput, infer _TResolvedTypesMeta> ? Actor<ActorLogic<MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput>, TEvent, TInput, AnyActorSystem>> : never;
764
744
  export type MachineImplementationsFrom<T extends AnyStateMachine | ((...args: any[]) => AnyStateMachine), TRequireMissingImplementations extends boolean = false> = ReturnTypeOrValue<T> extends StateMachine<infer TContext, infer _TEvent, infer _TChildren, infer _TActor, infer _TAction, infer _TGuard, infer _TDelay, infer _TStateValue, infer _TTag, infer _TInput, infer _TOutput, infer TResolvedTypesMeta> ? InternalMachineImplementations<TContext, TResolvedTypesMeta, TRequireMissingImplementations> : never;
765
745
  export type __ResolvedTypesMetaFrom<T> = T extends StateMachine<any, // context
766
746
  any, // event
@@ -769,6 +749,7 @@ any, // actor
769
749
  any, // action
770
750
  any, // guard
771
751
  any, // delay
752
+ any, // state value
772
753
  any, // tag
773
754
  any, // input
774
755
  any, // output
@@ -858,9 +839,9 @@ any>;
858
839
  export type UnknownActorLogic = ActorLogic<any, any, never, AnyActorSystem>;
859
840
  export type SnapshotFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends ActorRef<infer TSnapshot, infer _> ? TSnapshot : R extends Actor<infer TLogic> ? SnapshotFrom<TLogic> : R extends ActorLogic<infer _, infer __, infer ___, infer ____> ? ReturnType<R['transition']> : R extends ActorScope<infer TSnapshot, infer _, infer __> ? TSnapshot : never : never;
860
841
  export type EventFromLogic<TLogic extends ActorLogic<any, any, any, any>> = TLogic extends ActorLogic<infer _, infer TEvent, infer __, infer _____> ? TEvent : never;
861
- type ResolveEventType<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<infer _TContext, infer TEvent, infer _TChildren, infer _TActor, infer _TAction, infer _TGuard, infer _TDelay, infer _TStateValue, infer _TTag, infer _TInput, infer _TOutput, infer _TResolvedTypesMeta> ? TEvent : R extends MachineSnapshot<infer _TContext, infer TEvent, infer _TChildren, infer _TTag, infer _TOutput, infer _TResolvedTypesMeta> ? TEvent : R extends ActorRef<infer _, infer TEvent> ? TEvent : never : never;
842
+ type ResolveEventType<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<infer _TContext, infer TEvent, infer _TChildren, infer _TActor, infer _TAction, infer _TGuard, infer _TDelay, infer _TStateValue, infer _TTag, infer _TInput, infer _TOutput, infer _TResolvedTypesMeta> ? TEvent : R extends MachineSnapshot<infer _TContext, infer TEvent, infer _TChildren, infer _TStateValue, infer _TTag, infer _TOutput> ? TEvent : R extends ActorRef<infer _, infer TEvent> ? TEvent : never : never;
862
843
  export type EventFrom<T, K extends Prop<TEvent, 'type'> = never, TEvent extends EventObject = ResolveEventType<T>> = IsNever<K> extends true ? TEvent : ExtractEvent<TEvent, K>;
863
- export type ContextFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<infer TContext, infer _TEvent, infer _TChildren, infer _TActor, infer _TAction, infer _TGuard, infer _TDelay, infer _TStateValue, infer _TTag, infer _TInput, infer _TOutput, infer _TTypesMeta> ? TContext : R extends MachineSnapshot<infer TContext, infer _TEvent, infer _TChildren, infer _TTag, infer _TOutput, infer _TResolvedTypesMeta> ? TContext : R extends Actor<infer TActorLogic> ? TActorLogic extends StateMachine<infer TContext, infer _TEvent, infer _TChildren, infer _TActor, infer _TAction, infer _TGuard, infer _TDelay, infer _TTag, infer _TInput, infer _TOutput, infer _TTypesMeta> ? TContext : never : never : never;
844
+ export type ContextFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<infer TContext, infer _TEvent, infer _TChildren, infer _TActor, infer _TAction, infer _TGuard, infer _TDelay, infer _TStateValue, infer _TTag, infer _TInput, infer _TOutput, infer _TResolvedTypesMeta> ? TContext : R extends MachineSnapshot<infer TContext, infer _TEvent, infer _TChildren, infer _TStateValue, infer _TTag, infer _TOutput> ? TContext : R extends Actor<infer TActorLogic> ? TActorLogic extends StateMachine<infer TContext, infer _TEvent, infer _TChildren, infer _TActor, infer _TAction, infer _TGuard, infer _TDelay, infer _TTag, infer _TInput, infer _TOutput, infer _TResolvedTypesMeta> ? TContext : never : never : never;
864
845
  export type InferEvent<E extends EventObject> = {
865
846
  [T in E['type']]: {
866
847
  type: T;
@@ -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-7df513e7.esm.js';
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?.self,
71
- system: actorScope?.system
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?.self._parent;
228
+ targetActorRef = actorScope.self._parent;
192
229
  } else if (resolvedTarget === SpecialTargets.Internal) {
193
- targetActorRef = actorScope?.self;
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?.self;
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 a specified service.
309
+ * Forwards (sends) an event to the `target` actor.
273
310
  *
274
- * @param target The target service to forward the event to.
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
  }
@@ -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-0fc3a80c.development.esm.js';
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-8da27ebb.development.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?.self,
71
- system: actorScope?.system
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) {
@@ -141,7 +168,9 @@ function assign(assignment) {
141
168
  /** @deprecated use `AnyMachineSnapshot` instead */
142
169
 
143
170
  // TODO: possibly refactor this somehow, use even a simpler type, and maybe even make `machine.options` private or something
144
-
171
+ /**
172
+ * @internal
173
+ */
145
174
  let SpecialTargets = /*#__PURE__*/function (SpecialTargets) {
146
175
  SpecialTargets["Parent"] = "#_parent";
147
176
  SpecialTargets["Internal"] = "#_internal";
@@ -154,6 +183,14 @@ let SpecialTargets = /*#__PURE__*/function (SpecialTargets) {
154
183
 
155
184
  // Based on RxJS types
156
185
 
186
+ /**
187
+ * @internal
188
+ */
189
+
190
+ /**
191
+ * @internal
192
+ */
193
+
157
194
  /**
158
195
  * @deprecated Use `Actor<T>` instead.
159
196
  */
@@ -191,9 +228,9 @@ function resolveSendTo(actorScope, snapshot, args, actionParams, {
191
228
  let targetActorRef;
192
229
  if (typeof resolvedTarget === 'string') {
193
230
  if (resolvedTarget === SpecialTargets.Parent) {
194
- targetActorRef = actorScope?.self._parent;
231
+ targetActorRef = actorScope.self._parent;
195
232
  } else if (resolvedTarget === SpecialTargets.Internal) {
196
- targetActorRef = actorScope?.self;
233
+ targetActorRef = actorScope.self;
197
234
  } else if (resolvedTarget.startsWith('#_')) {
198
235
  // SCXML compatibility: https://www.w3.org/TR/scxml/#SCXMLEventProcessor
199
236
  // #_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.
@@ -205,7 +242,7 @@ function resolveSendTo(actorScope, snapshot, args, actionParams, {
205
242
  throw new Error(`Unable to send event to actor '${resolvedTarget}' from machine '${snapshot.machine.id}'.`);
206
243
  }
207
244
  } else {
208
- targetActorRef = resolvedTarget || actorScope?.self;
245
+ targetActorRef = resolvedTarget || actorScope.self;
209
246
  }
210
247
  return [snapshot, {
211
248
  to: targetActorRef,
@@ -275,9 +312,9 @@ function sendParent(event, options) {
275
312
  return sendTo(SpecialTargets.Parent, event, options);
276
313
  }
277
314
  /**
278
- * Forwards (sends) an event to a specified service.
315
+ * Forwards (sends) an event to the `target` actor.
279
316
  *
280
- * @param target The target service to forward the event to.
317
+ * @param target The target actor to forward the event to.
281
318
  * @param options Options to pass into the send action creator.
282
319
  */
283
320
  function forwardTo(target, options) {
@@ -331,6 +368,26 @@ function resolveEnqueueActions(actorScope, snapshot, args, _actionParams, {
331
368
  });
332
369
  return [snapshot, undefined, actions];
333
370
  }
371
+ /**
372
+ * Creates an action object that will execute actions that are queued by the `enqueue(action)` function.
373
+ *
374
+ * @example
375
+ ```ts
376
+ import { createMachine, enqueueActions } from 'xstate';
377
+
378
+ const machine = createMachine({
379
+ entry: enqueueActions(({ enqueue, check }) => {
380
+ enqueue.assign({ count: 0 });
381
+
382
+ if (check('someGuard')) {
383
+ enqueue.assign({ count: 1 });
384
+ }
385
+
386
+ enqueue('someAction');
387
+ })
388
+ })
389
+ ```
390
+ */
334
391
  function enqueueActions(collect) {
335
392
  function enqueueActions(args, params) {
336
393
  {
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var guards_dist_xstateGuards = require('./raise-c3bbdd3a.cjs.js');
3
+ var guards_dist_xstateGuards = require('./raise-ad8bb7c2.cjs.js');
4
4
 
5
5
  // it's likely-ish that `(TActor & { src: TSrc })['logic']` would be faster
6
6
  // but it's only possible to do it since https://github.com/microsoft/TypeScript/pull/53098 (TS 5.1)
@@ -69,8 +69,8 @@ function resolveAssign(actorScope, snapshot, actionArgs, actionParams, {
69
69
  context: snapshot.context,
70
70
  event: actionArgs.event,
71
71
  spawn: createSpawner(actorScope, snapshot, actionArgs.event, spawnedChildren),
72
- self: actorScope?.self,
73
- system: actorScope?.system
72
+ self: actorScope.self,
73
+ system: actorScope.system
74
74
  };
75
75
  let partialUpdate = {};
76
76
  if (typeof assignment === 'function') {
@@ -93,7 +93,34 @@ function resolveAssign(actorScope, snapshot, actionArgs, actionParams, {
93
93
  /**
94
94
  * Updates the current context of the machine.
95
95
  *
96
- * @param assignment An object that represents the partial context to update.
96
+ * @param assignment An object that represents the partial context to update, or a
97
+ * function that returns an object that represents the partial context to update.
98
+ *
99
+ * @example
100
+ ```ts
101
+ import { createMachine, assign } from 'xstate';
102
+
103
+ const countMachine = createMachine({
104
+ context: {
105
+ count: 0,
106
+ message: ''
107
+ },
108
+ on: {
109
+ inc: {
110
+ actions: assign({
111
+ count: ({ context }) => context.count + 1
112
+ })
113
+ },
114
+ updateMessage: {
115
+ actions: assign(({ context, event }) => {
116
+ return {
117
+ message: event.message.trim()
118
+ }
119
+ })
120
+ }
121
+ }
122
+ });
123
+ ```
97
124
  */
98
125
  function assign(assignment) {
99
126
  function assign(args, params) {
@@ -140,7 +167,9 @@ function assign(assignment) {
140
167
  /** @deprecated use `AnyMachineSnapshot` instead */
141
168
 
142
169
  // TODO: possibly refactor this somehow, use even a simpler type, and maybe even make `machine.options` private or something
143
-
170
+ /**
171
+ * @internal
172
+ */
144
173
  let SpecialTargets = /*#__PURE__*/function (SpecialTargets) {
145
174
  SpecialTargets["Parent"] = "#_parent";
146
175
  SpecialTargets["Internal"] = "#_internal";
@@ -153,6 +182,14 @@ let SpecialTargets = /*#__PURE__*/function (SpecialTargets) {
153
182
 
154
183
  // Based on RxJS types
155
184
 
185
+ /**
186
+ * @internal
187
+ */
188
+
189
+ /**
190
+ * @internal
191
+ */
192
+
156
193
  /**
157
194
  * @deprecated Use `Actor<T>` instead.
158
195
  */
@@ -190,9 +227,9 @@ function resolveSendTo(actorScope, snapshot, args, actionParams, {
190
227
  let targetActorRef;
191
228
  if (typeof resolvedTarget === 'string') {
192
229
  if (resolvedTarget === SpecialTargets.Parent) {
193
- targetActorRef = actorScope?.self._parent;
230
+ targetActorRef = actorScope.self._parent;
194
231
  } else if (resolvedTarget === SpecialTargets.Internal) {
195
- targetActorRef = actorScope?.self;
232
+ targetActorRef = actorScope.self;
196
233
  } else if (resolvedTarget.startsWith('#_')) {
197
234
  // SCXML compatibility: https://www.w3.org/TR/scxml/#SCXMLEventProcessor
198
235
  // #_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.
@@ -204,7 +241,7 @@ function resolveSendTo(actorScope, snapshot, args, actionParams, {
204
241
  throw new Error(`Unable to send event to actor '${resolvedTarget}' from machine '${snapshot.machine.id}'.`);
205
242
  }
206
243
  } else {
207
- targetActorRef = resolvedTarget || actorScope?.self;
244
+ targetActorRef = resolvedTarget || actorScope.self;
208
245
  }
209
246
  return [snapshot, {
210
247
  to: targetActorRef,
@@ -271,9 +308,9 @@ function sendParent(event, options) {
271
308
  return sendTo(SpecialTargets.Parent, event, options);
272
309
  }
273
310
  /**
274
- * Forwards (sends) an event to a specified service.
311
+ * Forwards (sends) an event to the `target` actor.
275
312
  *
276
- * @param target The target service to forward the event to.
313
+ * @param target The target actor to forward the event to.
277
314
  * @param options Options to pass into the send action creator.
278
315
  */
279
316
  function forwardTo(target, options) {
@@ -317,6 +354,26 @@ function resolveEnqueueActions(actorScope, snapshot, args, _actionParams, {
317
354
  });
318
355
  return [snapshot, undefined, actions];
319
356
  }
357
+ /**
358
+ * Creates an action object that will execute actions that are queued by the `enqueue(action)` function.
359
+ *
360
+ * @example
361
+ ```ts
362
+ import { createMachine, enqueueActions } from 'xstate';
363
+
364
+ const machine = createMachine({
365
+ entry: enqueueActions(({ enqueue, check }) => {
366
+ enqueue.assign({ count: 0 });
367
+
368
+ if (check('someGuard')) {
369
+ enqueue.assign({ count: 1 });
370
+ }
371
+
372
+ enqueue('someAction');
373
+ })
374
+ })
375
+ ```
376
+ */
320
377
  function enqueueActions(collect) {
321
378
  function enqueueActions(args, params) {
322
379
  }