xstate 5.0.0-alpha.0 → 5.0.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. package/README.md +23 -13
  2. package/actions/dist/xstate-actions.cjs.dev.js +22 -24
  3. package/actions/dist/xstate-actions.cjs.prod.js +22 -24
  4. package/actions/dist/xstate-actions.esm.js +1 -1
  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 +4 -4
  8. package/actions/package.json +5 -1
  9. package/actors/dist/xstate-actors.cjs.dev.js +12 -13
  10. package/actors/dist/xstate-actors.cjs.prod.js +12 -13
  11. package/actors/dist/xstate-actors.esm.js +1 -1
  12. package/actors/dist/xstate-actors.umd.min.js +2 -0
  13. package/actors/dist/xstate-actors.umd.min.js.map +1 -0
  14. package/actors/package.json +5 -1
  15. package/dev/dist/xstate-dev.umd.min.js +2 -0
  16. package/dev/dist/xstate-dev.umd.min.js.map +1 -0
  17. package/dev/package.json +5 -1
  18. package/dist/{actions-70094c93.cjs.prod.js → actions-7ea9280f.cjs.prod.js} +3118 -3209
  19. package/dist/{actions-6b86876d.cjs.dev.js → actions-b08d0da8.cjs.dev.js} +3105 -3202
  20. package/dist/{actions-ff512f16.esm.js → actions-b673cb13.esm.js} +3092 -3189
  21. package/dist/declarations/actions/dynamicAction.d.ts +5 -3
  22. package/dist/declarations/src/Machine.d.ts +4 -4
  23. package/dist/declarations/src/Mailbox.d.ts +12 -12
  24. package/dist/declarations/src/SimulatedClock.d.ts +16 -16
  25. package/dist/declarations/src/State.d.ts +97 -104
  26. package/dist/declarations/src/StateMachine.d.ts +120 -112
  27. package/dist/declarations/src/StateNode.d.ts +127 -127
  28. package/dist/declarations/src/actionTypes.d.ts +16 -17
  29. package/dist/declarations/src/actions/assign.d.ts +7 -7
  30. package/dist/declarations/src/actions/cancel.d.ts +10 -10
  31. package/dist/declarations/src/actions/choose.d.ts +3 -3
  32. package/dist/declarations/src/actions/invoke.d.ts +3 -3
  33. package/dist/declarations/src/actions/log.d.ts +11 -11
  34. package/dist/declarations/src/actions/pure.d.ts +3 -3
  35. package/dist/declarations/src/actions/raise.d.ts +9 -9
  36. package/dist/declarations/src/actions/send.d.ts +51 -55
  37. package/dist/declarations/src/actions/stop.d.ts +7 -8
  38. package/dist/declarations/src/actions.d.ts +43 -44
  39. package/dist/declarations/src/actors.d.ts +37 -38
  40. package/dist/declarations/src/constants.d.ts +5 -5
  41. package/dist/declarations/src/dev/index.d.ts +14 -14
  42. package/dist/declarations/src/environment.d.ts +1 -1
  43. package/dist/declarations/src/guards.d.ts +8 -9
  44. package/dist/declarations/src/index.d.ts +44 -47
  45. package/dist/declarations/src/interpreter.d.ts +108 -147
  46. package/dist/declarations/src/mapState.d.ts +3 -3
  47. package/dist/declarations/src/memo.d.ts +2 -1
  48. package/dist/declarations/src/registry.d.ts +8 -8
  49. package/dist/declarations/src/schema.d.ts +2 -2
  50. package/dist/declarations/src/spawn.d.ts +2 -2
  51. package/dist/declarations/src/stateUtils.d.ts +70 -85
  52. package/dist/declarations/src/symbolObservable.d.ts +1 -0
  53. package/dist/declarations/src/typegenTypes.d.ts +132 -132
  54. package/dist/declarations/src/types.d.ts +1001 -1026
  55. package/dist/declarations/src/utils.d.ts +54 -56
  56. package/dist/xstate.cjs.dev.js +856 -80
  57. package/dist/xstate.cjs.prod.js +856 -80
  58. package/dist/xstate.esm.js +815 -35
  59. package/dist/xstate.umd.min.js +2 -0
  60. package/dist/xstate.umd.min.js.map +1 -0
  61. package/guards/dist/xstate-guards.cjs.dev.js +7 -7
  62. package/guards/dist/xstate-guards.cjs.prod.js +7 -7
  63. package/guards/dist/xstate-guards.esm.js +1 -1
  64. package/guards/dist/xstate-guards.umd.min.js +2 -0
  65. package/guards/dist/xstate-guards.umd.min.js.map +1 -0
  66. package/guards/package.json +5 -1
  67. package/package.json +25 -2
  68. package/CHANGELOG.md +0 -1986
  69. package/actions/ExecutableAction.ts +0 -58
  70. package/dist/Machine-9ce74c11.cjs.dev.js +0 -755
  71. package/dist/Machine-dca041dc.cjs.prod.js +0 -749
  72. package/dist/Machine-fb2f47f5.esm.js +0 -751
  73. package/dist/declarations/actions/ExecutableAction.d.ts +0 -23
  74. package/dist/declarations/src/ObservableActorRef.d.ts +0 -25
  75. package/dist/declarations/src/match.d.ts +0 -5
  76. package/dist/declarations/src/model.d.ts +0 -5
  77. package/dist/declarations/src/model.types.d.ts +0 -53
  78. package/model/dist/xstate-model.cjs.d.ts +0 -1
  79. package/model/dist/xstate-model.cjs.dev.js +0 -41
  80. package/model/dist/xstate-model.cjs.js +0 -7
  81. package/model/dist/xstate-model.cjs.prod.js +0 -41
  82. package/model/dist/xstate-model.esm.js +0 -37
  83. package/model/package.json +0 -4
@@ -1,38 +1,37 @@
1
- import type { InvokeCallback, Subscribable, InterpreterOptions, Lazy, Behavior, ActorContext, EventObject, ActorRef, AnyStateMachine, BaseActorRef, EventFrom, StateFrom } from './types';
2
- import { AreAllImplementationsAssumedToBeProvided } from './typegenTypes';
3
- /**
4
- * Returns an actor behavior from a reducer and its initial state.
5
- *
6
- * @param transition The pure reducer that returns the next state given the current state and event.
7
- * @param initialState The initial state of the reducer.
8
- * @returns An actor behavior
9
- */
10
- export declare function fromReducer<TState, TEvent extends EventObject>(transition: (state: TState, event: TEvent, actorContext: ActorContext<TEvent, TState>) => TState, initialState: TState): Behavior<TEvent, TState>;
11
- export declare const startSignalType: unique symbol;
12
- export declare const stopSignalType: unique symbol;
13
- export declare const startSignal: StartSignal;
14
- export declare const stopSignal: StopSignal;
15
- export interface StartSignal {
16
- type: typeof startSignalType;
17
- }
18
- export interface StopSignal {
19
- type: typeof stopSignalType;
20
- }
21
- export declare type LifecycleSignal = StartSignal | StopSignal;
22
- export declare function fromCallback<TEvent extends EventObject>(invokeCallback: InvokeCallback): Behavior<TEvent, undefined>;
23
- export declare function fromPromise<T>(lazyPromise: Lazy<PromiseLike<T>>): Behavior<{
24
- type: string;
25
- }, T | undefined>;
26
- export declare function fromObservable<T, TEvent extends EventObject>(lazyObservable: Lazy<Subscribable<T>>): Behavior<TEvent, T | undefined>;
27
- /**
28
- * Creates an event observable behavior that listens to an observable
29
- * that delivers event objects.
30
- *
31
- *
32
- * @param lazyObservable A function that creates an observable
33
- * @returns An event observable behavior
34
- */
35
- export declare function fromEventObservable<T extends EventObject>(lazyObservable: Lazy<Subscribable<T>>): Behavior<EventObject, T | undefined>;
36
- export declare function fromMachine<TMachine extends AnyStateMachine>(machine: AreAllImplementationsAssumedToBeProvided<TMachine['__TResolvedTypesMeta']> extends true ? TMachine : 'Some implementations missing', options?: Partial<InterpreterOptions>): Behavior<EventFrom<TMachine>, StateFrom<TMachine>>;
37
- export declare function isActorRef(item: any): item is ActorRef<any>;
38
- 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>>;
1
+ import type { InvokeCallback, Subscribable, Lazy, Behavior, ActorContext, EventObject, ActorRef, BaseActorRef } from './types';
2
+ /**
3
+ * Returns an actor behavior from a reducer and its initial state.
4
+ *
5
+ * @param transition The pure reducer that returns the next state given the current state and event.
6
+ * @param initialState The initial state of the reducer.
7
+ * @returns An actor behavior
8
+ */
9
+ export declare function fromReducer<TState, TEvent extends EventObject>(transition: (state: TState, event: TEvent, actorContext: ActorContext<TEvent, TState>) => TState, initialState: TState): Behavior<TEvent, TState>;
10
+ export declare const startSignalType = "xstate.init";
11
+ export declare const stopSignalType = "xstate.stop";
12
+ export declare const startSignal: StartSignal;
13
+ export declare const stopSignal: StopSignal;
14
+ export interface StartSignal {
15
+ type: 'xstate.init';
16
+ }
17
+ export interface StopSignal {
18
+ type: 'xstate.stop';
19
+ }
20
+ export declare type LifecycleSignal = StartSignal | StopSignal;
21
+ export declare type LifecycleSignalType = typeof startSignalType | typeof stopSignalType;
22
+ export declare function fromCallback<TEvent extends EventObject>(invokeCallback: InvokeCallback): Behavior<TEvent, undefined>;
23
+ export declare function fromPromise<T>(lazyPromise: Lazy<PromiseLike<T>>): Behavior<{
24
+ type: string;
25
+ }, T | undefined>;
26
+ export declare function fromObservable<T, TEvent extends EventObject>(lazyObservable: Lazy<Subscribable<T>>): Behavior<TEvent, T | undefined>;
27
+ /**
28
+ * Creates an event observable behavior that listens to an observable
29
+ * that delivers event objects.
30
+ *
31
+ *
32
+ * @param lazyObservable A function that creates an observable
33
+ * @returns An event observable behavior
34
+ */
35
+ export declare function fromEventObservable<T extends EventObject>(lazyObservable: Lazy<Subscribable<T>>): Behavior<EventObject, T | undefined>;
36
+ export declare function isActorRef(item: any): item is ActorRef<any>;
37
+ 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>>;
@@ -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';
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 +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';
2
+ import type { State } from './State';
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';
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, ActorStatus } from './interpreter';
11
+ import { createMachine } from './Machine';
12
+ import { mapState } from './mapState';
13
+ import { State } from './State';
14
+ import { StateNode } from './StateNode';
15
+ export { createSchema, t } from './schema';
16
+ export { SimulatedClock } from './SimulatedClock';
17
+ export { StateMachine } from './StateMachine';
18
+ export { getStateNodes } from './stateUtils';
19
+ export * from './typegenTypes';
20
+ export * from './types';
21
+ export { matchesState, pathToStateValue, toObserver, toSCXMLEvent } from './utils';
22
+ export { StateNode, State, mapState, actions, assign, send, 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,108 @@
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 { AnyActorRef, AnyStateMachine, Behavior, EventFromBehavior, InterpreterFrom, SnapshotFrom } from './types';
2
+ import { AreAllImplementationsAssumedToBeProvided } from './typegenTypes';
3
+ import { ActorRef, DoneEvent, EventObject, InteropSubscribable, InterpreterOptions, Observer, SCXML, SendActionObject, StateValue, Subscription } from './types';
4
+ import { symbolObservable } from './symbolObservable';
5
+ export declare type SnapshotListener<TBehavior extends Behavior<any, any>> = (state: SnapshotFrom<TBehavior>) => void;
6
+ export declare type EventListener<TEvent extends EventObject = EventObject> = (event: TEvent) => void;
7
+ export declare type Listener = () => void;
8
+ export declare 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
+ declare type InternalStateFrom<TBehavior extends Behavior<any, any, any>> = TBehavior extends Behavior<infer _, infer __, infer TInternalState> ? TInternalState : never;
19
+ export declare class Interpreter<TBehavior extends Behavior<any, any>, TEvent extends EventObject = EventFromBehavior<TBehavior>> implements ActorRef<TEvent, SnapshotFrom<TBehavior>> {
20
+ behavior: TBehavior;
21
+ /**
22
+ * The current state of the interpreted behavior.
23
+ */
24
+ private _state?;
25
+ /**
26
+ * The clock that is responsible for setting and clearing timeouts, such as delayed events and transitions.
27
+ */
28
+ clock: Clock;
29
+ options: Readonly<InterpreterOptions>;
30
+ /**
31
+ * The unique identifier for this actor relative to its parent.
32
+ */
33
+ id: string;
34
+ private mailbox;
35
+ private delayedEventsMap;
36
+ private observers;
37
+ private logger;
38
+ /**
39
+ * Whether the service is started.
40
+ */
41
+ status: ActorStatus;
42
+ _parent?: ActorRef<any>;
43
+ ref: ActorRef<TEvent>;
44
+ private _actorContext;
45
+ /**
46
+ * The globally unique process ID for this invocation.
47
+ */
48
+ sessionId: string;
49
+ _forwardTo: Set<AnyActorRef>;
50
+ /**
51
+ * Creates a new Interpreter instance (i.e., service) for the given behavior with the provided options, if any.
52
+ *
53
+ * @param behavior The behavior to be interpreted
54
+ * @param options Interpreter options
55
+ */
56
+ constructor(behavior: TBehavior, options?: InterpreterOptions);
57
+ private _deferred;
58
+ private _getInitialState;
59
+ private update;
60
+ onTransition(listener: SnapshotListener<TBehavior>): this;
61
+ subscribe(observer: Observer<SnapshotFrom<TBehavior>>): Subscription;
62
+ subscribe(nextListener?: (state: SnapshotFrom<TBehavior>) => void, errorListener?: (error: any) => void, completeListener?: () => void): Subscription;
63
+ /**
64
+ * Adds a state listener that is notified when the statechart has reached its final state.
65
+ * @param listener The state listener
66
+ */
67
+ onDone(listener: EventListener<DoneEvent>): this;
68
+ /**
69
+ * Starts the interpreter from the given state, or the initial state.
70
+ * @param initialState The state to start the statechart from
71
+ */
72
+ start(initialState?: InternalStateFrom<TBehavior> | StateValue): this;
73
+ private _process;
74
+ /**
75
+ * Stops the interpreter and unsubscribe all listeners.
76
+ */
77
+ stop(): this;
78
+ private _complete;
79
+ private _stop;
80
+ /**
81
+ * Sends an event to the running interpreter to trigger a transition.
82
+ *
83
+ * An array of events (batched) can be sent as well, which will send all
84
+ * batched events to the running interpreter. The listeners will be
85
+ * notified only **once** when all events are processed.
86
+ *
87
+ * @param event The event(s) to send
88
+ */
89
+ send(event: TEvent | SCXML.Event<TEvent>): void;
90
+ private forward;
91
+ delaySend(sendAction: SendActionObject): void;
92
+ cancel(sendId: string | number): void;
93
+ private attachDevTools;
94
+ toJSON(): {
95
+ id: string;
96
+ };
97
+ [Symbol.observable](): InteropSubscribable<SnapshotFrom<TBehavior>>;
98
+ getSnapshot(): SnapshotFrom<TBehavior>;
99
+ }
100
+ /**
101
+ * Creates a new Interpreter instance for the given machine with the provided options, if any.
102
+ *
103
+ * @param machine The machine to interpret
104
+ * @param options Interpreter options
105
+ */
106
+ export declare function interpret<TMachine extends AnyStateMachine>(machine: AreAllImplementationsAssumedToBeProvided<TMachine['__TResolvedTypesMeta']> extends true ? TMachine : 'Some implementations missing', options?: InterpreterOptions): InterpreterFrom<TMachine>;
107
+ export declare function interpret<TBehavior extends Behavior<any, any>>(behavior: TBehavior, options?: InterpreterOptions): Interpreter<TBehavior>;
108
+ export {};
@@ -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,8 +1,8 @@
1
- import { ActorRef } from './types';
2
- export interface Registry {
3
- bookId(): string;
4
- register(id: string, actor: ActorRef<any>): string;
5
- get(id: string): ActorRef<any> | undefined;
6
- free(id: string): void;
7
- }
8
- export declare const registry: Registry;
1
+ import { ActorRef } from './types';
2
+ export interface Registry {
3
+ bookId(): string;
4
+ register(id: string, actor: ActorRef<any>): string;
5
+ get(id: string): ActorRef<any> | undefined;
6
+ free(id: string): void;
7
+ }
8
+ export declare const registry: Registry;
@@ -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;
@@ -1,2 +1,2 @@
1
- import { MachineContext, EventObject, SCXML, InvokeActionObject, AnyStateMachine, Spawner } from '.';
2
- export declare function createSpawner<TContext extends MachineContext, TEvent extends EventObject>(machine: AnyStateMachine, context: TContext, _event: SCXML.Event<TEvent>, mutCapturedActions: InvokeActionObject[]): Spawner;
1
+ import { MachineContext, EventObject, SCXML, InvokeActionObject, AnyStateMachine, Spawner } from '.';
2
+ export declare function createSpawner<TContext extends MachineContext, TEvent extends EventObject>(machine: AnyStateMachine, context: TContext, _event: SCXML.Event<TEvent>, mutCapturedActions: InvokeActionObject[]): Spawner;