1 | import { symbolObservable } from "./symbolObservable.js";
|
2 | import { AnyActorSystem, Clock } from "./system.js";
|
3 | export declare let executingCustomAction: boolean;
|
4 | import type { AnyActorLogic, AnyActorRef, ConditionalRequired, EmittedFrom, EventFromLogic, InputFrom, IsNotNever, Snapshot, SnapshotFrom } from "./types.js";
|
5 | import { ActorOptions, ActorRef, InteropSubscribable, Observer, Subscription } from "./types.js";
|
6 | export declare const $$ACTOR_TYPE = 1;
|
7 | export declare enum ProcessingStatus {
|
8 | NotStarted = 0,
|
9 | Running = 1,
|
10 | Stopped = 2
|
11 | }
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | export declare class Actor<TLogic extends AnyActorLogic> implements ActorRef<SnapshotFrom<TLogic>, EventFromLogic<TLogic>, EmittedFrom<TLogic>> {
|
18 | logic: TLogic;
|
19 |
|
20 | private _snapshot;
|
21 | |
22 |
|
23 |
|
24 |
|
25 | clock: Clock;
|
26 | options: Readonly<ActorOptions<TLogic>>;
|
27 |
|
28 | id: string;
|
29 | private mailbox;
|
30 | private observers;
|
31 | private eventListeners;
|
32 | private logger;
|
33 | _parent?: AnyActorRef;
|
34 | ref: ActorRef<SnapshotFrom<TLogic>, EventFromLogic<TLogic>, EmittedFrom<TLogic>>;
|
35 | private _actorScope;
|
36 | private _systemId;
|
37 |
|
38 | sessionId: string;
|
39 |
|
40 | system: AnyActorSystem;
|
41 | private _doneEvent?;
|
42 | src: string | AnyActorLogic;
|
43 | |
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 | constructor(logic: TLogic, options?: ActorOptions<TLogic>);
|
51 | private _initState;
|
52 | private _deferred;
|
53 | private update;
|
54 | /**
|
55 | * Subscribe an observer to an actor’s snapshot values.
|
56 | *
|
57 | * @remarks
|
58 | * The observer will receive the actor’s snapshot value when it is emitted.
|
59 | * The observer can be:
|
60 | *
|
61 | * - A plain function that receives the latest snapshot, or
|
62 | * - An observer object whose `.next(snapshot)` method receives the latest
|
63 | * snapshot
|
64 | *
|
65 | * @example
|
66 | *
|
67 | * ```ts
|
68 | * // Observer as a plain function
|
69 | * const subscription = actor.subscribe((snapshot) => {
|
70 | * console.log(snapshot);
|
71 | * });
|
72 | * ```
|
73 | *
|
74 | * @example
|
75 | *
|
76 | * ```ts
|
77 | * // Observer as an object
|
78 | * const subscription = actor.subscribe({
|
79 | * next(snapshot) {
|
80 | * console.log(snapshot);
|
81 | * },
|
82 | * error(err) {
|
83 | *
|
84 | * },
|
85 | * complete() {
|
86 | *
|
87 | * }
|
88 | * });
|
89 | * ```
|
90 | *
|
91 | * The return value of `actor.subscribe(observer)` is a subscription object
|
92 | * that has an `.unsubscribe()` method. You can call
|
93 | * `subscription.unsubscribe()` to unsubscribe the observer:
|
94 | *
|
95 | * @example
|
96 | *
|
97 | * ```ts
|
98 | * const subscription = actor.subscribe((snapshot) => {
|
99 | *
|
100 | * });
|
101 | *
|
102 | * // Unsubscribe the observer
|
103 | * subscription.unsubscribe();
|
104 | * ```
|
105 | *
|
106 | * When the actor is stopped, all of its observers will automatically be
|
107 | * unsubscribed.
|
108 | *
|
109 | * @param observer - Either a plain function that receives the latest
|
110 | * snapshot, or an observer object whose `.next(snapshot)` method receives
|
111 | * the latest snapshot
|
112 | */
|
113 | subscribe(observer: Observer<SnapshotFrom<TLogic>>): Subscription;
|
114 | subscribe(nextListener?: (snapshot: SnapshotFrom<TLogic>) => void, errorListener?: (error: any) => void, completeListener?: () => void): Subscription;
|
115 | on<TType extends EmittedFrom<TLogic>['type'] | '*'>(type: TType, handler: (emitted: EmittedFrom<TLogic> & (TType extends '*' ? unknown : {
|
116 | type: TType;
|
117 | })) => void): Subscription;
|
118 | /** Starts the Actor from the initial state */
|
119 | start(): this;
|
120 | private _process;
|
121 | private _stop;
|
122 | /** Stops the Actor and unsubscribe all listeners. */
|
123 | stop(): this;
|
124 | private _complete;
|
125 | private _reportError;
|
126 | private _error;
|
127 | private _stopProcedure;
|
128 | /**
|
129 | * Sends an event to the running Actor to trigger a transition.
|
130 | *
|
131 | * @param event The event to send
|
132 | */
|
133 | send(event: EventFromLogic<TLogic>): void;
|
134 | private attachDevTools;
|
135 | toJSON(): {
|
136 | xstate$$type: number;
|
137 | id: string;
|
138 | };
|
139 | |
140 |
|
141 |
|
142 |
|
143 |
|
144 |
|
145 |
|
146 |
|
147 |
|
148 |
|
149 |
|
150 |
|
151 |
|
152 | getPersistedSnapshot(): Snapshot<unknown>;
|
153 | [symbolObservable](): InteropSubscribable<SnapshotFrom<TLogic>>;
|
154 | |
155 |
|
156 |
|
157 |
|
158 |
|
159 |
|
160 |
|
161 |
|
162 |
|
163 |
|
164 |
|
165 |
|
166 |
|
167 |
|
168 | getSnapshot(): SnapshotFrom<TLogic>;
|
169 | }
|
170 | export type RequiredActorOptionsKeys<TLogic extends AnyActorLogic> = undefined extends InputFrom<TLogic> ? never : 'input';
|
171 |
|
172 |
|
173 |
|
174 |
|
175 |
|
176 |
|
177 |
|
178 |
|
179 |
|
180 |
|
181 |
|
182 |
|
183 |
|
184 |
|
185 |
|
186 |
|
187 |
|
188 |
|
189 |
|
190 |
|
191 |
|
192 |
|
193 |
|
194 |
|
195 |
|
196 |
|
197 |
|
198 |
|
199 |
|
200 |
|
201 |
|
202 |
|
203 |
|
204 |
|
205 |
|
206 |
|
207 |
|
208 |
|
209 | export declare function createActor<TLogic extends AnyActorLogic>(logic: TLogic, ...[options]: ConditionalRequired<[
|
210 | options?: ActorOptions<TLogic> & {
|
211 | [K in RequiredActorOptionsKeys<TLogic>]: unknown;
|
212 | }
|
213 | ], IsNotNever<RequiredActorOptionsKeys<TLogic>>>): Actor<TLogic>;
|
214 |
|
215 |
|
216 |
|
217 |
|
218 |
|
219 |
|
220 |
|
221 | export declare const interpret: typeof createActor;
|
222 |
|
223 |
|
224 |
|
225 |
|
226 | export type Interpreter = typeof Actor;
|