@xmachines/play-xstate 2.0.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +66 -65
- package/dist/define-player.d.ts +16 -16
- package/dist/define-player.js +16 -16
- package/dist/errors.d.ts +57 -50
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +63 -55
- package/dist/errors.js.map +1 -1
- package/dist/guards/compose.d.ts +53 -50
- package/dist/guards/compose.d.ts.map +1 -1
- package/dist/guards/compose.js +67 -63
- package/dist/guards/compose.js.map +1 -1
- package/dist/guards/helpers.d.ts +22 -22
- package/dist/guards/helpers.js +23 -23
- package/dist/guards/index.d.ts +9 -9
- package/dist/guards/index.js +9 -9
- package/dist/guards/types.d.ts +9 -8
- package/dist/guards/types.d.ts.map +1 -1
- package/dist/index.d.ts +6 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -7
- package/dist/index.js.map +1 -1
- package/dist/player-actor.d.ts +162 -146
- package/dist/player-actor.d.ts.map +1 -1
- package/dist/player-actor.js +269 -241
- package/dist/player-actor.js.map +1 -1
- package/dist/routing/build-url.d.ts +19 -16
- package/dist/routing/build-url.d.ts.map +1 -1
- package/dist/routing/build-url.js +62 -59
- package/dist/routing/build-url.js.map +1 -1
- package/dist/routing/derive-current-route.d.ts +42 -36
- package/dist/routing/derive-current-route.d.ts.map +1 -1
- package/dist/routing/derive-current-route.js +57 -49
- package/dist/routing/derive-current-route.js.map +1 -1
- package/dist/routing/derive-initial-route.d.ts +23 -20
- package/dist/routing/derive-initial-route.d.ts.map +1 -1
- package/dist/routing/derive-initial-route.js +27 -24
- package/dist/routing/derive-initial-route.js.map +1 -1
- package/dist/routing/derive-route.d.ts +38 -37
- package/dist/routing/derive-route.d.ts.map +1 -1
- package/dist/routing/derive-route.js +45 -42
- package/dist/routing/derive-route.js.map +1 -1
- package/dist/routing/format-play-route-transitions.d.ts +34 -28
- package/dist/routing/format-play-route-transitions.d.ts.map +1 -1
- package/dist/routing/format-play-route-transitions.js +32 -28
- package/dist/routing/format-play-route-transitions.js.map +1 -1
- package/dist/routing/index.d.ts +3 -3
- package/dist/routing/index.js +3 -3
- package/dist/routing/types.d.ts +12 -11
- package/dist/routing/types.d.ts.map +1 -1
- package/dist/types.d.ts +64 -60
- package/dist/types.d.ts.map +1 -1
- package/dist/view/derive-current-view.d.ts +42 -40
- package/dist/view/derive-current-view.d.ts.map +1 -1
- package/dist/view/derive-current-view.js +51 -47
- package/dist/view/derive-current-view.js.map +1 -1
- package/package.json +7 -6
package/dist/player-actor.d.ts
CHANGED
|
@@ -3,28 +3,31 @@ import { AbstractActor, type Routable, type Viewable, type PlaySpec } from "@xma
|
|
|
3
3
|
import { Signal } from "@xmachines/play-signals";
|
|
4
4
|
import type { PlayerOptions } from "./types.js";
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* The concrete XState actor. It implements the signal protocol of the Play Architecture
|
|
7
7
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* XState
|
|
13
|
-
*
|
|
8
|
+
* The class extends {@link @xmachines/play-actor!AbstractActor}, and therefore the
|
|
9
|
+
* `Actor` class of XState. It gives you the XState v5 integration, and it keeps the
|
|
10
|
+
* compatibility with the ecosystem, such as the XState inspection and the devtools.
|
|
11
|
+
* The constructor of the base class receives the machine. Therefore a `PlayerActor`
|
|
12
|
+
* **is** the XState actor, and it is no wrapper around one: every member of the
|
|
13
|
+
* XState `Actor` class works on the state of this instance, and this class adds the
|
|
14
|
+
* reactive state on the TC39 Signals for the observation by the infrastructure.
|
|
14
15
|
*
|
|
15
|
-
* **Capabilities:**
|
|
16
|
-
* {@link @xmachines/play-actor!
|
|
17
|
-
*
|
|
16
|
+
* **Capabilities:** the class implements both the
|
|
17
|
+
* {@link @xmachines/play-actor!Routable} interface and the
|
|
18
|
+
* {@link @xmachines/play-actor!Viewable} interface. It therefore supports the
|
|
19
|
+
* routing and the view rendering.
|
|
18
20
|
*
|
|
19
|
-
* **Architectural
|
|
20
|
-
* XState machine
|
|
21
|
-
* the actor
|
|
22
|
-
*
|
|
21
|
+
* **Architectural context:** the class implements **Actor Authority (INV-01)**,
|
|
22
|
+
* because the guards of the XState machine control every decision of the
|
|
23
|
+
* navigation. The infrastructure observes the signals of the actor (`state`,
|
|
24
|
+
* `currentRoute`, and `currentView`), but it changes no state directly: every
|
|
25
|
+
* change goes through the event handlers of the state machine.
|
|
23
26
|
*
|
|
24
|
-
* @typeParam TMachine - XState v5 state machine
|
|
27
|
+
* @typeParam TMachine - The type of the XState v5 state machine
|
|
25
28
|
*
|
|
26
29
|
* @example
|
|
27
|
-
*
|
|
30
|
+
* The creation of an actor, and its lifecycle
|
|
28
31
|
* ```typescript
|
|
29
32
|
* import { setup } from "xstate";
|
|
30
33
|
* import { definePlayer } from "@xmachines/play-xstate";
|
|
@@ -35,7 +38,7 @@ import type { PlayerOptions } from "./types.js";
|
|
|
35
38
|
* idle: {
|
|
36
39
|
* meta: {
|
|
37
40
|
* route: '/',
|
|
38
|
-
* // A view spec needs `root` and `elements
|
|
41
|
+
* // A view spec needs `root` and `elements`. Every other shape derives null.
|
|
39
42
|
* view: {
|
|
40
43
|
* root: 'home',
|
|
41
44
|
* elements: { home: { type: 'HomePage', props: {}, children: [] } },
|
|
@@ -49,13 +52,13 @@ import type { PlayerOptions } from "./types.js";
|
|
|
49
52
|
* const actor = createPlayer();
|
|
50
53
|
* actor.start();
|
|
51
54
|
*
|
|
52
|
-
* // Observe signals
|
|
55
|
+
* // Observe the signals
|
|
53
56
|
* console.log(actor.currentRoute.get()); // '/'
|
|
54
57
|
* console.log(actor.currentView.get()?.root); // 'home'
|
|
55
58
|
* ```
|
|
56
59
|
*
|
|
57
60
|
* @example
|
|
58
|
-
*
|
|
61
|
+
* The signal lifecycle with a watcher
|
|
59
62
|
* ```typescript
|
|
60
63
|
* import { Signal } from "@xmachines/play-signals";
|
|
61
64
|
*
|
|
@@ -68,82 +71,86 @@ import type { PlayerOptions } from "./types.js";
|
|
|
68
71
|
*
|
|
69
72
|
* watcher.watch(actor.state);
|
|
70
73
|
* actor.send({ type: 'play.route', to: '#about' });
|
|
71
|
-
* //
|
|
74
|
+
* // The watcher schedules its own notification in a microtask
|
|
72
75
|
* ```
|
|
73
76
|
*
|
|
74
77
|
* @see [Play RFC](../../docs/rfc/play.md)
|
|
75
|
-
* @see {@link definePlayer} for
|
|
76
|
-
* @see {@link @xmachines/play-actor!AbstractActor} for signal protocol
|
|
77
|
-
* @see {@link @xmachines/play-actor!Routable} for routing capability
|
|
78
|
-
* @see {@link @xmachines/play-actor!Viewable} for view rendering capability
|
|
78
|
+
* @see {@link definePlayer} for the creation through a factory
|
|
79
|
+
* @see {@link @xmachines/play-actor!AbstractActor} for the signal protocol
|
|
80
|
+
* @see {@link @xmachines/play-actor!Routable} for the routing capability
|
|
81
|
+
* @see {@link @xmachines/play-actor!Viewable} for the view rendering capability
|
|
79
82
|
*
|
|
80
83
|
* @remarks
|
|
81
|
-
* **
|
|
82
|
-
*
|
|
83
|
-
* `meta.route
|
|
84
|
+
* **The routing:** this actor supports the `route: {}` config pattern of XState and
|
|
85
|
+
* also a `play.route` event with parameters. The `deriveRoute()` function reads
|
|
86
|
+
* `meta.route`, which is the Stately pattern, for a URL template, and it substitutes
|
|
87
|
+
* each parameter.
|
|
84
88
|
*
|
|
85
|
-
* **
|
|
86
|
-
* `Signal.
|
|
87
|
-
*
|
|
89
|
+
* **The pattern of the view signal:** the `currentView` signal is a direct
|
|
90
|
+
* `Signal.State`, and not a `Signal.Computed`. The propagation to a watcher in
|
|
91
|
+
* PlayRenderer is therefore correct. The class derives each view at the entry of a
|
|
92
|
+
* state and keeps it, and it computes no view on a read.
|
|
88
93
|
*/
|
|
89
94
|
export declare class PlayerActor<TMachine extends AnyStateMachine> extends AbstractActor<AnyActorLogic, EventFromLogic<TMachine>> implements Routable, Viewable {
|
|
90
95
|
private playerOptions?;
|
|
91
96
|
/**
|
|
92
|
-
*
|
|
97
|
+
* Tells you if this constructor returned already.
|
|
93
98
|
*
|
|
94
|
-
* XState
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
+
* XState gives the actor to a context factory as `self`, and to an `inspect`
|
|
100
|
+
* observer as `actorRef`, from inside its own constructor. No field of this class
|
|
101
|
+
* exists at that moment, and XState itself refuses to read the snapshot there:
|
|
102
|
+
* "Snapshot can't be read while the actor initializes itself". Therefore each thing
|
|
103
|
+
* that the code can reach from that window must test this field first.
|
|
99
104
|
*/
|
|
100
105
|
private constructed?;
|
|
101
106
|
/**
|
|
102
|
-
* The
|
|
107
|
+
* The live options object of the caller, or an empty object during the construction.
|
|
103
108
|
*
|
|
104
|
-
* XState
|
|
105
|
-
*
|
|
106
|
-
* any field here
|
|
107
|
-
* that window
|
|
108
|
-
*
|
|
109
|
-
* read
|
|
109
|
+
* XState gives this actor to a context factory as `self`, and to an `inspect`
|
|
110
|
+
* observer as `actorRef`, from inside its own constructor, before the code assigns
|
|
111
|
+
* any field here. A read of a hook through this accessor therefore does not throw
|
|
112
|
+
* in that window. A throw goes to the initialization of XState, which parks it as
|
|
113
|
+
* an error snapshot. The accessor also keeps the behavior that the documentation of
|
|
114
|
+
* the object promises: a read at the moment of the delivery.
|
|
110
115
|
*
|
|
111
|
-
* The
|
|
112
|
-
* This target compiles class
|
|
113
|
-
* after `super()` returns
|
|
114
|
-
*
|
|
115
|
-
* emits nothing,
|
|
116
|
+
* The fields below that this window touches have a `declare` modifier for the same
|
|
117
|
+
* reason. This target compiles a class field into `Object.defineProperty`, which
|
|
118
|
+
* runs after `super()` returns. A plain declaration, with an initializer or without
|
|
119
|
+
* one, therefore resets each value of the window to `undefined`. A `declare`
|
|
120
|
+
* modifier emits nothing, and those values survive.
|
|
116
121
|
*/
|
|
117
122
|
private get hooks();
|
|
118
123
|
/**
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
* before start()
|
|
124
|
+
* The record of the real lifecycle transitions, so that onStart and onStop each
|
|
125
|
+
* fire one time. The status of XState is internal, and a machine snapshot reads
|
|
126
|
+
* "active" before start() already. Therefore neither of them can separate an actor
|
|
127
|
+
* that did not start yet from an actor that runs.
|
|
122
128
|
*/
|
|
123
129
|
private lifecycle?;
|
|
124
130
|
/**
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
*
|
|
131
|
+
* The subscriptions of the user code without an error listener. The dispatch of
|
|
132
|
+
* XState throws an actor error again, globally, for them. It does this one time for
|
|
133
|
+
* each delivery, with a shared flag. Therefore the loud default of the internal
|
|
134
|
+
* error listener, which also throws again, must stand down while such a
|
|
135
|
+
* subscription is active. Without this rule, the code reports the same error two
|
|
136
|
+
* times.
|
|
130
137
|
*/
|
|
131
138
|
private nextOnlySubscriptions?;
|
|
132
139
|
/**
|
|
133
|
-
* The last snapshot the view pipeline
|
|
134
|
-
*
|
|
135
|
-
* snapshot
|
|
136
|
-
* reference
|
|
137
|
-
* snapshot
|
|
138
|
-
*
|
|
140
|
+
* The last snapshot of the view pipeline. XState notifies each observer on EVERY
|
|
141
|
+
* event that it processes, and an event that it ignores delivers the identical
|
|
142
|
+
* snapshot again. deriveCurrentView is pure in the snapshot. Therefore an identical
|
|
143
|
+
* reference can change no result. The first value is undefined, and never a
|
|
144
|
+
* snapshot: the snapshot of the construction has the same reference as the snapshot
|
|
145
|
+
* that start() replays, and that value therefore stops the first view.
|
|
139
146
|
*/
|
|
140
147
|
private lastViewSnapshot;
|
|
141
148
|
state: Signal.State<ReturnType<TMachine["transition"]>>;
|
|
142
149
|
/**
|
|
143
|
-
*
|
|
150
|
+
* Tells you if the current state of the actor accepts the given event.
|
|
144
151
|
*
|
|
145
|
-
*
|
|
146
|
-
* compile error.
|
|
152
|
+
* The type is the event union of the machine. An unknown event type is therefore a
|
|
153
|
+
* compile error. The method evaluates the event against the snapshot signal.
|
|
147
154
|
*
|
|
148
155
|
* @example
|
|
149
156
|
* ```typescript
|
|
@@ -152,165 +159,174 @@ export declare class PlayerActor<TMachine extends AnyStateMachine> extends Abstr
|
|
|
152
159
|
*/
|
|
153
160
|
can(event: EventFromLogic<TMachine>): boolean;
|
|
154
161
|
/**
|
|
155
|
-
* A TC39 `Signal.Computed
|
|
156
|
-
* machine state
|
|
162
|
+
* A TC39 `Signal.Computed`. It derives the current URL path from the `meta.route`
|
|
163
|
+
* template of the active machine state and from the context of the actor.
|
|
157
164
|
*
|
|
158
|
-
*
|
|
159
|
-
*
|
|
160
|
-
* is caught
|
|
161
|
-
*
|
|
165
|
+
* It returns `null` when the current state has no `meta.route` field, and also when
|
|
166
|
+
* it cannot resolve the complete route template. A necessary `:param` that the
|
|
167
|
+
* context does not hold is caught inside the signal, and a
|
|
168
|
+
* `MissingRouteParamError` therefore never leaves `get()`: that condition is
|
|
169
|
+
* temporary during a transition, and the signal computes the value again on the next
|
|
162
170
|
* snapshot.
|
|
163
171
|
*
|
|
164
172
|
* @example
|
|
165
173
|
* ```typescript
|
|
166
|
-
* //
|
|
167
|
-
* // and null while the param is still
|
|
174
|
+
* // It returns "/profile/alice" when context.params.userId === "alice",
|
|
175
|
+
* // and null while the param is still absent.
|
|
168
176
|
* const route = actor.currentRoute.get();
|
|
169
177
|
* ```
|
|
170
178
|
*/
|
|
171
179
|
currentRoute: Signal.Computed<string | null>;
|
|
172
180
|
/**
|
|
173
|
-
* The route
|
|
174
|
-
* never changes
|
|
181
|
+
* The route of the initial state of the machine. The constructor fixes it, and it
|
|
182
|
+
* never changes, also when the code restores the actor from a snapshot.
|
|
175
183
|
*
|
|
176
|
-
*
|
|
177
|
-
* (
|
|
178
|
-
* different
|
|
184
|
+
* A router bridge compares it with the browser URL, and it therefore separates a
|
|
185
|
+
* deep link (a URL that is not the initial one → the router wins) from a restore
|
|
186
|
+
* (the initial URL, and the actor at a different route from the restore → the actor
|
|
187
|
+
* wins).
|
|
179
188
|
*
|
|
180
|
-
*
|
|
181
|
-
*
|
|
182
|
-
* `meta.route` templates are fixed at
|
|
183
|
-
* substitution uses the
|
|
184
|
-
*
|
|
185
|
-
* value
|
|
189
|
+
* `deriveInitialRoute` derives the value statically from the machine definition,
|
|
190
|
+
* with the pure `initialTransition` helper of XState: the chain of the initial states
|
|
191
|
+
* and their `meta.route` templates are fixed at the moment of the machine
|
|
192
|
+
* definition, and the substitution of a `:param` uses the real initial context of
|
|
193
|
+
* the machine for the `input` of this actor. The code makes no second actor, and a
|
|
194
|
+
* snapshot of a restore changes the value never: it is always the **default**
|
|
195
|
+
* initial route of the machine.
|
|
186
196
|
*/
|
|
187
197
|
readonly initialRoute: string | null;
|
|
188
198
|
/**
|
|
189
|
-
*
|
|
190
|
-
* `meta.view` metadata.
|
|
199
|
+
* The reactive signal of the current view spec. The signal derives the spec from
|
|
200
|
+
* the `meta.view` metadata of the active state.
|
|
191
201
|
*
|
|
192
|
-
*
|
|
193
|
-
* a different state
|
|
194
|
-
* spec
|
|
195
|
-
*
|
|
196
|
-
*
|
|
202
|
+
* It emits a **new object reference** on each real change of the view on the
|
|
203
|
+
* screen: the view of a different state, or a change of a param or of the context
|
|
204
|
+
* that changes the resolved spec. A re-entry with `reenter: true` and new params
|
|
205
|
+
* also changes the spec. A snapshot that changes no view on the screen, such as an
|
|
206
|
+
* assign of the context alone, keeps the previous reference. A provider below the
|
|
207
|
+
* signal therefore mounts the UI again not on every event.
|
|
197
208
|
*
|
|
198
|
-
* The
|
|
199
|
-
* `state` under the read-only `/context` subtree
|
|
200
|
-
*
|
|
201
|
-
* (`{ $state: "/context/params/section" }`).
|
|
202
|
-
*
|
|
209
|
+
* The `PlaySpec` of the emission carries the context of the machine in its composed
|
|
210
|
+
* `state` field, under the read-only `/context` subtree. A spec therefore reads the
|
|
211
|
+
* context, and also each URL param, through the ordinary state grammar
|
|
212
|
+
* (`{ $state: "/context/params/section" }`). The context-projection module of
|
|
213
|
+
* `@xmachines/play-actor` holds the complete contract.
|
|
203
214
|
*
|
|
204
|
-
*
|
|
215
|
+
* The signal returns `null` when the current state has no `meta.view` metadata.
|
|
205
216
|
*
|
|
206
|
-
* Two states
|
|
207
|
-
*
|
|
208
|
-
* provider
|
|
209
|
-
*
|
|
217
|
+
* Two states can declare two separate `meta.view` literals with an identical
|
|
218
|
+
* structure. A transition between those two states then emits two different
|
|
219
|
+
* references, and a provider mounts the UI again. Move the shared literal into one
|
|
220
|
+
* `typedSpec` constant, and the identity then removes the duplicate.
|
|
210
221
|
*
|
|
211
222
|
* @example
|
|
212
223
|
* ```typescript
|
|
213
224
|
* const view = actor.currentView.get();
|
|
214
225
|
* if (view) {
|
|
215
|
-
* console.log(view.root); //
|
|
216
|
-
* console.log(view.elements); // @xmachines/json-render-core
|
|
226
|
+
* console.log(view.root); // for example "root"
|
|
227
|
+
* console.log(view.elements); // the Spec elements of @xmachines/json-render-core
|
|
217
228
|
* }
|
|
218
229
|
* ```
|
|
219
230
|
*/
|
|
220
231
|
readonly currentView: Signal.State<PlaySpec | null>;
|
|
221
232
|
constructor(machine: TMachine, options: PlayerOptions<TMachine>, input?: InputFrom<TMachine>, restoredSnapshot?: ActorOptions<TMachine>["snapshot"]);
|
|
222
233
|
/**
|
|
223
|
-
*
|
|
234
|
+
* Starts the actor.
|
|
224
235
|
*
|
|
225
|
-
*
|
|
226
|
-
* running
|
|
227
|
-
* `start()`
|
|
228
|
-
* while
|
|
229
|
-
*
|
|
236
|
+
* The method fires `onStart` on each real start, which is every transition from
|
|
237
|
+
* "not running" to "running". A start after a stop is such a transition, and XState
|
|
238
|
+
* permits it: its own `start()` stops only while the actor RUNS already. A second
|
|
239
|
+
* call while the actor runs fires no hook. Therefore a defensive double mount runs
|
|
240
|
+
* the side effects of `onStart` one time for one real start.
|
|
230
241
|
*/
|
|
231
242
|
start(): this;
|
|
232
243
|
/**
|
|
233
|
-
*
|
|
244
|
+
* Stops the actor and cleans up.
|
|
234
245
|
*
|
|
235
|
-
*
|
|
236
|
-
*
|
|
237
|
-
*
|
|
238
|
-
* against
|
|
239
|
-
* actor for
|
|
240
|
-
* `onStart` again.
|
|
246
|
+
* The method fires `onStop` only when the actor ran. This matches XState, where a
|
|
247
|
+
* stop of an actor that never started, or of an actor that stopped already, does
|
|
248
|
+
* nothing and tears nothing down. Therefore the paired cleanup runs never two
|
|
249
|
+
* times, and it runs never against a resource that `onStart` did not take. A stop
|
|
250
|
+
* does not close the actor for ever: a later `start()` is a new lifecycle, and it
|
|
251
|
+
* fires `onStart` again.
|
|
241
252
|
*/
|
|
242
253
|
stop(): this;
|
|
243
254
|
/**
|
|
244
|
-
*
|
|
255
|
+
* Sends an event to this actor.
|
|
245
256
|
*
|
|
246
|
-
* The
|
|
247
|
-
*
|
|
257
|
+
* The guards of the state machine of the actor decide if the event causes a
|
|
258
|
+
* transition. Give any event of the event union of the machine: a domain event, a
|
|
259
|
+
* routing event, and so on.
|
|
248
260
|
*
|
|
249
|
-
* @param event - An event
|
|
261
|
+
* @param event - An event of the `EventFromLogic<TMachine>` union of the machine.
|
|
250
262
|
*
|
|
251
|
-
* @throws {InvalidEventError} When `event` is not a plain object
|
|
252
|
-
* a string, number
|
|
263
|
+
* @throws {InvalidEventError} When `event` is not a plain object, for example
|
|
264
|
+
* `null`, `undefined`, a string, or a number. Import the class from
|
|
265
|
+
* `@xmachines/play-xstate/errors`.
|
|
253
266
|
*
|
|
254
267
|
* @example
|
|
255
268
|
* ```typescript
|
|
256
|
-
* //
|
|
269
|
+
* // A domain event, with the type of the event union of the machine
|
|
257
270
|
* actor.send({ type: "auth.login", userId: "123" });
|
|
258
271
|
*
|
|
259
|
-
* //
|
|
272
|
+
* // A routing event
|
|
260
273
|
* actor.send({ type: "play.route", to: "#home" });
|
|
261
274
|
* ```
|
|
262
275
|
*/
|
|
263
276
|
send(event: EventFromLogic<TMachine>): void;
|
|
264
277
|
/**
|
|
265
|
-
*
|
|
278
|
+
* Returns the current snapshot
|
|
266
279
|
*/
|
|
267
280
|
getSnapshot(): ReturnType<Actor<TMachine>["getSnapshot"]>;
|
|
268
281
|
/**
|
|
269
|
-
*
|
|
282
|
+
* Subscribes to the snapshot updates of this actor.
|
|
270
283
|
*
|
|
271
|
-
*
|
|
284
|
+
* The method accepts an observer object, exactly like `Actor.subscribe` of XState.
|
|
272
285
|
*
|
|
273
|
-
* @param observer -
|
|
274
|
-
* @returns
|
|
286
|
+
* @param observer - The observer, with a `next`, an `error`, and a `complete` handler.
|
|
287
|
+
* @returns The subscription, with an `unsubscribe()` method.
|
|
275
288
|
*/
|
|
276
289
|
subscribe(observer: Observer<SnapshotFrom<TMachine>>): Subscription;
|
|
277
290
|
/**
|
|
278
|
-
*
|
|
291
|
+
* Subscribes to the snapshot updates of this actor.
|
|
279
292
|
*
|
|
280
|
-
*
|
|
293
|
+
* The method accepts listener functions, exactly like `Actor.subscribe` of XState.
|
|
281
294
|
*
|
|
282
|
-
* @param nextListener -
|
|
283
|
-
* @param errorListener -
|
|
284
|
-
* @param completeListener -
|
|
285
|
-
* @returns
|
|
295
|
+
* @param nextListener - The listener function of each snapshot.
|
|
296
|
+
* @param errorListener - The actor calls it on an error.
|
|
297
|
+
* @param completeListener - The actor calls it when it completes, which means that it reaches a final state.
|
|
298
|
+
* @returns The subscription, with an `unsubscribe()` method.
|
|
286
299
|
*/
|
|
287
300
|
subscribe(nextListener?: (snapshot: SnapshotFrom<TMachine>) => void, errorListener?: (error: unknown) => void, completeListener?: () => void): Subscription;
|
|
288
301
|
/**
|
|
289
|
-
*
|
|
302
|
+
* Listens for the events that this actor emits with the `emit` action.
|
|
290
303
|
*
|
|
291
|
-
* @param type -
|
|
292
|
-
* @param handler -
|
|
293
|
-
* @returns
|
|
304
|
+
* @param type - The type of the emitted event to listen for, or `"*"` for every event.
|
|
305
|
+
* @param handler - The actor calls it with each emitted event that matches.
|
|
306
|
+
* @returns The subscription, with an `unsubscribe()` method.
|
|
294
307
|
*/
|
|
295
308
|
on<TType extends EmittedFrom<TMachine>["type"] | "*">(type: TType, handler: (emitted: EmittedFrom<TMachine> & (TType extends "*" ? unknown : {
|
|
296
309
|
type: TType;
|
|
297
310
|
})) => void): Subscription;
|
|
298
311
|
/**
|
|
299
|
-
*
|
|
312
|
+
* Returns the persisted snapshot of this actor.
|
|
300
313
|
*
|
|
301
|
-
*
|
|
302
|
-
* `restore.snapshot` option.
|
|
314
|
+
* Use it to serialize the state, and to restore it later with the
|
|
315
|
+
* `restore.snapshot` option of the factory.
|
|
303
316
|
*/
|
|
304
317
|
getPersistedSnapshot(options?: unknown): Snapshot<unknown>;
|
|
305
318
|
/**
|
|
306
|
-
*
|
|
307
|
-
*
|
|
319
|
+
* Derives the view at the entry of a state, and keeps it. This happens one time for
|
|
320
|
+
* each transition. The signal holds the view, and the code computes it not on each
|
|
321
|
+
* read.
|
|
308
322
|
*
|
|
309
|
-
* @param snapshot -
|
|
323
|
+
* @param snapshot - The current XState snapshot
|
|
310
324
|
*/
|
|
311
325
|
private validateAndCacheView;
|
|
312
326
|
/**
|
|
313
|
-
*
|
|
327
|
+
* The dispose method, for the cleanup. It is the alias of {@link stop}.
|
|
328
|
+
*
|
|
329
|
+
* @deprecated Use {@link stop}. Will be removed in the next major.
|
|
314
330
|
*/
|
|
315
331
|
dispose(): void;
|
|
316
332
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"player-actor.d.ts","sourceRoot":"","sources":["../src/player-actor.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,EACL,KAAK,eAAe,EACpB,KAAK,aAAa,EAElB,KAAK,WAAW,EAChB,KAAK,SAAS,EACd,KAAK,YAAY,EACjB,KAAK,QAAQ,EACb,KAAK,QAAQ,EACb,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,MAAM,QAAQ,CAAC;AAChB,OAAO,EACN,aAAa,EAGb,KAAK,QAAQ,EACb,KAAK,QAAQ,EACb,KAAK,QAAQ,EACb,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,MAA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