xstate 5.0.0-beta.12 → 5.0.0-beta.14

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 (57) hide show
  1. package/actions/dist/xstate-actions.cjs.js +1 -1
  2. package/actions/dist/xstate-actions.development.cjs.js +1 -1
  3. package/actions/dist/xstate-actions.development.esm.js +1 -1
  4. package/actions/dist/xstate-actions.esm.js +1 -1
  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 +1 -1
  12. package/actors/dist/xstate-actors.umd.min.js.map +1 -1
  13. package/dist/{actions-e4c704f3.cjs.js → actions-17c3bcfa.cjs.js} +803 -853
  14. package/dist/{actions-b34f6ce7.esm.js → actions-444a17c3.esm.js} +804 -854
  15. package/dist/{actions-c8b9504d.development.esm.js → actions-60622c0c.development.esm.js} +829 -879
  16. package/dist/{actions-d9c19f35.development.cjs.js → actions-73b8d456.development.cjs.js} +828 -878
  17. package/dist/declarations/src/Machine.d.ts +3 -3
  18. package/dist/declarations/src/SimulatedClock.d.ts +1 -1
  19. package/dist/declarations/src/State.d.ts +4 -10
  20. package/dist/declarations/src/StateMachine.d.ts +8 -13
  21. package/dist/declarations/src/StateNode.d.ts +4 -4
  22. package/dist/declarations/src/actionTypes.d.ts +1 -1
  23. package/dist/declarations/src/actions/assign.d.ts +1 -1
  24. package/dist/declarations/src/actions/cancel.d.ts +2 -2
  25. package/dist/declarations/src/actions/choose.d.ts +2 -2
  26. package/dist/declarations/src/actions/log.d.ts +2 -2
  27. package/dist/declarations/src/actions/pure.d.ts +2 -2
  28. package/dist/declarations/src/actions/raise.d.ts +1 -1
  29. package/dist/declarations/src/actions/send.d.ts +2 -2
  30. package/dist/declarations/src/actions/stop.d.ts +1 -1
  31. package/dist/declarations/src/actions.d.ts +10 -10
  32. package/dist/declarations/src/actors/callback.d.ts +2 -2
  33. package/dist/declarations/src/actors/index.d.ts +6 -6
  34. package/dist/declarations/src/actors/observable.d.ts +8 -6
  35. package/dist/declarations/src/actors/promise.d.ts +4 -3
  36. package/dist/declarations/src/actors/transition.d.ts +4 -4
  37. package/dist/declarations/src/dev/index.d.ts +1 -1
  38. package/dist/declarations/src/guards.d.ts +2 -2
  39. package/dist/declarations/src/index.d.ts +22 -22
  40. package/dist/declarations/src/interpreter.d.ts +18 -18
  41. package/dist/declarations/src/stateUtils.d.ts +8 -10
  42. package/dist/declarations/src/typegenTypes.d.ts +1 -1
  43. package/dist/declarations/src/types.d.ts +29 -39
  44. package/dist/declarations/src/utils.d.ts +9 -9
  45. package/dist/declarations/src/waitFor.d.ts +1 -1
  46. package/dist/xstate.cjs.js +13 -37
  47. package/dist/xstate.development.cjs.js +13 -37
  48. package/dist/xstate.development.esm.js +14 -38
  49. package/dist/xstate.esm.js +14 -38
  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
@@ -1,9 +1,9 @@
1
- import type { StateNode } from './StateNode.ts';
2
- import type { State } from './State.ts';
3
- import type { ActorStatus, Clock, Interpreter } from './interpreter.ts';
4
- import type { StateMachine } from './StateMachine.ts';
5
- import type { LifecycleSignal } from './actors/index.ts';
6
- import { TypegenDisabled, ResolveTypegenMeta, TypegenConstraint, MarkAllImplementationsAsProvided, AreAllImplementationsAssumedToBeProvided } from './typegenTypes.ts';
1
+ import type { StateNode } from "./StateNode.js";
2
+ import type { State } from "./State.js";
3
+ import type { ActorStatus, Clock, Interpreter } from "./interpreter.js";
4
+ import type { StateMachine } from "./StateMachine.js";
5
+ import type { LifecycleSignal } from "./actors/index.js";
6
+ import { TypegenDisabled, ResolveTypegenMeta, TypegenConstraint, MarkAllImplementationsAsProvided, AreAllImplementationsAssumedToBeProvided } from "./typegenTypes.js";
7
7
  export type AnyFunction = (...args: any[]) => any;
8
8
  type ReturnTypeOrValue<T> = T extends AnyFunction ? ReturnType<T> : T;
9
9
  export type IsNever<T> = [T] extends [never] ? true : false;
@@ -76,12 +76,12 @@ export type MachineContext = Record<string, any>;
76
76
  export interface ActionMeta<TEvent extends EventObject, TAction extends ParameterizedObject = ParameterizedObject> extends StateMeta<TEvent> {
77
77
  action: TAction;
78
78
  }
79
- export type Spawner = <T extends ActorBehavior<any, any> | string>(// TODO: read string from machine behavior keys
80
- behavior: T, options?: Partial<{
79
+ export type Spawner = <T extends ActorLogic<any, any> | string>(// TODO: read string from machine logic keys
80
+ logic: T, options?: Partial<{
81
81
  id: string;
82
82
  systemId?: string;
83
83
  input: any;
84
- }>) => T extends ActorBehavior<infer TActorEvent, infer TActorEmitted> ? ActorRef<TActorEvent, TActorEmitted> : ActorRef<any, any>;
84
+ }>) => T extends ActorLogic<infer TActorEvent, infer TActorEmitted, infer _, infer __, infer ___> ? ActorRef<TActorEvent, TActorEmitted> : ActorRef<any, any>;
85
85
  export interface AssignMeta<TExpressionEvent extends EventObject, _TEvent extends EventObject> extends StateMeta<TExpressionEvent> {
86
86
  action: BaseActionObject;
87
87
  event: TExpressionEvent;
@@ -182,17 +182,10 @@ type ExtractWithSimpleSupport<T extends {
182
182
  export type Receiver<TEvent extends EventObject> = (listener: {
183
183
  bivarianceHack(event: TEvent): void;
184
184
  }['bivarianceHack']) => void;
185
- export type InvokeCallback<TEvent extends EventObject = AnyEventObject, TSentEvent extends EventObject = AnyEventObject> = (sendBack: (event: TSentEvent) => void, onReceive: Receiver<TEvent>, { input }: {
185
+ export type InvokeCallback<TEvent extends EventObject = AnyEventObject, TSentEvent extends EventObject = AnyEventObject> = (sendBack: (event: TSentEvent) => void, onReceive: Receiver<TEvent>, { input, system }: {
186
186
  input: any;
187
+ system: AnyActorSystem;
187
188
  }) => (() => void) | Promise<any> | void;
188
- export type ActorBehaviorCreator<TContext extends MachineContext, TEvent extends EventObject, TActorBehavior extends AnyActorBehavior = AnyActorBehavior> = (context: TContext, event: TEvent, meta: {
189
- id: string;
190
- data?: any;
191
- src: string;
192
- event: TEvent;
193
- meta: MetaObject | undefined;
194
- input: any;
195
- }) => TActorBehavior;
196
189
  export interface InvokeMeta {
197
190
  src: string;
198
191
  meta: MetaObject | undefined;
@@ -201,7 +194,7 @@ export interface InvokeDefinition<TContext extends MachineContext, TEvent extend
201
194
  id: string;
202
195
  systemId: string | undefined;
203
196
  /**
204
- * The source of the actor's behavior to be invoked
197
+ * The source of the actor logic to be invoked
205
198
  */
206
199
  src: string;
207
200
  input?: Mapper<TContext, TEvent, any> | any;
@@ -259,7 +252,7 @@ export interface InvokeConfig<TContext extends MachineContext, TEvent extends Ev
259
252
  /**
260
253
  * The source of the machine to be invoked, or the machine itself.
261
254
  */
262
- src: string | ActorBehavior<any, any>;
255
+ src: string | ActorLogic<any, any>;
263
256
  input?: Mapper<TContext, TEvent, any> | any;
264
257
  /**
265
258
  * The transition to take upon the invoked child machine reaching its final top-level state.
@@ -428,8 +421,8 @@ export type DelayConfig<TContext extends MachineContext, TEvent extends EventObj
428
421
  export interface MachineImplementationsSimplified<TContext extends MachineContext, TEvent extends EventObject, TAction extends ParameterizedObject = ParameterizedObject> {
429
422
  guards: Record<string, GuardPredicate<TContext, TEvent>>;
430
423
  actions: ActionFunctionMap<TContext, TEvent, TAction>;
431
- actors: Record<string, AnyActorBehavior | {
432
- src: AnyActorBehavior;
424
+ actors: Record<string, AnyActorLogic | {
425
+ src: AnyActorLogic;
433
426
  input: Mapper<TContext, TEvent, any> | any;
434
427
  }>;
435
428
  delays: DelayFunctionMap<TContext, TEvent>;
@@ -446,8 +439,8 @@ type MachineImplementationsGuards<TContext extends MachineContext, TResolvedType
446
439
  [K in keyof TEventsCausingGuards]?: GuardPredicate<TContext, Cast<Prop<TIndexedEvents, TEventsCausingGuards[K]>, EventObject>>;
447
440
  };
448
441
  type MachineImplementationsActors<TContext extends MachineContext, TResolvedTypesMeta, TEventsCausingActors = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'eventsCausingActors'>, TIndexedEvents = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'indexedEvents'>, _TInvokeSrcNameMap = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'invokeSrcNameMap'>> = {
449
- [K in keyof TEventsCausingActors]?: AnyActorBehavior | {
450
- src: AnyActorBehavior;
442
+ [K in keyof TEventsCausingActors]?: AnyActorLogic | {
443
+ src: AnyActorLogic;
451
444
  input: Mapper<TContext, Cast<Prop<TIndexedEvents, TEventsCausingActors[K]>, EventObject>, any> | any;
452
445
  };
453
446
  };
@@ -782,9 +775,7 @@ export interface StateLike<TContext extends MachineContext> {
782
775
  export interface StateConfig<TContext extends MachineContext, TEvent extends EventObject> {
783
776
  value: StateValue;
784
777
  context: TContext;
785
- event: TEvent;
786
778
  historyValue?: HistoryValue<TContext, TEvent>;
787
- actions?: BaseActionObject[];
788
779
  meta?: any;
789
780
  configuration?: Array<StateNode<TContext, TEvent>>;
790
781
  transitions?: Array<TransitionDefinition<TContext, TEvent>>;
@@ -795,7 +786,7 @@ export interface StateConfig<TContext extends MachineContext, TEvent extends Eve
795
786
  machine?: StateMachine<TContext, TEvent, any, any, any>;
796
787
  _internalQueue?: Array<TEvent>;
797
788
  }
798
- export interface InterpreterOptions<_TActorBehavior extends AnyActorBehavior> {
789
+ export interface InterpreterOptions<_TActorLogic extends AnyActorLogic> {
799
790
  /**
800
791
  * Whether state actions should be executed immediately upon transition. Defaults to `true`.
801
792
  */
@@ -855,7 +846,6 @@ export interface Subscribable<T> extends InteropSubscribable<T> {
855
846
  subscribe(observer: Observer<T>): Subscription;
856
847
  subscribe(next: (value: T) => void, error?: (error: any) => void, complete?: () => void): Subscription;
857
848
  }
858
- export type Spawnable = AnyStateMachine | PromiseLike<any> | InvokeCallback | InteropObservable<any> | Subscribable<any> | ActorBehavior<any, any>;
859
849
  export type ExtractEvent<TEvent extends EventObject, TEventType extends TEvent['type']> = TEvent extends any ? TEventType extends TEvent['type'] ? TEvent : never : never;
860
850
  export interface BaseActorRef<TEvent extends EventObject> {
861
851
  send: (event: TEvent) => void;
@@ -883,9 +873,9 @@ export interface ActorRef<TEvent extends EventObject, TSnapshot = any> extends S
883
873
  export type AnyActorRef = ActorRef<any, any>;
884
874
  export type ActorRefFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<infer TContext, infer TEvent, any, any, infer TResolvedTypesMeta> ? ActorRef<TEvent, State<TContext, TEvent, AreAllImplementationsAssumedToBeProvided<TResolvedTypesMeta> extends false ? MarkAllImplementationsAsProvided<TResolvedTypesMeta> : TResolvedTypesMeta>> : R extends Promise<infer U> ? ActorRef<{
885
875
  type: string;
886
- }, U | undefined> : R extends ActorBehavior<infer TEvent, infer TSnapshot> ? ActorRef<TEvent, TSnapshot> : never : never;
876
+ }, U | undefined> : R extends ActorLogic<infer TEvent, infer TSnapshot> ? ActorRef<TEvent, TSnapshot> : never : never;
887
877
  export type DevToolsAdapter = (service: AnyInterpreter) => void;
888
- export type InterpreterFrom<T extends AnyStateMachine | ((...args: any[]) => AnyStateMachine)> = ReturnTypeOrValue<T> extends StateMachine<infer TContext, infer TEvent, any, any, infer TResolvedTypesMeta> ? Interpreter<ActorBehavior<TEvent, State<TContext, TEvent, TResolvedTypesMeta>, State<TContext, TEvent, TResolvedTypesMeta>, PersistedMachineState<State<TContext, TEvent, TResolvedTypesMeta>>>> : never;
878
+ export type InterpreterFrom<T extends AnyStateMachine | ((...args: any[]) => AnyStateMachine)> = ReturnTypeOrValue<T> extends StateMachine<infer TContext, infer TEvent, any, any, infer TResolvedTypesMeta> ? Interpreter<ActorLogic<TEvent, State<TContext, TEvent, TResolvedTypesMeta>, State<TContext, TEvent, TResolvedTypesMeta>, PersistedMachineState<State<TContext, TEvent, TResolvedTypesMeta>>>> : never;
889
879
  export type MachineImplementationsFrom<T extends AnyStateMachine | ((...args: any[]) => AnyStateMachine), TRequireMissingImplementations extends boolean = false> = ReturnTypeOrValue<T> extends StateMachine<infer TContext, infer TEvent, any, any, infer TResolvedTypesMeta> ? InternalMachineImplementations<TContext, TEvent, TResolvedTypesMeta, TRequireMissingImplementations> : never;
890
880
  export type __ResolvedTypesMetaFrom<T> = T extends StateMachine<any, any, any, infer TResolvedTypesMeta> ? TResolvedTypesMeta : never;
891
881
  export type EventOfMachine<TMachine extends AnyStateMachine> = TMachine extends StateMachine<any, infer E, any, any, any> ? E : never;
@@ -899,7 +889,7 @@ export interface ActorContext<TEvent extends EventObject, TSnapshot, TSystem ext
899
889
  stopChild: (child: AnyActorRef) => void;
900
890
  }
901
891
  export type AnyActorContext = ActorContext<any, any, any>;
902
- export interface ActorBehavior<TEvent extends EventObject, TSnapshot = any, TInternalState = any,
892
+ export interface ActorLogic<TEvent extends EventObject, TSnapshot = any, TInternalState = TSnapshot,
903
893
  /**
904
894
  * Serialized internal state used for persistence & restoration
905
895
  */
@@ -919,14 +909,14 @@ TPersisted = TInternalState, TSystem extends ActorSystem<any> = ActorSystem<any>
919
909
  */
920
910
  getPersistedState?: (state: TInternalState) => TPersisted;
921
911
  }
922
- export type AnyActorBehavior = ActorBehavior<any, any, any, any>;
923
- export type SnapshotFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends ActorRef<infer _, infer TSnapshot> ? TSnapshot : R extends Interpreter<infer TBehavior> ? SnapshotFrom<TBehavior> : R extends StateMachine<infer _, infer __, infer ___, infer ____, infer _____> ? StateFrom<R> : R extends ActorBehavior<infer _, infer TSnapshot, infer __, infer ___, infer ____> ? TSnapshot : R extends ActorContext<infer _, infer TSnapshot, infer __> ? TSnapshot : never : never;
924
- export type EventFromBehavior<TBehavior extends ActorBehavior<any, any>> = TBehavior extends ActorBehavior<infer TEvent, infer _> ? TEvent : never;
925
- export type PersistedStateFrom<TBehavior extends ActorBehavior<any, any>> = TBehavior extends ActorBehavior<infer _TEvent, infer _TSnapshot, infer _TInternalState, infer TPersisted> ? TPersisted : never;
926
- export type InternalStateFrom<TBehavior extends ActorBehavior<any, any>> = TBehavior extends ActorBehavior<infer _TEvent, infer _TSnapshot, infer TInternalState, infer _TPersisted> ? TInternalState : never;
912
+ export type AnyActorLogic = ActorLogic<any, any, any, any>;
913
+ export type SnapshotFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends ActorRef<infer _, infer TSnapshot> ? TSnapshot : R extends Interpreter<infer TLogic> ? SnapshotFrom<TLogic> : R extends StateMachine<infer _, infer __, infer ___, infer ____, infer _____> ? StateFrom<R> : R extends ActorLogic<infer _, infer TSnapshot, infer __, infer ___, infer ____> ? TSnapshot : R extends ActorContext<infer _, infer TSnapshot, infer __> ? TSnapshot : never : never;
914
+ export type EventFromLogic<TLogic extends ActorLogic<any, any>> = TLogic extends ActorLogic<infer TEvent, infer _, infer __, infer ___, infer ____> ? TEvent : never;
915
+ export type PersistedStateFrom<TLogic extends ActorLogic<any, any>> = TLogic extends ActorLogic<infer _TEvent, infer _TSnapshot, infer _TInternalState, infer TPersisted> ? TPersisted : never;
916
+ export type InternalStateFrom<TLogic extends ActorLogic<any, any>> = TLogic extends ActorLogic<infer _TEvent, infer _TSnapshot, infer TInternalState, infer _TPersisted> ? TInternalState : never;
927
917
  type ResolveEventType<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<infer _, infer TEvent, infer __, infer ___, infer ____> ? TEvent : R extends State<infer _, infer TEvent, infer __> ? TEvent : R extends ActorRef<infer TEvent, infer _> ? TEvent : never : never;
928
918
  export type EventFrom<T, K extends Prop<TEvent, 'type'> = never, TEvent extends EventObject = ResolveEventType<T>> = IsNever<K> extends true ? TEvent : ExtractEvent<TEvent, K>;
929
- export type ContextFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<infer TContext, infer _, infer __, infer ___, infer ____> ? TContext : R extends State<infer TContext, infer _, infer __> ? TContext : R extends Interpreter<infer TBehavior> ? TBehavior extends StateMachine<infer TContext, infer _> ? TContext : never : never : never;
919
+ export type ContextFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<infer TContext, infer _, infer __, infer ___, infer ____> ? TContext : R extends State<infer TContext, infer _, infer __> ? TContext : R extends Interpreter<infer TActorLogic> ? TActorLogic extends StateMachine<infer TContext, infer _> ? TContext : never : never : never;
930
920
  export type InferEvent<E extends EventObject> = {
931
921
  [T in E['type']]: {
932
922
  type: T;
@@ -937,7 +927,6 @@ export type InferEvent<E extends EventObject> = {
937
927
  export type TODO = any;
938
928
  export type StateValueFrom<TMachine extends AnyStateMachine> = Parameters<StateFrom<TMachine>['matches']>[0];
939
929
  export type TagsFrom<TMachine extends AnyStateMachine> = Parameters<StateFrom<TMachine>['hasTag']>[0];
940
- export type StateFromMachine<TMachine extends AnyStateMachine> = TMachine['initialState'];
941
930
  export interface ActorSystemInfo {
942
931
  actors: Record<string, AnyActorRef>;
943
932
  }
@@ -948,7 +937,8 @@ export interface ActorSystem<T extends ActorSystemInfo> {
948
937
  _set: <K extends keyof T['actors']>(key: K, actorRef: T['actors'][K]) => void;
949
938
  get: <K extends keyof T['actors']>(key: K) => T['actors'][K] | undefined;
950
939
  }
951
- export type PersistedMachineState<TState extends AnyState> = Pick<TState, 'value' | 'output' | 'context' | 'event' | 'done' | 'historyValue'> & {
940
+ export type AnyActorSystem = ActorSystem<any>;
941
+ export type PersistedMachineState<TState extends AnyState> = Pick<TState, 'value' | 'output' | 'context' | 'done' | 'historyValue'> & {
952
942
  children: {
953
943
  [K in keyof TState['children']]: {
954
944
  state: any;
@@ -1,7 +1,7 @@
1
- import { AnyActorBehavior, AnyState } from './index.ts';
2
- import { NULL_EVENT } from './constants.ts';
3
- import type { StateNode } from './StateNode.ts';
4
- import type { ActorBehavior, AnyEventObject, EventObject, EventType, InvokeConfig, MachineContext, Mapper, Observer, PropertyMapper, ErrorEvent, SingleOrArray, StateLike, StateValue, Subscribable, TransitionConfig, TransitionConfigTarget } from './types.ts';
1
+ import { AnyActorLogic, AnyState } from "./index.js";
2
+ import { NULL_EVENT } from "./constants.js";
3
+ import type { StateNode } from "./StateNode.js";
4
+ import type { ActorLogic, AnyEventObject, EventObject, EventType, InvokeConfig, MachineContext, Mapper, Observer, PropertyMapper, ErrorEvent, SingleOrArray, StateLike, StateValue, Subscribable, TransitionConfig, TransitionConfigTarget } from "./types.js";
5
5
  export declare function keys<T extends object>(value: T): Array<keyof T & string>;
6
6
  export declare function matchesState(parentStateId: StateValue, childStateId: StateValue, delimiter?: string): boolean;
7
7
  export declare function toStatePath(stateId: string | string[], delimiter: string): string[];
@@ -30,7 +30,7 @@ export declare function toArray<T>(value: T[] | T | undefined): T[];
30
30
  export declare function mapContext<TContext extends MachineContext, TEvent extends EventObject>(mapper: Mapper<TContext, TEvent, any> | PropertyMapper<TContext, TEvent, any>, context: TContext, event: TEvent): any;
31
31
  export declare function isBuiltInEvent(eventType: EventType): boolean;
32
32
  export declare function isPromiseLike(value: any): value is PromiseLike<any>;
33
- export declare function isBehavior(value: any): value is ActorBehavior<any, any>;
33
+ export declare function isActorLogic(value: any): value is ActorLogic<any, any>;
34
34
  export declare function partition<T, A extends T, B extends T>(items: T[], predicate: (item: T) => item is A): [A[], B[]];
35
35
  export declare function isArray(value: any): value is any[];
36
36
  export declare function isFunction(value: any): value is Function;
@@ -43,13 +43,13 @@ export declare function toTransitionConfigArray<TContext extends MachineContext,
43
43
  }>;
44
44
  export declare function normalizeTarget<TContext extends MachineContext, TEvent extends EventObject>(target: SingleOrArray<string | StateNode<TContext, TEvent>> | undefined): Array<string | StateNode<TContext, TEvent>> | undefined;
45
45
  export declare function reportUnhandledExceptionOnInvocation(originalError: any, currentError: any, id: string): void;
46
- export declare function toInvokeConfig<TContext extends MachineContext, TEvent extends EventObject>(invocable: InvokeConfig<TContext, TEvent> | string | ActorBehavior<any, any>, id: string): InvokeConfig<TContext, TEvent>;
46
+ export declare function toInvokeConfig<TContext extends MachineContext, TEvent extends EventObject>(invocable: InvokeConfig<TContext, TEvent> | string | ActorLogic<any, any>, id: string): InvokeConfig<TContext, TEvent>;
47
47
  export declare function toObserver<T>(nextHandler?: Observer<T> | ((value: T) => void), errorHandler?: (error: any) => void, completionHandler?: () => void): Observer<T>;
48
48
  export declare function createInvokeId(stateNodeId: string, index: number): string;
49
- export declare function resolveReferencedActor(referenced: AnyActorBehavior | {
50
- src: AnyActorBehavior;
49
+ export declare function resolveReferencedActor(referenced: AnyActorLogic | {
50
+ src: AnyActorLogic;
51
51
  input: Mapper<any, any, any> | any;
52
52
  } | undefined): {
53
- src: AnyActorBehavior;
53
+ src: AnyActorLogic;
54
54
  input: Mapper<any, any, any> | any;
55
55
  } | undefined;
@@ -1,4 +1,4 @@
1
- import { ActorRef, SnapshotFrom } from './types.ts';
1
+ import { ActorRef, SnapshotFrom } from "./types.js";
2
2
  interface WaitForOptions {
3
3
  /**
4
4
  * How long to wait before rejecting, if no emitted
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var actors_dist_xstateActors = require('./actions-e4c704f3.cjs.js');
5
+ var actors_dist_xstateActors = require('./actions-17c3bcfa.cjs.js');
6
6
  require('../dev/dist/xstate-dev.cjs.js');
7
7
 
8
8
  const EMPTY_OBJECT = {};
@@ -173,15 +173,15 @@ class StateNode {
173
173
  }
174
174
 
175
175
  /**
176
- * The behaviors invoked as actors by this state node.
176
+ * The logic invoked as actors by this state node.
177
177
  */
178
178
  get invoke() {
179
179
  return actors_dist_xstateActors.memo(this, 'invoke', () => actors_dist_xstateActors.toArray(this.config.invoke).map((invocable, i) => {
180
180
  const generatedId = actors_dist_xstateActors.createInvokeId(this.id, i);
181
181
  const invokeConfig = actors_dist_xstateActors.toInvokeConfig(invocable, generatedId);
182
182
  const resolvedId = invokeConfig.id || generatedId;
183
+ const src = invokeConfig.src;
183
184
  const {
184
- src,
185
185
  systemId
186
186
  } = invokeConfig;
187
187
  const resolvedSrc = actors_dist_xstateActors.isString(src) ? src : !('type' in src) ? resolvedId : src;
@@ -451,15 +451,14 @@ class StateMachine {
451
451
  * @param state The current State instance or state value
452
452
  * @param event The received event
453
453
  */
454
- transition(state = this.initialState, event, actorCtx) {
455
- const currentState = state instanceof actors_dist_xstateActors.State ? state : this.resolveStateValue(state);
454
+ transition(state, event, actorCtx) {
456
455
  // TODO: handle error events in a better way
457
- if (actors_dist_xstateActors.isErrorEvent(event) && !currentState.nextEvents.some(nextEvent => nextEvent === event.type)) {
456
+ if (actors_dist_xstateActors.isErrorEvent(event) && !state.nextEvents.some(nextEvent => nextEvent === event.type)) {
458
457
  throw event.data;
459
458
  }
460
459
  const {
461
460
  state: nextState
462
- } = actors_dist_xstateActors.macrostep(currentState, event, actorCtx);
461
+ } = actors_dist_xstateActors.macrostep(state, event, actorCtx);
463
462
  return nextState;
464
463
  }
465
464
 
@@ -470,7 +469,7 @@ class StateMachine {
470
469
  * @param state The current state
471
470
  * @param event The received event
472
471
  */
473
- microstep(state = this.initialState, event, actorCtx) {
472
+ microstep(state, event, actorCtx) {
474
473
  return actors_dist_xstateActors.macrostep(state, event, actorCtx).microstates;
475
474
  }
476
475
  getTransitionData(state, event) {
@@ -488,33 +487,19 @@ class StateMachine {
488
487
  value: {},
489
488
  // TODO: this is computed in state constructor
490
489
  context,
491
- event: actors_dist_xstateActors.createInitEvent({}),
492
- actions: [],
493
490
  meta: undefined,
494
491
  configuration: config,
495
492
  transitions: [],
496
493
  children: {}
497
494
  }));
498
495
  preInitial._initial = true;
499
- preInitial.actions.unshift(...actions);
500
496
  if (actorCtx) {
501
- const {
502
- nextState
503
- } = actors_dist_xstateActors.resolveActionsAndContext(actions, actors_dist_xstateActors.initEvent, preInitial, actorCtx);
497
+ const [nextState] = actors_dist_xstateActors.resolveActionsAndContext(actions, actors_dist_xstateActors.initEvent, preInitial, actorCtx);
504
498
  preInitial.children = nextState.children;
505
- preInitial.actions = nextState.actions;
506
499
  }
507
500
  return preInitial;
508
501
  }
509
502
 
510
- /**
511
- * The initial State instance, which includes all actions to be executed from
512
- * entering the initial state.
513
- */
514
- get initialState() {
515
- return this.getInitialState();
516
- }
517
-
518
503
  /**
519
504
  * Returns the initial `State` instance, with reference to `self` as an `ActorRef`.
520
505
  */
@@ -523,16 +508,12 @@ class StateMachine {
523
508
 
524
509
  const preInitialState = this.getPreInitialState(actorCtx, input);
525
510
  const nextState = actors_dist_xstateActors.microstep([], preInitialState, actorCtx, initEvent);
526
- nextState.actions.unshift(...preInitialState.actions);
527
511
  const {
528
512
  state: macroState
529
513
  } = actors_dist_xstateActors.macrostep(nextState, initEvent, actorCtx);
530
514
  return macroState;
531
515
  }
532
516
  start(state, actorCtx) {
533
- state.actions.forEach(action => {
534
- action.execute?.(actorCtx);
535
- });
536
517
  Object.values(state.children).forEach(child => {
537
518
  if (child.status === 0) {
538
519
  try {
@@ -567,11 +548,7 @@ class StateMachine {
567
548
  return actors_dist_xstateActors.getPersistedState(state);
568
549
  }
569
550
  createState(stateConfig) {
570
- const state = stateConfig instanceof actors_dist_xstateActors.State ? stateConfig : new actors_dist_xstateActors.State(stateConfig, this);
571
- const {
572
- nextState: resolvedState
573
- } = actors_dist_xstateActors.resolveActionsAndContext(state.actions, state.event, state, undefined);
574
- return resolvedState;
551
+ return stateConfig instanceof actors_dist_xstateActors.State ? stateConfig : new actors_dist_xstateActors.State(stateConfig, this);
575
552
  }
576
553
  getStatus(state) {
577
554
  return state.done ? {
@@ -587,12 +564,12 @@ class StateMachine {
587
564
  const actorData = state.children[actorId];
588
565
  const childState = actorData.state;
589
566
  const src = actorData.src;
590
- const behavior = src ? actors_dist_xstateActors.resolveReferencedActor(this.options.actors[src])?.src : undefined;
591
- if (!behavior) {
567
+ const logic = src ? actors_dist_xstateActors.resolveReferencedActor(this.options.actors[src])?.src : undefined;
568
+ if (!logic) {
592
569
  return;
593
570
  }
594
- const actorState = behavior.restoreState?.(childState, _actorCtx);
595
- const actorRef = actors_dist_xstateActors.interpret(behavior, {
571
+ const actorState = logic.restoreState?.(childState, _actorCtx);
572
+ const actorRef = actors_dist_xstateActors.interpret(logic, {
596
573
  id: actorId,
597
574
  state: actorState
598
575
  });
@@ -626,7 +603,6 @@ class StateMachine {
626
603
  });
627
604
  }
628
605
  });
629
- restoredState.actions = [];
630
606
  return restoredState;
631
607
  }
632
608
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var actors_dist_xstateActors = require('./actions-d9c19f35.development.cjs.js');
5
+ var actors_dist_xstateActors = require('./actions-73b8d456.development.cjs.js');
6
6
  require('../dev/dist/xstate-dev.development.cjs.js');
7
7
 
8
8
  const EMPTY_OBJECT = {};
@@ -173,15 +173,15 @@ class StateNode {
173
173
  }
174
174
 
175
175
  /**
176
- * The behaviors invoked as actors by this state node.
176
+ * The logic invoked as actors by this state node.
177
177
  */
178
178
  get invoke() {
179
179
  return actors_dist_xstateActors.memo(this, 'invoke', () => actors_dist_xstateActors.toArray(this.config.invoke).map((invocable, i) => {
180
180
  const generatedId = actors_dist_xstateActors.createInvokeId(this.id, i);
181
181
  const invokeConfig = actors_dist_xstateActors.toInvokeConfig(invocable, generatedId);
182
182
  const resolvedId = invokeConfig.id || generatedId;
183
+ const src = invokeConfig.src;
183
184
  const {
184
- src,
185
185
  systemId
186
186
  } = invokeConfig;
187
187
  const resolvedSrc = actors_dist_xstateActors.isString(src) ? src : !('type' in src) ? resolvedId : src;
@@ -451,15 +451,14 @@ class StateMachine {
451
451
  * @param state The current State instance or state value
452
452
  * @param event The received event
453
453
  */
454
- transition(state = this.initialState, event, actorCtx) {
455
- const currentState = state instanceof actors_dist_xstateActors.State ? state : this.resolveStateValue(state);
454
+ transition(state, event, actorCtx) {
456
455
  // TODO: handle error events in a better way
457
- if (actors_dist_xstateActors.isErrorEvent(event) && !currentState.nextEvents.some(nextEvent => nextEvent === event.type)) {
456
+ if (actors_dist_xstateActors.isErrorEvent(event) && !state.nextEvents.some(nextEvent => nextEvent === event.type)) {
458
457
  throw event.data;
459
458
  }
460
459
  const {
461
460
  state: nextState
462
- } = actors_dist_xstateActors.macrostep(currentState, event, actorCtx);
461
+ } = actors_dist_xstateActors.macrostep(state, event, actorCtx);
463
462
  return nextState;
464
463
  }
465
464
 
@@ -470,7 +469,7 @@ class StateMachine {
470
469
  * @param state The current state
471
470
  * @param event The received event
472
471
  */
473
- microstep(state = this.initialState, event, actorCtx) {
472
+ microstep(state, event, actorCtx) {
474
473
  return actors_dist_xstateActors.macrostep(state, event, actorCtx).microstates;
475
474
  }
476
475
  getTransitionData(state, event) {
@@ -488,33 +487,19 @@ class StateMachine {
488
487
  value: {},
489
488
  // TODO: this is computed in state constructor
490
489
  context,
491
- event: actors_dist_xstateActors.createInitEvent({}),
492
- actions: [],
493
490
  meta: undefined,
494
491
  configuration: config,
495
492
  transitions: [],
496
493
  children: {}
497
494
  }));
498
495
  preInitial._initial = true;
499
- preInitial.actions.unshift(...actions);
500
496
  if (actorCtx) {
501
- const {
502
- nextState
503
- } = actors_dist_xstateActors.resolveActionsAndContext(actions, actors_dist_xstateActors.initEvent, preInitial, actorCtx);
497
+ const [nextState] = actors_dist_xstateActors.resolveActionsAndContext(actions, actors_dist_xstateActors.initEvent, preInitial, actorCtx);
504
498
  preInitial.children = nextState.children;
505
- preInitial.actions = nextState.actions;
506
499
  }
507
500
  return preInitial;
508
501
  }
509
502
 
510
- /**
511
- * The initial State instance, which includes all actions to be executed from
512
- * entering the initial state.
513
- */
514
- get initialState() {
515
- return this.getInitialState();
516
- }
517
-
518
503
  /**
519
504
  * Returns the initial `State` instance, with reference to `self` as an `ActorRef`.
520
505
  */
@@ -523,16 +508,12 @@ class StateMachine {
523
508
 
524
509
  const preInitialState = this.getPreInitialState(actorCtx, input);
525
510
  const nextState = actors_dist_xstateActors.microstep([], preInitialState, actorCtx, initEvent);
526
- nextState.actions.unshift(...preInitialState.actions);
527
511
  const {
528
512
  state: macroState
529
513
  } = actors_dist_xstateActors.macrostep(nextState, initEvent, actorCtx);
530
514
  return macroState;
531
515
  }
532
516
  start(state, actorCtx) {
533
- state.actions.forEach(action => {
534
- action.execute?.(actorCtx);
535
- });
536
517
  Object.values(state.children).forEach(child => {
537
518
  if (child.status === 0) {
538
519
  try {
@@ -567,11 +548,7 @@ class StateMachine {
567
548
  return actors_dist_xstateActors.getPersistedState(state);
568
549
  }
569
550
  createState(stateConfig) {
570
- const state = stateConfig instanceof actors_dist_xstateActors.State ? stateConfig : new actors_dist_xstateActors.State(stateConfig, this);
571
- const {
572
- nextState: resolvedState
573
- } = actors_dist_xstateActors.resolveActionsAndContext(state.actions, state.event, state, undefined);
574
- return resolvedState;
551
+ return stateConfig instanceof actors_dist_xstateActors.State ? stateConfig : new actors_dist_xstateActors.State(stateConfig, this);
575
552
  }
576
553
  getStatus(state) {
577
554
  return state.done ? {
@@ -587,12 +564,12 @@ class StateMachine {
587
564
  const actorData = state.children[actorId];
588
565
  const childState = actorData.state;
589
566
  const src = actorData.src;
590
- const behavior = src ? actors_dist_xstateActors.resolveReferencedActor(this.options.actors[src])?.src : undefined;
591
- if (!behavior) {
567
+ const logic = src ? actors_dist_xstateActors.resolveReferencedActor(this.options.actors[src])?.src : undefined;
568
+ if (!logic) {
592
569
  return;
593
570
  }
594
- const actorState = behavior.restoreState?.(childState, _actorCtx);
595
- const actorRef = actors_dist_xstateActors.interpret(behavior, {
571
+ const actorState = logic.restoreState?.(childState, _actorCtx);
572
+ const actorRef = actors_dist_xstateActors.interpret(logic, {
596
573
  id: actorId,
597
574
  state: actorState
598
575
  });
@@ -626,7 +603,6 @@ class StateMachine {
626
603
  });
627
604
  }
628
605
  });
629
- restoredState.actions = [];
630
606
  return restoredState;
631
607
  }
632
608
 
@@ -1,5 +1,5 @@
1
- import { m as mapValues, t as toActionObjects, a as toArray, f as formatTransitions, b as toTransitionConfigArray, N as NULL_EVENT, c as formatTransition, d as memo, e as evaluateGuard, g as flatten, h as createInvokeId, i as isString, j as invoke, k as getDelayedTransitions, l as formatInitialTransition, n as getCandidates, o as toInvokeConfig, p as createSpawner, S as STATE_DELIMITER, q as getConfiguration, r as getStateNodes, s as resolveStateValue, u as isInFinalState, v as State, w as isErrorEvent, x as macrostep, y as transitionNode, z as getInitialConfiguration, A as createInitEvent, B as resolveActionsAndContext, C as microstep, D as error, E as isStateId, F as getStateNodeByPath, G as getPersistedState, H as resolveReferencedActor, I as interpret, J as initEvent, K as matchesState } from './actions-c8b9504d.development.esm.js';
2
- export { a9 as ActionTypes, P as Interpreter, Q as InterpreterStatus, aa as SpecialTargets, v as State, a7 as and, T as assign, U as cancel, V as choose, R as doneInvoke, O as forwardTo, a2 as fromCallback, a3 as fromEventObservable, a1 as fromObservable, a0 as fromPromise, a4 as fromTransition, r as getStateNodes, I as interpret, W as log, K as matchesState, a6 as not, a8 as or, _ as pathToStateValue, X as pure, Y as raise, M as sendParent, L as sendTo, a5 as stateIn, Z as stop, $ as toObserver } from './actions-c8b9504d.development.esm.js';
1
+ import { m as mapValues, t as toActionObjects, a as toArray, f as formatTransitions, b as toTransitionConfigArray, N as NULL_EVENT, c as formatTransition, d as memo, e as evaluateGuard, g as flatten, h as createInvokeId, i as isString, j as invoke, k as getDelayedTransitions, l as formatInitialTransition, n as getCandidates, o as toInvokeConfig, p as createSpawner, S as STATE_DELIMITER, q as getConfiguration, r as getStateNodes, s as resolveStateValue, u as isInFinalState, v as State, w as isErrorEvent, x as macrostep, y as transitionNode, z as getInitialConfiguration, A as resolveActionsAndContext, B as microstep, C as error, D as isStateId, E as getStateNodeByPath, F as getPersistedState, G as resolveReferencedActor, H as interpret, I as createInitEvent, J as initEvent, K as matchesState } from './actions-60622c0c.development.esm.js';
2
+ export { a9 as ActionTypes, P as Interpreter, Q as InterpreterStatus, aa as SpecialTargets, v as State, a7 as and, T as assign, U as cancel, V as choose, R as doneInvoke, O as forwardTo, a2 as fromCallback, a3 as fromEventObservable, a1 as fromObservable, a0 as fromPromise, a4 as fromTransition, r as getStateNodes, H as interpret, W as log, K as matchesState, a6 as not, a8 as or, _ as pathToStateValue, X as pure, Y as raise, M as sendParent, L as sendTo, a5 as stateIn, Z as stop, $ as toObserver } from './actions-60622c0c.development.esm.js';
3
3
  import '../dev/dist/xstate-dev.development.esm.js';
4
4
 
5
5
  const EMPTY_OBJECT = {};
@@ -170,15 +170,15 @@ class StateNode {
170
170
  }
171
171
 
172
172
  /**
173
- * The behaviors invoked as actors by this state node.
173
+ * The logic invoked as actors by this state node.
174
174
  */
175
175
  get invoke() {
176
176
  return memo(this, 'invoke', () => toArray(this.config.invoke).map((invocable, i) => {
177
177
  const generatedId = createInvokeId(this.id, i);
178
178
  const invokeConfig = toInvokeConfig(invocable, generatedId);
179
179
  const resolvedId = invokeConfig.id || generatedId;
180
+ const src = invokeConfig.src;
180
181
  const {
181
- src,
182
182
  systemId
183
183
  } = invokeConfig;
184
184
  const resolvedSrc = isString(src) ? src : !('type' in src) ? resolvedId : src;
@@ -448,15 +448,14 @@ class StateMachine {
448
448
  * @param state The current State instance or state value
449
449
  * @param event The received event
450
450
  */
451
- transition(state = this.initialState, event, actorCtx) {
452
- const currentState = state instanceof State ? state : this.resolveStateValue(state);
451
+ transition(state, event, actorCtx) {
453
452
  // TODO: handle error events in a better way
454
- if (isErrorEvent(event) && !currentState.nextEvents.some(nextEvent => nextEvent === event.type)) {
453
+ if (isErrorEvent(event) && !state.nextEvents.some(nextEvent => nextEvent === event.type)) {
455
454
  throw event.data;
456
455
  }
457
456
  const {
458
457
  state: nextState
459
- } = macrostep(currentState, event, actorCtx);
458
+ } = macrostep(state, event, actorCtx);
460
459
  return nextState;
461
460
  }
462
461
 
@@ -467,7 +466,7 @@ class StateMachine {
467
466
  * @param state The current state
468
467
  * @param event The received event
469
468
  */
470
- microstep(state = this.initialState, event, actorCtx) {
469
+ microstep(state, event, actorCtx) {
471
470
  return macrostep(state, event, actorCtx).microstates;
472
471
  }
473
472
  getTransitionData(state, event) {
@@ -485,33 +484,19 @@ class StateMachine {
485
484
  value: {},
486
485
  // TODO: this is computed in state constructor
487
486
  context,
488
- event: createInitEvent({}),
489
- actions: [],
490
487
  meta: undefined,
491
488
  configuration: config,
492
489
  transitions: [],
493
490
  children: {}
494
491
  }));
495
492
  preInitial._initial = true;
496
- preInitial.actions.unshift(...actions);
497
493
  if (actorCtx) {
498
- const {
499
- nextState
500
- } = resolveActionsAndContext(actions, initEvent, preInitial, actorCtx);
494
+ const [nextState] = resolveActionsAndContext(actions, initEvent, preInitial, actorCtx);
501
495
  preInitial.children = nextState.children;
502
- preInitial.actions = nextState.actions;
503
496
  }
504
497
  return preInitial;
505
498
  }
506
499
 
507
- /**
508
- * The initial State instance, which includes all actions to be executed from
509
- * entering the initial state.
510
- */
511
- get initialState() {
512
- return this.getInitialState();
513
- }
514
-
515
500
  /**
516
501
  * Returns the initial `State` instance, with reference to `self` as an `ActorRef`.
517
502
  */
@@ -520,16 +505,12 @@ class StateMachine {
520
505
 
521
506
  const preInitialState = this.getPreInitialState(actorCtx, input);
522
507
  const nextState = microstep([], preInitialState, actorCtx, initEvent);
523
- nextState.actions.unshift(...preInitialState.actions);
524
508
  const {
525
509
  state: macroState
526
510
  } = macrostep(nextState, initEvent, actorCtx);
527
511
  return macroState;
528
512
  }
529
513
  start(state, actorCtx) {
530
- state.actions.forEach(action => {
531
- action.execute?.(actorCtx);
532
- });
533
514
  Object.values(state.children).forEach(child => {
534
515
  if (child.status === 0) {
535
516
  try {
@@ -564,11 +545,7 @@ class StateMachine {
564
545
  return getPersistedState(state);
565
546
  }
566
547
  createState(stateConfig) {
567
- const state = stateConfig instanceof State ? stateConfig : new State(stateConfig, this);
568
- const {
569
- nextState: resolvedState
570
- } = resolveActionsAndContext(state.actions, state.event, state, undefined);
571
- return resolvedState;
548
+ return stateConfig instanceof State ? stateConfig : new State(stateConfig, this);
572
549
  }
573
550
  getStatus(state) {
574
551
  return state.done ? {
@@ -584,12 +561,12 @@ class StateMachine {
584
561
  const actorData = state.children[actorId];
585
562
  const childState = actorData.state;
586
563
  const src = actorData.src;
587
- const behavior = src ? resolveReferencedActor(this.options.actors[src])?.src : undefined;
588
- if (!behavior) {
564
+ const logic = src ? resolveReferencedActor(this.options.actors[src])?.src : undefined;
565
+ if (!logic) {
589
566
  return;
590
567
  }
591
- const actorState = behavior.restoreState?.(childState, _actorCtx);
592
- const actorRef = interpret(behavior, {
568
+ const actorState = logic.restoreState?.(childState, _actorCtx);
569
+ const actorRef = interpret(logic, {
593
570
  id: actorId,
594
571
  state: actorState
595
572
  });
@@ -623,7 +600,6 @@ class StateMachine {
623
600
  });
624
601
  }
625
602
  });
626
- restoredState.actions = [];
627
603
  return restoredState;
628
604
  }
629
605