xstate 5.0.0-alpha.0 → 5.0.0-alpha.2

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 (97) hide show
  1. package/README.md +26 -15
  2. package/actions/dist/xstate-actions.cjs.dev.js +24 -25
  3. package/actions/dist/xstate-actions.cjs.prod.js +23 -24
  4. package/actions/dist/xstate-actions.esm.js +2 -2
  5. package/actions/dist/xstate-actions.umd.min.js +2 -0
  6. package/actions/dist/xstate-actions.umd.min.js.map +1 -0
  7. package/actions/dynamicAction.ts +15 -7
  8. package/actions/package.json +5 -1
  9. package/actors/dist/xstate-actors.cjs.d.ts +1 -1
  10. package/actors/dist/xstate-actors.cjs.dev.js +14 -14
  11. package/actors/dist/xstate-actors.cjs.prod.js +13 -13
  12. package/actors/dist/xstate-actors.esm.js +2 -2
  13. package/actors/dist/xstate-actors.umd.min.js +2 -0
  14. package/actors/dist/xstate-actors.umd.min.js.map +1 -0
  15. package/actors/package.json +5 -1
  16. package/dev/dist/xstate-dev.cjs.dev.js +1 -1
  17. package/dev/dist/xstate-dev.cjs.prod.js +0 -11
  18. package/dev/dist/xstate-dev.esm.js +1 -1
  19. package/dev/dist/xstate-dev.umd.min.js +2 -0
  20. package/dev/dist/xstate-dev.umd.min.js.map +1 -0
  21. package/dev/package.json +5 -1
  22. package/dist/{actions-6b86876d.cjs.dev.js → actions-1e9778c2.cjs.dev.js} +2819 -3334
  23. package/dist/actions-9778f6fb.esm.js +4246 -0
  24. package/dist/actions-acb29ffe.cjs.prod.js +4262 -0
  25. package/dist/declarations/actions/dynamicAction.d.ts +5 -3
  26. package/dist/declarations/src/Machine.d.ts +4 -4
  27. package/dist/declarations/src/Mailbox.d.ts +12 -12
  28. package/dist/declarations/src/SimulatedClock.d.ts +16 -16
  29. package/dist/declarations/src/State.d.ts +97 -104
  30. package/dist/declarations/src/StateMachine.d.ts +110 -112
  31. package/dist/declarations/src/StateNode.d.ts +127 -127
  32. package/dist/declarations/src/actionTypes.d.ts +16 -17
  33. package/dist/declarations/src/actions/assign.d.ts +7 -7
  34. package/dist/declarations/src/actions/cancel.d.ts +10 -10
  35. package/dist/declarations/src/actions/choose.d.ts +3 -3
  36. package/dist/declarations/src/actions/invoke.d.ts +3 -3
  37. package/dist/declarations/src/actions/log.d.ts +11 -11
  38. package/dist/declarations/src/actions/pure.d.ts +3 -3
  39. package/dist/declarations/src/actions/raise.d.ts +8 -9
  40. package/dist/declarations/src/actions/send.d.ts +53 -55
  41. package/dist/declarations/src/actions/stop.d.ts +7 -8
  42. package/dist/declarations/src/actions.d.ts +47 -44
  43. package/dist/declarations/src/actors/callback.d.ts +8 -0
  44. package/dist/declarations/src/actors/index.d.ts +27 -0
  45. package/dist/declarations/src/actors/observable.d.ts +23 -0
  46. package/dist/declarations/src/actors/promise.d.ts +12 -0
  47. package/dist/declarations/src/actors/transition.d.ts +13 -0
  48. package/dist/declarations/src/constants.d.ts +5 -5
  49. package/dist/declarations/src/dev/index.d.ts +14 -14
  50. package/dist/declarations/src/environment.d.ts +1 -1
  51. package/dist/declarations/src/guards.d.ts +8 -9
  52. package/dist/declarations/src/index.d.ts +44 -47
  53. package/dist/declarations/src/interpreter.d.ts +104 -147
  54. package/dist/declarations/src/mapState.d.ts +3 -3
  55. package/dist/declarations/src/memo.d.ts +2 -1
  56. package/dist/declarations/src/schema.d.ts +2 -2
  57. package/dist/declarations/src/spawn.d.ts +2 -2
  58. package/dist/declarations/src/stateUtils.d.ts +70 -85
  59. package/dist/declarations/src/symbolObservable.d.ts +1 -0
  60. package/dist/declarations/src/system.d.ts +2 -0
  61. package/dist/declarations/src/typegenTypes.d.ts +132 -132
  62. package/dist/declarations/src/types.d.ts +1008 -1026
  63. package/dist/declarations/src/utils.d.ts +58 -56
  64. package/dist/{index-20b364c4.esm.js → index-50bd0aff.esm.js} +0 -12
  65. package/dist/{index-2a564d03.cjs.dev.js → index-ebaab3c9.cjs.dev.js} +0 -12
  66. package/dist/xstate.cjs.dev.js +798 -100
  67. package/dist/xstate.cjs.prod.js +797 -99
  68. package/dist/xstate.esm.js +756 -55
  69. package/dist/xstate.umd.min.js +2 -0
  70. package/dist/xstate.umd.min.js.map +1 -0
  71. package/guards/dist/xstate-guards.cjs.dev.js +8 -8
  72. package/guards/dist/xstate-guards.cjs.prod.js +7 -7
  73. package/guards/dist/xstate-guards.esm.js +2 -2
  74. package/guards/dist/xstate-guards.umd.min.js +2 -0
  75. package/guards/dist/xstate-guards.umd.min.js.map +1 -0
  76. package/guards/package.json +5 -1
  77. package/package.json +28 -6
  78. package/CHANGELOG.md +0 -1986
  79. package/actions/ExecutableAction.ts +0 -58
  80. package/dist/Machine-9ce74c11.cjs.dev.js +0 -755
  81. package/dist/Machine-dca041dc.cjs.prod.js +0 -749
  82. package/dist/Machine-fb2f47f5.esm.js +0 -751
  83. package/dist/actions-70094c93.cjs.prod.js +0 -4765
  84. package/dist/actions-ff512f16.esm.js +0 -4757
  85. package/dist/declarations/actions/ExecutableAction.d.ts +0 -23
  86. package/dist/declarations/src/ObservableActorRef.d.ts +0 -25
  87. package/dist/declarations/src/actors.d.ts +0 -38
  88. package/dist/declarations/src/match.d.ts +0 -5
  89. package/dist/declarations/src/model.d.ts +0 -5
  90. package/dist/declarations/src/model.types.d.ts +0 -53
  91. package/dist/declarations/src/registry.d.ts +0 -8
  92. package/model/dist/xstate-model.cjs.d.ts +0 -1
  93. package/model/dist/xstate-model.cjs.dev.js +0 -41
  94. package/model/dist/xstate-model.cjs.js +0 -7
  95. package/model/dist/xstate-model.cjs.prod.js +0 -41
  96. package/model/dist/xstate-model.esm.js +0 -37
  97. package/model/package.json +0 -4
@@ -1,44 +1,47 @@
1
- import { Action, EventObject, SingleOrArray, ActionType, ActionFunction, ActionFunctionMap, ActionTypes, DoneEvent, ErrorPlatformEvent, DoneEventObject, MachineContext, BaseActionObject } from './types';
2
- import * as actionTypes from './actionTypes';
3
- export { send, sendTo, sendUpdate, sendParent, respond, forwardTo, escalate } from './actions/send';
4
- export { stop } from './actions/stop';
5
- export { log } from './actions/log';
6
- export { cancel } from './actions/cancel';
7
- export { assign } from './actions/assign';
8
- export { raise } from './actions/raise';
9
- export { choose } from './actions/choose';
10
- export { actionTypes };
11
- export declare const initEvent: import("./types").SCXML.Event<{
12
- type: ActionTypes;
13
- }>;
14
- export declare function getActionFunction<TContext extends MachineContext, TEvent extends EventObject>(actionType: ActionType, actionFunctionMap?: ActionFunctionMap<TContext, TEvent>): BaseActionObject | ActionFunction<TContext, TEvent> | undefined;
15
- export declare function resolveActionObject(actionObject: BaseActionObject, actionFunctionMap?: ActionFunctionMap<any, any>): BaseActionObject;
16
- export declare function toActionObject<TContext extends MachineContext, TEvent extends EventObject>(action: BaseActionObject | ActionFunction<TContext, TEvent> | string, actionFunctionMap?: ActionFunctionMap<TContext, TEvent>): BaseActionObject;
17
- export declare const toActionObjects: <TContext extends MachineContext, TEvent extends EventObject>(action?: SingleOrArray<Action<TContext, TEvent>> | undefined, actionFunctionMap?: ActionFunctionMap<TContext, TEvent, BaseActionObject> | undefined) => BaseActionObject[];
18
- /**
19
- * Returns an event type that represents an implicit event that
20
- * is sent after the specified `delay`.
21
- *
22
- * @param delayRef The delay in milliseconds
23
- * @param id The state node ID where this event is handled
24
- */
25
- export declare function after(delayRef: number | string, id?: string): string;
26
- /**
27
- * Returns an event that represents that a final state node
28
- * has been reached in the parent state node.
29
- *
30
- * @param id The final state node's parent state node `id`
31
- * @param data The data to pass into the event
32
- */
33
- export declare function done(id: string, data?: any): DoneEventObject;
34
- /**
35
- * Returns an event that represents that an invoked service has terminated.
36
- *
37
- * An invoked service is terminated when it has reached a top-level final state node,
38
- * but not when it is canceled.
39
- *
40
- * @param invokeId The invoked service ID
41
- * @param data The data to pass into the event
42
- */
43
- export declare function doneInvoke(invokeId: string, data?: any): DoneEvent;
44
- export declare function error(id: string, data?: any): ErrorPlatformEvent & string;
1
+ import { Action, EventObject, SingleOrArray, ActionFunction, ActionFunctionMap, ActionTypes, DoneEvent, ErrorPlatformEvent, DoneEventObject, MachineContext, BaseActionObject, SCXML } from './types.js';
2
+ import * as actionTypes from './actionTypes.js';
3
+ export { send, sendTo, sendParent, respond, forwardTo, escalate } from './actions/send.js';
4
+ export { stop } from './actions/stop.js';
5
+ export { log } from './actions/log.js';
6
+ export { cancel } from './actions/cancel.js';
7
+ export { assign } from './actions/assign.js';
8
+ export { raise } from './actions/raise.js';
9
+ export { choose } from './actions/choose.js';
10
+ export { actionTypes };
11
+ export declare const initEvent: SCXML.Event<{
12
+ type: ActionTypes;
13
+ }>;
14
+ export declare function resolveActionObject(actionObject: BaseActionObject, actionFunctionMap: ActionFunctionMap<any, any>): BaseActionObject;
15
+ export declare function toActionObject<TContext extends MachineContext, TEvent extends EventObject>(action: BaseActionObject | ActionFunction<TContext, TEvent> | string): BaseActionObject;
16
+ export declare const toActionObjects: <TContext extends MachineContext, TEvent extends EventObject>(action?: SingleOrArray<Action<TContext, TEvent, TEvent>> | undefined) => BaseActionObject[];
17
+ /**
18
+ * Returns an event type that represents an implicit event that
19
+ * is sent after the specified `delay`.
20
+ *
21
+ * @param delayRef The delay in milliseconds
22
+ * @param id The state node ID where this event is handled
23
+ */
24
+ export declare function after(delayRef: number | string, id?: string): string;
25
+ /**
26
+ * Returns an event that represents that a final state node
27
+ * has been reached in the parent state node.
28
+ *
29
+ * @param id The final state node's parent state node `id`
30
+ * @param data The data to pass into the event
31
+ */
32
+ export declare function done(id: string, data?: any): DoneEventObject;
33
+ /**
34
+ * Returns an event that represents that an invoked service has terminated.
35
+ *
36
+ * An invoked service is terminated when it has reached a top-level final state node,
37
+ * but not when it is canceled.
38
+ *
39
+ * @param invokeId The invoked service ID
40
+ * @param data The data to pass into the event
41
+ */
42
+ export declare function doneInvoke(invokeId: string, data?: any): DoneEvent;
43
+ export declare function error(id: string, data?: any): ErrorPlatformEvent & string;
44
+ export declare function createInitEvent(input: any): SCXML.Event<{
45
+ type: ActionTypes.Init;
46
+ input: any;
47
+ }>;
@@ -0,0 +1,8 @@
1
+ import { InvokeCallback, ActorBehavior, EventObject } from '../types';
2
+ export interface CallbackInternalState {
3
+ canceled: boolean;
4
+ receivers: Set<(e: EventObject) => void>;
5
+ dispose: void | (() => void) | Promise<any>;
6
+ input?: any;
7
+ }
8
+ export declare function fromCallback<TEvent extends EventObject>(invokeCallback: InvokeCallback): ActorBehavior<TEvent, undefined>;
@@ -0,0 +1,27 @@
1
+ import type { EventObject, ActorRef, BaseActorRef } from '../types.js';
2
+ export { fromTransition } from './transition.js';
3
+ export { fromPromise } from './promise.js';
4
+ export { fromObservable, fromEventObservable } from './observable.js';
5
+ export { fromCallback } from './callback.js';
6
+ export declare const startSignalType = "xstate.init";
7
+ export declare const stopSignalType = "xstate.stop";
8
+ export declare const startSignal: StartSignal;
9
+ export declare const stopSignal: StopSignal;
10
+ export interface StartSignal {
11
+ type: 'xstate.init';
12
+ }
13
+ export interface StopSignal {
14
+ type: 'xstate.stop';
15
+ }
16
+ export type LifecycleSignal = StartSignal | StopSignal;
17
+ export type LifecycleSignalType = typeof startSignalType | typeof stopSignalType;
18
+ /**
19
+ * An object that expresses the behavior of an actor in reaction to received events,
20
+ * as well as an optionally emitted stream of values.
21
+ *
22
+ * @template TReceived The received event
23
+ * @template TSnapshot The emitted value
24
+ */
25
+ export declare function isSignal(eventType: string): eventType is LifecycleSignalType;
26
+ export declare function isActorRef(item: any): item is ActorRef<any>;
27
+ export declare function toActorRef<TEvent extends EventObject, TSnapshot = any, TActorRefLike extends BaseActorRef<TEvent> = BaseActorRef<TEvent>>(actorRefLike: TActorRefLike): ActorRef<TEvent, TSnapshot> & Omit<TActorRefLike, keyof ActorRef<any, any>>;
@@ -0,0 +1,23 @@
1
+ import { Subscribable, ActorBehavior, EventObject, Subscription } from '../types';
2
+ export interface ObservableInternalState<T> {
3
+ subscription: Subscription | undefined;
4
+ canceled: boolean;
5
+ status: 'active' | 'done' | 'error';
6
+ data: T | undefined;
7
+ input?: any;
8
+ }
9
+ export type ObservablePersistedState<T> = Omit<ObservableInternalState<T>, 'subscription'>;
10
+ export declare function fromObservable<T, TEvent extends EventObject>(observableCreator: ({ input }: {
11
+ input: any;
12
+ }) => Subscribable<T>): ActorBehavior<TEvent, T | undefined, ObservableInternalState<T>, ObservablePersistedState<T>>;
13
+ /**
14
+ * Creates an event observable behavior that listens to an observable
15
+ * that delivers event objects.
16
+ *
17
+ *
18
+ * @param lazyObservable A function that creates an observable
19
+ * @returns An event observable behavior
20
+ */
21
+ export declare function fromEventObservable<T extends EventObject>(lazyObservable: ({ input }: {
22
+ input: any;
23
+ }) => Subscribable<T>): ActorBehavior<EventObject, T | undefined>;
@@ -0,0 +1,12 @@
1
+ import { ActorBehavior } from '../types';
2
+ export interface PromiseInternalState<T> {
3
+ status: 'active' | 'error' | 'done';
4
+ canceled: boolean;
5
+ data: T | undefined;
6
+ input?: any;
7
+ }
8
+ export declare function fromPromise<T>(promiseCreator: ({ input }: {
9
+ input: any;
10
+ }) => PromiseLike<T>): ActorBehavior<{
11
+ type: string;
12
+ }, T | undefined, PromiseInternalState<T>>;
@@ -0,0 +1,13 @@
1
+ import { ActorBehavior, ActorContext, ActorSystem, EventObject } from '../types';
2
+ /**
3
+ * Returns an actor behavior from a transition function and its initial state.
4
+ *
5
+ * A transition function is a function that takes the current state and an event and returns the next state.
6
+ *
7
+ * @param transition The transition function that returns the next state given the current state and event.
8
+ * @param initialState The initial state of the transition function.
9
+ * @returns An actor behavior
10
+ */
11
+ export declare function fromTransition<TState, TEvent extends EventObject, TSystem extends ActorSystem<any>>(transition: (state: TState, event: TEvent, actorContext: ActorContext<TEvent, TState, TSystem>) => TState, initialState: TState | (({ input }: {
12
+ input: any;
13
+ }) => TState)): ActorBehavior<TEvent, TState, TState>;
@@ -1,5 +1,5 @@
1
- export declare const STATE_DELIMITER = ".";
2
- export declare const TARGETLESS_KEY = "";
3
- export declare const NULL_EVENT = "";
4
- export declare const STATE_IDENTIFIER = "#";
5
- export declare const WILDCARD = "*";
1
+ export declare const STATE_DELIMITER = ".";
2
+ export declare const TARGETLESS_KEY = "";
3
+ export declare const NULL_EVENT = "";
4
+ export declare const STATE_IDENTIFIER = "#";
5
+ export declare const WILDCARD = "*";
@@ -1,14 +1,14 @@
1
- import { AnyInterpreter, DevToolsAdapter } from '../types';
2
- declare type ServiceListener = (service: AnyInterpreter) => void;
3
- export interface XStateDevInterface {
4
- register: (service: AnyInterpreter) => void;
5
- unregister: (service: AnyInterpreter) => void;
6
- onRegister: (listener: ServiceListener) => {
7
- unsubscribe: () => void;
8
- };
9
- services: Set<AnyInterpreter>;
10
- }
11
- export declare function getGlobal(): typeof globalThis | undefined;
12
- export declare function registerService(service: AnyInterpreter): void;
13
- export declare const devToolsAdapter: DevToolsAdapter;
14
- export {};
1
+ import { AnyInterpreter, DevToolsAdapter } from '../types.js';
2
+ type ServiceListener = (service: AnyInterpreter) => void;
3
+ export interface XStateDevInterface {
4
+ register: (service: AnyInterpreter) => void;
5
+ unregister: (service: AnyInterpreter) => void;
6
+ onRegister: (listener: ServiceListener) => {
7
+ unsubscribe: () => void;
8
+ };
9
+ services: Set<AnyInterpreter>;
10
+ }
11
+ export declare function getGlobal(): typeof globalThis | undefined;
12
+ export declare function registerService(service: AnyInterpreter): void;
13
+ export declare const devToolsAdapter: DevToolsAdapter;
14
+ export {};
@@ -1 +1 @@
1
- export declare const IS_PRODUCTION: boolean;
1
+ export declare const IS_PRODUCTION: boolean;
@@ -1,9 +1,8 @@
1
- import type { EventObject, StateValue, BooleanGuardDefinition, GuardConfig, GuardDefinition, SCXML, GuardPredicate, MachineContext } from './types';
2
- import type { State } from './State';
3
- import type { StateMachine } from './StateMachine';
4
- export declare function stateIn<TContext extends MachineContext, TEvent extends EventObject>(stateValue: StateValue): GuardDefinition<TContext, TEvent>;
5
- export declare function not<TContext extends MachineContext, TEvent extends EventObject>(guard: GuardConfig<TContext, TEvent>): BooleanGuardDefinition<TContext, TEvent>;
6
- export declare function and<TContext extends MachineContext, TEvent extends EventObject>(guards: Array<GuardConfig<TContext, TEvent>>): BooleanGuardDefinition<TContext, TEvent>;
7
- export declare function or<TContext extends MachineContext, TEvent extends EventObject>(guards: Array<GuardConfig<TContext, TEvent>>): BooleanGuardDefinition<TContext, TEvent>;
8
- export declare function evaluateGuard<TContext extends MachineContext, TEvent extends EventObject>(guard: GuardDefinition<TContext, TEvent>, context: TContext, _event: SCXML.Event<TEvent>, state: State<TContext, TEvent>, machine: StateMachine<TContext, TEvent>): boolean;
9
- export declare function toGuardDefinition<TContext extends MachineContext, TEvent extends EventObject>(guardConfig: GuardConfig<TContext, TEvent>, getPredicate?: (guardType: string) => GuardPredicate<TContext, TEvent>): GuardDefinition<TContext, TEvent>;
1
+ import type { EventObject, StateValue, BooleanGuardDefinition, GuardConfig, GuardDefinition, SCXML, GuardPredicate, MachineContext } from './types.js';
2
+ import type { State } from './State.js';
3
+ export declare function stateIn<TContext extends MachineContext, TEvent extends EventObject>(stateValue: StateValue): GuardDefinition<TContext, TEvent>;
4
+ export declare function not<TContext extends MachineContext, TEvent extends EventObject>(guard: GuardConfig<TContext, TEvent>): BooleanGuardDefinition<TContext, TEvent>;
5
+ export declare function and<TContext extends MachineContext, TEvent extends EventObject>(guards: Array<GuardConfig<TContext, TEvent>>): BooleanGuardDefinition<TContext, TEvent>;
6
+ export declare function or<TContext extends MachineContext, TEvent extends EventObject>(guards: Array<GuardConfig<TContext, TEvent>>): BooleanGuardDefinition<TContext, TEvent>;
7
+ export declare function evaluateGuard<TContext extends MachineContext, TEvent extends EventObject>(guard: GuardDefinition<TContext, TEvent>, context: TContext, _event: SCXML.Event<TEvent>, state: State<TContext, TEvent>): boolean;
8
+ export declare function toGuardDefinition<TContext extends MachineContext, TEvent extends EventObject>(guardConfig: GuardConfig<TContext, TEvent>, getPredicate?: (guardType: string) => GuardPredicate<TContext, TEvent>): GuardDefinition<TContext, TEvent>;
@@ -1,47 +1,44 @@
1
- import { after, done, doneInvoke, escalate, forwardTo, respond, sendParent, sendTo, sendUpdate } from './actions';
2
- import { assign } from './actions/assign';
3
- import { cancel } from './actions/cancel';
4
- import { choose } from './actions/choose';
5
- import { log } from './actions/log';
6
- import { pure } from './actions/pure';
7
- import { raise } from './actions/raise';
8
- import { send } from './actions/send';
9
- import { stop } from './actions/stop';
10
- import { interpret, Interpreter, InterpreterStatus } from './interpreter';
11
- import { createMachine } from './Machine';
12
- import { mapState } from './mapState';
13
- import { matchState } from './match';
14
- import { State } from './State';
15
- import { StateNode } from './StateNode';
16
- export { createSchema, t } from './schema';
17
- export { SimulatedClock } from './SimulatedClock';
18
- export { StateMachine } from './StateMachine';
19
- export { getStateNodes } from './stateUtils';
20
- export { ObservableActorRef } from './ObservableActorRef';
21
- export * from './typegenTypes';
22
- export * from './types';
23
- export { matchesState, pathToStateValue, toEventObject, toObserver, toSCXMLEvent } from './utils';
24
- export { StateNode, State, mapState, actions, assign, send, sendParent, sendUpdate, forwardTo, interpret, Interpreter, InterpreterStatus, matchState, doneInvoke, createMachine };
25
- declare const actions: {
26
- raise: typeof raise;
27
- send: typeof send;
28
- sendParent: typeof sendParent;
29
- sendTo: typeof sendTo;
30
- sendUpdate: typeof sendUpdate;
31
- log: typeof log;
32
- cancel: typeof cancel;
33
- stop: typeof stop;
34
- assign: typeof assign;
35
- after: typeof after;
36
- done: typeof done;
37
- respond: typeof respond;
38
- forwardTo: typeof forwardTo;
39
- escalate: typeof escalate;
40
- choose: typeof choose;
41
- pure: typeof pure;
42
- };
43
- declare global {
44
- interface SymbolConstructor {
45
- readonly observable: symbol;
46
- }
47
- }
1
+ import { after, done, doneInvoke, escalate, forwardTo, respond, sendParent, sendTo } from './actions.js';
2
+ import { assign } from './actions/assign.js';
3
+ import { cancel } from './actions/cancel.js';
4
+ import { choose } from './actions/choose.js';
5
+ import { log } from './actions/log.js';
6
+ import { pure } from './actions/pure.js';
7
+ import { raise } from './actions/raise.js';
8
+ import { send } from './actions/send.js';
9
+ import { stop } from './actions/stop.js';
10
+ import { interpret, Interpreter, ActorStatus } from './interpreter.js';
11
+ import { createMachine } from './Machine.js';
12
+ import { mapState } from './mapState.js';
13
+ import { State } from './State.js';
14
+ import { StateNode } from './StateNode.js';
15
+ export { createSchema, t } from './schema.js';
16
+ export { SimulatedClock } from './SimulatedClock.js';
17
+ export { StateMachine } from './StateMachine.js';
18
+ export { getStateNodes } from './stateUtils.js';
19
+ export * from './typegenTypes.js';
20
+ export * from './types.js';
21
+ export { matchesState, pathToStateValue, toObserver, toSCXMLEvent } from './utils.js';
22
+ export { StateNode, State, mapState, actions, assign, send, sendTo, sendParent, forwardTo, interpret, Interpreter, ActorStatus as InterpreterStatus, doneInvoke, createMachine };
23
+ declare const actions: {
24
+ raise: typeof raise;
25
+ send: typeof send;
26
+ sendParent: typeof sendParent;
27
+ sendTo: typeof sendTo;
28
+ log: typeof log;
29
+ cancel: typeof cancel;
30
+ stop: typeof stop;
31
+ assign: typeof assign;
32
+ after: typeof after;
33
+ done: typeof done;
34
+ respond: typeof respond;
35
+ forwardTo: typeof forwardTo;
36
+ escalate: typeof escalate;
37
+ choose: typeof choose;
38
+ pure: typeof pure;
39
+ };
40
+ declare global {
41
+ interface SymbolConstructor {
42
+ readonly observable: symbol;
43
+ }
44
+ }
@@ -1,147 +1,104 @@
1
- import { AnyStateMachine, InterpreterFrom } from '.';
2
- import { State } from './State';
3
- import type { StateMachine } from './StateMachine';
4
- import { TypegenDisabled, AreAllImplementationsAssumedToBeProvided } from './typegenTypes';
5
- import type { MachineContext, PayloadSender } from './types';
6
- import { ActorRef, DoneEvent, Event, EventObject, InteropSubscribable, InterpreterOptions, Observer, SCXML, StateValue, Subscription } from './types';
7
- import { symbolObservable } from './utils';
8
- export declare type StateListener<TContext extends MachineContext, TEvent extends EventObject, TResolvedTypesMeta = TypegenDisabled> = (state: State<TContext, TEvent, TResolvedTypesMeta>, event: TEvent) => void;
9
- export declare type EventListener<TEvent extends EventObject = EventObject> = (event: TEvent) => void;
10
- export declare type Listener = () => void;
11
- export declare type ErrorListener = (error: any) => void;
12
- export interface Clock {
13
- setTimeout(fn: (...args: any[]) => void, timeout: number): any;
14
- clearTimeout(id: any): void;
15
- }
16
- export declare enum InterpreterStatus {
17
- NotStarted = 0,
18
- Running = 1,
19
- Stopped = 2
20
- }
21
- export declare class Interpreter<TContext extends MachineContext, TEvent extends EventObject = EventObject, TResolvedTypesMeta = TypegenDisabled> implements ActorRef<TEvent, State<TContext, TEvent, TResolvedTypesMeta>> {
22
- machine: StateMachine<TContext, TEvent, any, any, TResolvedTypesMeta>;
23
- /**
24
- * The current state of the interpreted machine.
25
- */
26
- private _state?;
27
- private _initialState?;
28
- /**
29
- * The clock that is responsible for setting and clearing timeouts, such as delayed events and transitions.
30
- */
31
- clock: Clock;
32
- options: Readonly<InterpreterOptions>;
33
- id: string;
34
- private mailbox;
35
- private delayedEventsMap;
36
- private listeners;
37
- private stopListeners;
38
- private errorListeners;
39
- private doneListeners;
40
- private logger;
41
- /**
42
- * Whether the service is started.
43
- */
44
- status: InterpreterStatus;
45
- _parent?: ActorRef<any>;
46
- name: string;
47
- ref: ActorRef<TEvent>;
48
- /**
49
- * The globally unique process ID for this invocation.
50
- */
51
- sessionId: string;
52
- private forwardTo;
53
- /**
54
- * Creates a new Interpreter instance (i.e., service) for the given machine with the provided options, if any.
55
- *
56
- * @param machine The machine to be interpreted
57
- * @param options Interpreter options
58
- */
59
- constructor(machine: StateMachine<TContext, TEvent, any, any, TResolvedTypesMeta>, options?: InterpreterOptions);
60
- get initialized(): boolean;
61
- get initialState(): State<TContext, TEvent, TResolvedTypesMeta>;
62
- get state(): State<TContext, TEvent, TResolvedTypesMeta>;
63
- /**
64
- * Executes the actions of the given state, with that state's `context` and `event`.
65
- *
66
- * @param state The state whose actions will be executed
67
- */
68
- execute(state: State<TContext, TEvent, TResolvedTypesMeta>): void;
69
- private update;
70
- onTransition(listener: StateListener<TContext, TEvent, TResolvedTypesMeta>): this;
71
- subscribe(observer: Observer<State<TContext, TEvent, TResolvedTypesMeta>>): Subscription;
72
- subscribe(nextListener?: (state: State<TContext, TEvent, TResolvedTypesMeta>) => void, errorListener?: (error: any) => void, completeListener?: () => void): Subscription;
73
- /**
74
-
75
- * Adds a listener that is notified when the machine is stopped.
76
- *
77
- * @param listener The listener
78
- */
79
- onStop(listener: Listener): this;
80
- /**
81
- * Adds an error listener that is notified with an `Error` whenever an
82
- * error occurs during execution.
83
- *
84
- * @param listener The error listener
85
- */
86
- onError(listener: ErrorListener): this;
87
- /**
88
- * Adds a state listener that is notified when the statechart has reached its final state.
89
- * @param listener The state listener
90
- */
91
- onDone(listener: EventListener<DoneEvent>): this;
92
- /**
93
- * Removes a listener.
94
- * @param listener The listener to remove
95
- */
96
- off(listener: (...args: any[]) => void): this;
97
- /**
98
- * Starts the interpreter from the given state, or the initial state.
99
- * @param initialState The state to start the statechart from
100
- */
101
- start(initialState?: State<TContext, TEvent, TResolvedTypesMeta> | StateValue): this;
102
- private _process;
103
- /**
104
- * Stops the interpreter and unsubscribe all listeners.
105
- *
106
- * This will also notify the `onStop` listeners.
107
- */
108
- stop(): this;
109
- /**
110
- * Sends an event to the running interpreter to trigger a transition.
111
- *
112
- * An array of events (batched) can be sent as well, which will send all
113
- * batched events to the running interpreter. The listeners will be
114
- * notified only **once** when all events are processed.
115
- *
116
- * @param event The event(s) to send
117
- */
118
- send: PayloadSender<TEvent>;
119
- private sendTo;
120
- /**
121
- * Returns the next state given the interpreter's current state and the event.
122
- *
123
- * This is a pure method that does _not_ update the interpreter's state.
124
- *
125
- * @param event The event to determine the next state
126
- */
127
- nextState(event: Event<TEvent> | SCXML.Event<TEvent>): State<TContext, TEvent, TResolvedTypesMeta>;
128
- private forward;
129
- private defer;
130
- private cancel;
131
- private getActionFunction;
132
- private exec;
133
- private stopChild;
134
- private attachDevTools;
135
- toJSON(): {
136
- id: string;
137
- };
138
- [Symbol.observable](): InteropSubscribable<State<TContext, TEvent, TResolvedTypesMeta>>;
139
- getSnapshot(): State<TContext, TEvent, TResolvedTypesMeta>;
140
- }
141
- /**
142
- * Creates a new Interpreter instance for the given machine with the provided options, if any.
143
- *
144
- * @param machine The machine to interpret
145
- * @param options Interpreter options
146
- */
147
- export declare function interpret<TMachine extends AnyStateMachine>(machine: AreAllImplementationsAssumedToBeProvided<TMachine['__TResolvedTypesMeta']> extends true ? TMachine : 'Some implementations missing', options?: InterpreterOptions): InterpreterFrom<TMachine>;
1
+ import type { AnyStateMachine, EventFromBehavior, InterpreterFrom, PersistedStateFrom, SnapshotFrom, ActorSystem, AnyActorBehavior, RaiseActionObject } from './types.js';
2
+ import { AreAllImplementationsAssumedToBeProvided } from './typegenTypes.js';
3
+ import { ActorRef, DoneEvent, EventObject, InteropSubscribable, InterpreterOptions, Observer, SCXML, SendActionObject, Subscription } from './types.js';
4
+ import { symbolObservable } from './symbolObservable.js';
5
+ export type SnapshotListener<TBehavior extends AnyActorBehavior> = (state: SnapshotFrom<TBehavior>) => void;
6
+ export type EventListener<TEvent extends EventObject = EventObject> = (event: TEvent) => void;
7
+ export type Listener = () => void;
8
+ export type ErrorListener = (error: any) => void;
9
+ export interface Clock {
10
+ setTimeout(fn: (...args: any[]) => void, timeout: number): any;
11
+ clearTimeout(id: any): void;
12
+ }
13
+ export declare enum ActorStatus {
14
+ NotStarted = 0,
15
+ Running = 1,
16
+ Stopped = 2
17
+ }
18
+ export declare class Interpreter<TBehavior extends AnyActorBehavior, TEvent extends EventObject = EventFromBehavior<TBehavior>> implements ActorRef<TEvent, SnapshotFrom<TBehavior>> {
19
+ behavior: TBehavior;
20
+ /**
21
+ * The current state of the interpreted behavior.
22
+ */
23
+ private _state;
24
+ /**
25
+ * The clock that is responsible for setting and clearing timeouts, such as delayed events and transitions.
26
+ */
27
+ clock: Clock;
28
+ options: Readonly<InterpreterOptions<TBehavior>>;
29
+ /**
30
+ * The unique identifier for this actor relative to its parent.
31
+ */
32
+ id: string;
33
+ private mailbox;
34
+ private delayedEventsMap;
35
+ private observers;
36
+ private logger;
37
+ /**
38
+ * Whether the service is started.
39
+ */
40
+ status: ActorStatus;
41
+ _parent?: ActorRef<any>;
42
+ ref: ActorRef<TEvent>;
43
+ private _actorContext;
44
+ private _systemId;
45
+ /**
46
+ * The globally unique process ID for this invocation.
47
+ */
48
+ sessionId: string;
49
+ system: ActorSystem<any>;
50
+ private _doneEvent?;
51
+ src?: string;
52
+ /**
53
+ * Creates a new Interpreter instance (i.e., service) for the given behavior with the provided options, if any.
54
+ *
55
+ * @param behavior The behavior to be interpreted
56
+ * @param options Interpreter options
57
+ */
58
+ constructor(behavior: TBehavior, options?: InterpreterOptions<TBehavior>);
59
+ private _initState;
60
+ private _deferred;
61
+ private update;
62
+ subscribe(observer: Observer<SnapshotFrom<TBehavior>>): Subscription;
63
+ subscribe(nextListener?: (state: SnapshotFrom<TBehavior>) => void, errorListener?: (error: any) => void, completeListener?: () => void): Subscription;
64
+ /**
65
+ * Adds a state listener that is notified when the statechart has reached its final state.
66
+ * @param listener The state listener
67
+ */
68
+ onDone(listener: EventListener<DoneEvent>): this;
69
+ /**
70
+ * Starts the interpreter from the initial state
71
+ */
72
+ start(): this;
73
+ private _process;
74
+ private _stop;
75
+ /**
76
+ * Stops the interpreter and unsubscribe all listeners.
77
+ */
78
+ stop(): this;
79
+ private _complete;
80
+ private _stopProcedure;
81
+ /**
82
+ * Sends an event to the running interpreter to trigger a transition.
83
+ *
84
+ * @param event The event to send
85
+ */
86
+ send(event: TEvent | SCXML.Event<TEvent>): void;
87
+ delaySend(sendAction: SendActionObject | RaiseActionObject<any, any, any>): void;
88
+ cancel(sendId: string | number): void;
89
+ private attachDevTools;
90
+ toJSON(): {
91
+ id: string;
92
+ };
93
+ getPersistedState(): PersistedStateFrom<TBehavior> | undefined;
94
+ [Symbol.observable](): InteropSubscribable<SnapshotFrom<TBehavior>>;
95
+ getSnapshot(): SnapshotFrom<TBehavior>;
96
+ }
97
+ /**
98
+ * Creates a new Interpreter instance for the given machine with the provided options, if any.
99
+ *
100
+ * @param machine The machine to interpret
101
+ * @param options Interpreter options
102
+ */
103
+ export declare function interpret<TMachine extends AnyStateMachine>(machine: AreAllImplementationsAssumedToBeProvided<TMachine['__TResolvedTypesMeta']> extends true ? TMachine : 'Some implementations missing', options?: InterpreterOptions<TMachine>): InterpreterFrom<TMachine>;
104
+ export declare function interpret<TBehavior extends AnyActorBehavior>(behavior: TBehavior, options?: InterpreterOptions<TBehavior>): Interpreter<TBehavior>;
@@ -1,3 +1,3 @@
1
- export declare function mapState(stateMap: {
2
- [stateId: string]: any;
3
- }, stateId: string): any;
1
+ export declare function mapState(stateMap: {
2
+ [stateId: string]: any;
3
+ }, stateId: string): any;
@@ -1 +1,2 @@
1
- export declare function memo<T>(object: any, key: string, fn: () => T): T;
1
+ export declare function memo<T>(object: any, key: string, fn: () => T): T;
2
+ export declare function evict(object: any, key?: string): void;
@@ -1,2 +1,2 @@
1
- export declare function createSchema<T>(schema?: any): T;
2
- export declare const t: typeof createSchema;
1
+ export declare function createSchema<T>(schema?: any): T;
2
+ export declare const t: typeof createSchema;