@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.
Files changed (56) hide show
  1. package/README.md +66 -65
  2. package/dist/define-player.d.ts +16 -16
  3. package/dist/define-player.js +16 -16
  4. package/dist/errors.d.ts +57 -50
  5. package/dist/errors.d.ts.map +1 -1
  6. package/dist/errors.js +63 -55
  7. package/dist/errors.js.map +1 -1
  8. package/dist/guards/compose.d.ts +53 -50
  9. package/dist/guards/compose.d.ts.map +1 -1
  10. package/dist/guards/compose.js +67 -63
  11. package/dist/guards/compose.js.map +1 -1
  12. package/dist/guards/helpers.d.ts +22 -22
  13. package/dist/guards/helpers.js +23 -23
  14. package/dist/guards/index.d.ts +9 -9
  15. package/dist/guards/index.js +9 -9
  16. package/dist/guards/types.d.ts +9 -8
  17. package/dist/guards/types.d.ts.map +1 -1
  18. package/dist/index.d.ts +6 -5
  19. package/dist/index.d.ts.map +1 -1
  20. package/dist/index.js +8 -7
  21. package/dist/index.js.map +1 -1
  22. package/dist/player-actor.d.ts +162 -146
  23. package/dist/player-actor.d.ts.map +1 -1
  24. package/dist/player-actor.js +269 -241
  25. package/dist/player-actor.js.map +1 -1
  26. package/dist/routing/build-url.d.ts +19 -16
  27. package/dist/routing/build-url.d.ts.map +1 -1
  28. package/dist/routing/build-url.js +62 -59
  29. package/dist/routing/build-url.js.map +1 -1
  30. package/dist/routing/derive-current-route.d.ts +42 -36
  31. package/dist/routing/derive-current-route.d.ts.map +1 -1
  32. package/dist/routing/derive-current-route.js +57 -49
  33. package/dist/routing/derive-current-route.js.map +1 -1
  34. package/dist/routing/derive-initial-route.d.ts +23 -20
  35. package/dist/routing/derive-initial-route.d.ts.map +1 -1
  36. package/dist/routing/derive-initial-route.js +27 -24
  37. package/dist/routing/derive-initial-route.js.map +1 -1
  38. package/dist/routing/derive-route.d.ts +38 -37
  39. package/dist/routing/derive-route.d.ts.map +1 -1
  40. package/dist/routing/derive-route.js +45 -42
  41. package/dist/routing/derive-route.js.map +1 -1
  42. package/dist/routing/format-play-route-transitions.d.ts +34 -28
  43. package/dist/routing/format-play-route-transitions.d.ts.map +1 -1
  44. package/dist/routing/format-play-route-transitions.js +32 -28
  45. package/dist/routing/format-play-route-transitions.js.map +1 -1
  46. package/dist/routing/index.d.ts +3 -3
  47. package/dist/routing/index.js +3 -3
  48. package/dist/routing/types.d.ts +12 -11
  49. package/dist/routing/types.d.ts.map +1 -1
  50. package/dist/types.d.ts +64 -60
  51. package/dist/types.d.ts.map +1 -1
  52. package/dist/view/derive-current-view.d.ts +42 -40
  53. package/dist/view/derive-current-view.d.ts.map +1 -1
  54. package/dist/view/derive-current-view.js +51 -47
  55. package/dist/view/derive-current-view.js.map +1 -1
  56. package/package.json +7 -6
@@ -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
- * Concrete XState actor implementing Play Architecture signal protocol
6
+ * The concrete XState actor. It implements the signal protocol of the Play Architecture
7
7
  *
8
- * Extends {@link @xmachines/play-actor!AbstractActor} and so XState's own `Actor` —
9
- * to provide XState v5 integration while maintaining ecosystem compatibility (XState
10
- * inspection, devtools). The machine is handed to the base constructor, so a
11
- * `PlayerActor` **is** the XState actor rather than a wrapper around one: everything
12
- * XState's `Actor` exposes operates on this instance's own state, and the class adds
13
- * TC39 Signal-based reactive state for Infrastructure observation on top.
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:** Implements both {@link @xmachines/play-actor!Routable} and
16
- * {@link @xmachines/play-actor!Viewable} interfaces, providing routing and view
17
- * rendering support.
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 Context:** Implements **Actor Authority (INV-01)** by ensuring the
20
- * XState machine's guards control all navigation decisions. Infrastructure observes
21
- * the actor's signals (`state`, `currentRoute`, `currentView`) but cannot directly
22
- * manipulate state—all mutations flow through the state machine's event handlers.
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 type
27
+ * @typeParam TMachine - The type of the XState v5 state machine
25
28
  *
26
29
  * @example
27
- * Basic actor creation and lifecycle
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` other shapes derive null.
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
- * Signal lifecycle with watchers
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
- * // Watcher notification scheduled via microtask by the watcher itself
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 factory creation
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
- * **Routing:** This actor supports both XState's `route: {}` config pattern
82
- * and `play.route` events with parameters. The `deriveRoute()` function checks
83
- * `meta.route` (Stately pattern) for URL templates with parameter substitution support.
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
- * **View Signal Pattern:** The `currentView` signal is a direct `Signal.State` (not
86
- * `Signal.Computed`) to ensure proper watcher propagation in PlayRenderer. Views are
87
- * cached and updated at state entry, not computed on every read.
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
- * Whether this constructor has returned.
97
+ * Tells you if this constructor returned already.
93
98
  *
94
- * XState hands the actor to a context factory as `self`, and to an
95
- * `inspect` observer as `actorRef`, from inside its own constructor where
96
- * none of this class's fields exist yet and XState itself refuses to read
97
- * the snapshot ("Snapshot can't be read while the actor initializes
98
- * itself"). Anything reachable from that window has to check this first.
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 caller's live options bag, or an empty one during construction.
107
+ * The live options object of the caller, or an empty object during the construction.
103
108
  *
104
- * XState hands this actor to a context factory as `self` and to an
105
- * `inspect` observer as `actorRef` from inside its own constructor, before
106
- * any field here is assigned. Reading hooks through this accessor keeps
107
- * that window from throwing a throw would be caught by XState's
108
- * initialization and parked as an error snapshot while preserving the
109
- * read-at-delivery-time behaviour the bag's own docs promise.
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 window-sensitive fields below are `declare`d for the same reason.
112
- * This target compiles class fields to `Object.defineProperty`, which runs
113
- * after `super()` returns: a plain declaration initializer or not — would
114
- * reset anything the window had written back to `undefined`. `declare`
115
- * emits nothing, so those writes survive.
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
- * Real lifecycle transitions, so onStart/onStop fire once each. XState's
120
- * own status is internal, and a machine snapshot already reads "active"
121
- * before start(), so neither can distinguish not-yet-started from running.
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
- * Userland subscriptions without an error listener. XState's dispatch
126
- * rethrows an actor error globally on their behalf (once per delivery, a
127
- * shared flag), so while one is active the internal error listener's own
128
- * loud-default rethrow must stand down or the same error is reported
129
- * twice.
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 processed. XState notifies observers
134
- * on EVERY processed event an ignored event redelivers the identical
135
- * snapshot and deriveCurrentView is pure in the snapshot, so an identical
136
- * reference cannot change the outcome. Seeded with undefined (never a
137
- * snapshot): the construction-time snapshot is reference-identical to the
138
- * one start() replays, and seeding with it would suppress the initial view.
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
- * Returns whether the actor's current state can accept the given event.
150
+ * Tells you if the current state of the actor accepts the given event.
144
151
  *
145
- * Typed to the machine's event union passing an unknown event type is a
146
- * compile error. Evaluated against the current snapshot signal.
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` that derives the current URL path from the active
156
- * machine state's `meta.route` template and the actor's context.
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
- * Returns `null` when the current state has no `meta.route`, or when the route
159
- * template cannot be fully resolved a required `:param` absent from context
160
- * is caught internally (`MissingRouteParamError` never escapes `get()`): the
161
- * condition is transient mid-transition and the signal recomputes on the next
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
- * // Returns "/profile/alice" when context.params.userId === "alice",
167
- * // and null while the param is still missing.
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 derived from the machine's initial state fixed at construction,
174
- * never changes even when the actor is restored from a snapshot.
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
- * Router bridges compare this against the browser URL to distinguish a deep-link
177
- * (non-initial URL → router wins) from a restore (initial URL + actor at a
178
- * different restored route → actor wins).
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
- * Derived statically from the machine definition via `deriveInitialRoute`
181
- * (XState's pure `initialTransition` helper): the initial state chain and its
182
- * `meta.route` templates are fixed at machine definition time, while `:param`
183
- * substitution uses the machine's real initial context for this actor's `input`.
184
- * No extra actor is ever created, and a restored snapshot never influences the
185
- * value it is always the machine's **default** initial route.
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
- * Reactive signal containing the current view spec derived from the active state's
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
- * Emits a **fresh object reference** whenever the rendered view actually changes —
193
- * a different state's view, or a param/context change that alters the resolved
194
- * spec (including `reenter: true` re-entries with new params). Snapshots that do
195
- * not change the rendered view (e.g. context-only assigns) keep the previous
196
- * reference so downstream providers do not remount the UI on every event.
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 emitted `PlaySpec` carries the machine's context in its composed
199
- * `state` under the read-only `/context` subtree, so specs read context
200
- * URL params included through the ordinary state grammar
201
- * (`{ $state: "/context/params/section" }`). See `@xmachines/play-actor`'s
202
- * context-projection module for the full contract.
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
- * Returns `null` when the current state has no `meta.view` metadata.
215
+ * The signal returns `null` when the current state has no `meta.view` metadata.
205
216
  *
206
- * Two states declaring separate but structurally identical `meta.view`
207
- * literals emit distinct references on a transition between them (a
208
- * provider remount); hoist the shared literal into one `typedSpec` constant
209
- * to deduplicate by identity.
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); // e.g. "root"
216
- * console.log(view.elements); // @xmachines/json-render-core Spec elements
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
- * Start the actor.
234
+ * Starts the actor.
224
235
  *
225
- * Fires `onStart` on each real start every transition from not-running to
226
- * running, including a start after a stop, which XState allows (its own
227
- * `start()` bails only while the actor is already RUNNING). A repeated call
228
- * while running does not re-fire it, so a defensive double mount does not
229
- * re-run `onStart` side effects for one actual start.
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
- * Stop the actor and clean up.
244
+ * Stops the actor and cleans up.
234
245
  *
235
- * Fires `onStop` only when the actor was actually running mirroring
236
- * XState, where stopping a never-started or already-stopped actor is a
237
- * no-op with zero teardown so paired cleanup never runs twice, nor
238
- * against resources `onStart` never acquired. Stopping does not close the
239
- * actor for good: a later `start()` is a fresh lifecycle and fires
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
- * Send an event to this actor.
255
+ * Sends an event to this actor.
245
256
  *
246
- * The actor's state machine guards decide whether the event causes a transition.
247
- * Pass any event from the machine's event union domain events, routing events, etc.
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 from the machine's `EventFromLogic<TMachine>` union.
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 (`null`, `undefined`,
252
- * a string, number, etc.). Import the class from `@xmachines/play-xstate/errors`.
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
- * // Domain event (typed to machine's event union)
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
- * // Routing event
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
- * Get current snapshot
278
+ * Returns the current snapshot
266
279
  */
267
280
  getSnapshot(): ReturnType<Actor<TMachine>["getSnapshot"]>;
268
281
  /**
269
- * Subscribe to this actor's snapshot updates.
282
+ * Subscribes to the snapshot updates of this actor.
270
283
  *
271
- * Accepts an observer object, exactly like XState's `Actor.subscribe`.
284
+ * The method accepts an observer object, exactly like `Actor.subscribe` of XState.
272
285
  *
273
- * @param observer - Observer with `next`/`error`/`complete` handlers.
274
- * @returns Subscription with an `unsubscribe()` method.
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
- * Subscribe to this actor's snapshot updates.
291
+ * Subscribes to the snapshot updates of this actor.
279
292
  *
280
- * Accepts listener functions, exactly like XState's `Actor.subscribe`.
293
+ * The method accepts listener functions, exactly like `Actor.subscribe` of XState.
281
294
  *
282
- * @param nextListener - Snapshot listener function.
283
- * @param errorListener - Called when the actor errors.
284
- * @param completeListener - Called when the actor completes (reaches a final state).
285
- * @returns Subscription with an `unsubscribe()` method.
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
- * Listen for events this actor emits via the `emit` action.
302
+ * Listens for the events that this actor emits with the `emit` action.
290
303
  *
291
- * @param type - Emitted event type to listen for, or `"*"` for all.
292
- * @param handler - Called with each matching emitted event.
293
- * @returns Subscription with an `unsubscribe()` method.
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
- * Get this actor's persisted snapshot.
312
+ * Returns the persisted snapshot of this actor.
300
313
  *
301
- * Suitable for serialization and later restoration via the factory's
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
- * Derive and cache the view at state entry once per transition, stored in
307
- * the signal rather than recomputed per read.
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 - Current XState snapshot
323
+ * @param snapshot - The current XState snapshot
310
324
  */
311
325
  private validateAndCacheView;
312
326
  /**
313
- * Convenience dispose method for cleanup an alias for {@link stop}.
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,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAGjD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAgFhD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmFG;AACH,qBAAa,WAAW,CAAC,QAAQ,SA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