@xmachines/play-xstate 2.0.0-alpha.1 → 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 (89) hide show
  1. package/README.md +114 -114
  2. package/dist/define-player.d.ts +16 -16
  3. package/dist/define-player.js +16 -16
  4. package/dist/errors.d.ts +84 -101
  5. package/dist/errors.d.ts.map +1 -1
  6. package/dist/errors.js +108 -108
  7. package/dist/errors.js.map +1 -1
  8. package/dist/guards/compose.d.ts +70 -77
  9. package/dist/guards/compose.d.ts.map +1 -1
  10. package/dist/guards/compose.js +90 -113
  11. package/dist/guards/compose.js.map +1 -1
  12. package/dist/guards/helpers.d.ts +22 -18
  13. package/dist/guards/helpers.d.ts.map +1 -1
  14. package/dist/guards/helpers.js +23 -19
  15. package/dist/guards/helpers.js.map +1 -1
  16. package/dist/guards/index.d.ts +10 -3
  17. package/dist/guards/index.d.ts.map +1 -1
  18. package/dist/guards/index.js +10 -3
  19. package/dist/guards/index.js.map +1 -1
  20. package/dist/guards/types.d.ts +9 -9
  21. package/dist/guards/types.d.ts.map +1 -1
  22. package/dist/index.d.ts +8 -8
  23. package/dist/index.d.ts.map +1 -1
  24. package/dist/index.js +9 -10
  25. package/dist/index.js.map +1 -1
  26. package/dist/player-actor.d.ts +197 -113
  27. package/dist/player-actor.d.ts.map +1 -1
  28. package/dist/player-actor.js +413 -401
  29. package/dist/player-actor.js.map +1 -1
  30. package/dist/routing/build-url.d.ts +19 -21
  31. package/dist/routing/build-url.d.ts.map +1 -1
  32. package/dist/routing/build-url.js +70 -71
  33. package/dist/routing/build-url.js.map +1 -1
  34. package/dist/routing/derive-current-route.d.ts +51 -13
  35. package/dist/routing/derive-current-route.d.ts.map +1 -1
  36. package/dist/routing/derive-current-route.js +69 -60
  37. package/dist/routing/derive-current-route.js.map +1 -1
  38. package/dist/routing/derive-initial-route.d.ts +23 -23
  39. package/dist/routing/derive-initial-route.js +27 -27
  40. package/dist/routing/derive-initial-route.js.map +1 -1
  41. package/dist/routing/derive-route.d.ts +38 -37
  42. package/dist/routing/derive-route.d.ts.map +1 -1
  43. package/dist/routing/derive-route.js +45 -42
  44. package/dist/routing/derive-route.js.map +1 -1
  45. package/dist/routing/format-play-route-transitions.d.ts +34 -71
  46. package/dist/routing/format-play-route-transitions.d.ts.map +1 -1
  47. package/dist/routing/format-play-route-transitions.js +74 -130
  48. package/dist/routing/format-play-route-transitions.js.map +1 -1
  49. package/dist/routing/index.d.ts +4 -8
  50. package/dist/routing/index.d.ts.map +1 -1
  51. package/dist/routing/index.js +4 -6
  52. package/dist/routing/index.js.map +1 -1
  53. package/dist/routing/types.d.ts +12 -11
  54. package/dist/routing/types.d.ts.map +1 -1
  55. package/dist/types.d.ts +97 -20
  56. package/dist/types.d.ts.map +1 -1
  57. package/dist/view/derive-current-view.d.ts +51 -0
  58. package/dist/view/derive-current-view.d.ts.map +1 -0
  59. package/dist/view/derive-current-view.js +119 -0
  60. package/dist/view/derive-current-view.js.map +1 -0
  61. package/package.json +22 -21
  62. package/dist/define-player.typecheck.d.ts +0 -2
  63. package/dist/define-player.typecheck.d.ts.map +0 -1
  64. package/dist/define-player.typecheck.js +0 -48
  65. package/dist/define-player.typecheck.js.map +0 -1
  66. package/dist/guards/compose.typecheck.d.ts +0 -2
  67. package/dist/guards/compose.typecheck.d.ts.map +0 -1
  68. package/dist/guards/compose.typecheck.js +0 -22
  69. package/dist/guards/compose.typecheck.js.map +0 -1
  70. package/dist/player-actor.typecheck.d.ts +0 -2
  71. package/dist/player-actor.typecheck.d.ts.map +0 -1
  72. package/dist/player-actor.typecheck.js +0 -30
  73. package/dist/player-actor.typecheck.js.map +0 -1
  74. package/dist/routing/create-routed-machine.d.ts +0 -71
  75. package/dist/routing/create-routed-machine.d.ts.map +0 -1
  76. package/dist/routing/create-routed-machine.js +0 -71
  77. package/dist/routing/create-routed-machine.js.map +0 -1
  78. package/dist/routing/play-route-event.typecheck.d.ts +0 -2
  79. package/dist/routing/play-route-event.typecheck.d.ts.map +0 -1
  80. package/dist/routing/play-route-event.typecheck.js +0 -43
  81. package/dist/routing/play-route-event.typecheck.js.map +0 -1
  82. package/dist/routing/schemas.d.ts +0 -99
  83. package/dist/routing/schemas.d.ts.map +0 -1
  84. package/dist/routing/schemas.js +0 -30
  85. package/dist/routing/schemas.js.map +0 -1
  86. package/dist/schemas.d.ts +0 -28
  87. package/dist/schemas.d.ts.map +0 -1
  88. package/dist/schemas.js +0 -29
  89. package/dist/schemas.js.map +0 -1
@@ -1,28 +1,33 @@
1
- import { type AnyStateMachine, type Actor, type AnyActorLogic, type EmittedFrom, type InputFrom, type Observer, type Snapshot, type SnapshotFrom, type Subscription, type EventFromLogic } from "xstate";
1
+ import { Actor, type AnyStateMachine, type AnyActorLogic, type EmittedFrom, type InputFrom, type ActorOptions, type Observer, type Snapshot, type SnapshotFrom, type Subscription, type EventFromLogic } from "xstate";
2
2
  import { AbstractActor, type Routable, type Viewable, type PlaySpec } from "@xmachines/play-actor";
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} to provide XState v6 integration
9
- * while maintaining ecosystem compatibility (XState inspection, devtools). This actor
10
- * wraps an internal XState actor and exposes TC39 Signal-based reactive state for
11
- * Infrastructure observation.
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.
12
15
  *
13
- * **Capabilities:** Implements both {@link @xmachines/play-actor!Routable} and
14
- * {@link @xmachines/play-actor!Viewable} interfaces, providing routing and view
15
- * 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.
16
20
  *
17
- * **Architectural Context:** Implements **Actor Authority (INV-01)** by ensuring the
18
- * XState machine's guards control all navigation decisions. Infrastructure observes
19
- * the actor's signals (`state`, `currentRoute`, `currentView`) but cannot directly
20
- * 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.
21
26
  *
22
- * @typeParam TMachine - XState v6 state machine type
27
+ * @typeParam TMachine - The type of the XState v5 state machine
23
28
  *
24
29
  * @example
25
- * Basic actor creation and lifecycle
30
+ * The creation of an actor, and its lifecycle
26
31
  * ```typescript
27
32
  * import { setup } from "xstate";
28
33
  * import { definePlayer } from "@xmachines/play-xstate";
@@ -31,7 +36,14 @@ import type { PlayerOptions } from "./types.js";
31
36
  * initial: 'idle',
32
37
  * states: {
33
38
  * idle: {
34
- * meta: { route: '/', view: { component: 'HomePage' } }
39
+ * meta: {
40
+ * route: '/',
41
+ * // A view spec needs `root` and `elements`. Every other shape derives null.
42
+ * view: {
43
+ * root: 'home',
44
+ * elements: { home: { type: 'HomePage', props: {}, children: [] } },
45
+ * },
46
+ * },
35
47
  * }
36
48
  * }
37
49
  * });
@@ -40,13 +52,13 @@ import type { PlayerOptions } from "./types.js";
40
52
  * const actor = createPlayer();
41
53
  * actor.start();
42
54
  *
43
- * // Observe signals
44
- * console.log(actor.currentRoute.get()); // '/'
45
- * console.log(actor.currentView.get()); // { component: 'HomePage' }
55
+ * // Observe the signals
56
+ * console.log(actor.currentRoute.get()); // '/'
57
+ * console.log(actor.currentView.get()?.root); // 'home'
46
58
  * ```
47
59
  *
48
60
  * @example
49
- * Signal lifecycle with watchers
61
+ * The signal lifecycle with a watcher
50
62
  * ```typescript
51
63
  * import { Signal } from "@xmachines/play-signals";
52
64
  *
@@ -59,36 +71,86 @@ import type { PlayerOptions } from "./types.js";
59
71
  *
60
72
  * watcher.watch(actor.state);
61
73
  * actor.send({ type: 'play.route', to: '#about' });
62
- * // Watcher notification scheduled via microtask by the watcher itself
74
+ * // The watcher schedules its own notification in a microtask
63
75
  * ```
64
76
  *
65
77
  * @see [Play RFC](../../docs/rfc/play.md)
66
- * @see {@link definePlayer} for factory creation
67
- * @see {@link @xmachines/play-actor!AbstractActor} for signal protocol
68
- * @see {@link @xmachines/play-actor!Routable} for routing capability
69
- * @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
70
82
  *
71
83
  * @remarks
72
- * **Routing:** This actor supports both XState's `route: {}` config pattern
73
- * and `play.route` events with parameters. The `deriveRoute()` function checks
74
- * `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.
75
88
  *
76
- * **View Signal Pattern:** The `currentView` signal is a direct `Signal.State` (not
77
- * `Signal.Computed`) to ensure proper watcher propagation in PlayRenderer. Views are
78
- * 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.
79
93
  */
80
94
  export declare class PlayerActor<TMachine extends AnyStateMachine> extends AbstractActor<AnyActorLogic, EventFromLogic<TMachine>> implements Routable, Viewable {
81
- private xstateActor;
82
- private playerOptions;
83
- private viewSignal;
84
- /** Last spec emitted on the view signal — used to skip no-change re-emissions. */
85
- private lastEmittedView;
86
- state: Signal.State<SnapshotFrom<TMachine>>;
95
+ private playerOptions?;
87
96
  /**
88
- * Returns whether the actor's current state can accept the given event.
97
+ * Tells you if this constructor returned already.
89
98
  *
90
- * Typed to the machine's event union — passing an unknown event type is a
91
- * compile error. Delegates to the underlying XState actor's snapshot.
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.
104
+ */
105
+ private constructed?;
106
+ /**
107
+ * The live options object of the caller, or an empty object during the construction.
108
+ *
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.
115
+ *
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.
121
+ */
122
+ private get hooks();
123
+ /**
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.
128
+ */
129
+ private lifecycle?;
130
+ /**
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.
137
+ */
138
+ private nextOnlySubscriptions?;
139
+ /**
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.
146
+ */
147
+ private lastViewSnapshot;
148
+ state: Signal.State<ReturnType<TMachine["transition"]>>;
149
+ /**
150
+ * Tells you if the current state of the actor accepts the given event.
151
+ *
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.
92
154
  *
93
155
  * @example
94
156
  * ```typescript
@@ -97,152 +159,174 @@ export declare class PlayerActor<TMachine extends AnyStateMachine> extends Abstr
97
159
  */
98
160
  can(event: EventFromLogic<TMachine>): boolean;
99
161
  /**
100
- * A TC39 `Signal.Computed` that derives the current URL path from the active
101
- * 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.
102
164
  *
103
- * Returns `null` when the current state has no `meta.route`, or when the route
104
- * template cannot be fully resolved (e.g. a required parameter is absent from
105
- * context).
106
- *
107
- * @throws {MissingRouteParamError} When a required `:param` placeholder in the
108
- * route template has no matching value in the actor's context. Import the class
109
- * from `@xmachines/play-xstate/errors`.
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
170
+ * snapshot.
110
171
  *
111
172
  * @example
112
173
  * ```typescript
113
- * // Returns "/profile/alice" when context.userId === "alice"
174
+ * // It returns "/profile/alice" when context.params.userId === "alice",
175
+ * // and null while the param is still absent.
114
176
  * const route = actor.currentRoute.get();
115
177
  * ```
116
178
  */
117
179
  currentRoute: Signal.Computed<string | null>;
118
180
  /**
119
- * The route derived from the machine's initial state — fixed at construction,
120
- * 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.
121
183
  *
122
- * Router bridges compare this against the browser URL to distinguish a deep-link
123
- * (non-initial URL → router wins) from a restore (initial URL + actor at a
124
- * 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).
125
188
  *
126
- * Derived statically from the machine definition via `deriveInitialRoute`
127
- * (XState's pure `initialTransition` helper): the initial state chain and its
128
- * `meta.route` templates are fixed at machine definition time, while `:param`
129
- * substitution uses the machine's real initial context for this actor's `input`.
130
- * No extra actor is ever created, and a restored snapshot never influences the
131
- * 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.
132
196
  */
133
197
  readonly initialRoute: string | null;
134
198
  /**
135
- * Reactive signal containing the current view spec derived from the active state's
136
- * `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.
201
+ *
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.
137
208
  *
138
- * Emits a **fresh object reference** whenever the rendered view actually changes —
139
- * a different state's view, or a param/context change that alters the resolved
140
- * spec (including `reenter: true` re-entries with new params). Snapshots that do
141
- * not change the rendered view (e.g. context-only assigns) keep the previous
142
- * reference so downstream providers do not remount the UI on every event.
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.
143
214
  *
144
- * The emitted `PlaySpec` has its element `props` enriched with `context.params`
145
- * before emission — URL path parameters (e.g. `:section?`) flow into component props
146
- * automatically. See `mergeRouteParamsIntoProps` for the merge priority rules.
215
+ * The signal returns `null` when the current state has no `meta.view` metadata.
147
216
  *
148
- * Returns `null` when the current state has no `meta.view` metadata.
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.
149
221
  *
150
222
  * @example
151
223
  * ```typescript
152
224
  * const view = actor.currentView.get();
153
225
  * if (view) {
154
- * console.log(view.root); // e.g. "root"
155
- * 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
156
228
  * }
157
229
  * ```
158
230
  */
159
- currentView: Signal.State<PlaySpec | null>;
160
- constructor(machine: TMachine, options: PlayerOptions<TMachine>, input?: InputFrom<TMachine>, restoredSnapshot?: SnapshotFrom<TMachine>);
231
+ readonly currentView: Signal.State<PlaySpec | null>;
232
+ constructor(machine: TMachine, options: PlayerOptions<TMachine>, input?: InputFrom<TMachine>, restoredSnapshot?: ActorOptions<TMachine>["snapshot"]);
161
233
  /**
162
- * Start the actor
234
+ * Starts the actor.
163
235
  *
164
- * Per RESEARCH.md Pitfall 1: Always call start() after creation
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.
165
241
  */
166
242
  start(): this;
167
243
  /**
168
- * Stop the actor and cleanup
244
+ * Stops the actor and cleans up.
245
+ *
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.
169
252
  */
170
253
  stop(): this;
171
254
  /**
172
- * Send an event to the underlying XState actor.
255
+ * Sends an event to this actor.
173
256
  *
174
- * The actor's state machine guards decide whether the event causes a transition.
175
- * 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.
176
260
  *
177
- * @param event - An event from the machine's `EventFromLogic<TMachine>` union.
261
+ * @param event - An event of the `EventFromLogic<TMachine>` union of the machine.
178
262
  *
179
- * @throws {InvalidEventError} When `event` is not a plain object (`null`, `undefined`,
180
- * 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`.
181
266
  *
182
267
  * @example
183
268
  * ```typescript
184
- * // Domain event (typed to machine's event union)
269
+ * // A domain event, with the type of the event union of the machine
185
270
  * actor.send({ type: "auth.login", userId: "123" });
186
271
  *
187
- * // Routing event
272
+ * // A routing event
188
273
  * actor.send({ type: "play.route", to: "#home" });
189
274
  * ```
190
275
  */
191
276
  send(event: EventFromLogic<TMachine>): void;
192
277
  /**
193
- * Get current snapshot
278
+ * Returns the current snapshot
194
279
  */
195
280
  getSnapshot(): ReturnType<Actor<TMachine>["getSnapshot"]>;
196
281
  /**
197
- * Subscribe to snapshot updates from the wrapped XState actor.
282
+ * Subscribes to the snapshot updates of this actor.
198
283
  *
199
- * Accepts an observer object, exactly like XState's `Actor.subscribe`.
284
+ * The method accepts an observer object, exactly like `Actor.subscribe` of XState.
200
285
  *
201
- * @param observer - Observer with `next`/`error`/`complete` handlers.
202
- * @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.
203
288
  */
204
289
  subscribe(observer: Observer<SnapshotFrom<TMachine>>): Subscription;
205
290
  /**
206
- * Subscribe to snapshot updates from the wrapped XState actor.
291
+ * Subscribes to the snapshot updates of this actor.
207
292
  *
208
- * Accepts listener functions, exactly like XState's `Actor.subscribe`.
293
+ * The method accepts listener functions, exactly like `Actor.subscribe` of XState.
209
294
  *
210
- * @param nextListener - Snapshot listener function.
211
- * @param errorListener - Called when the actor errors.
212
- * @param completeListener - Called when the actor completes (reaches a final state).
213
- * @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.
214
299
  */
215
300
  subscribe(nextListener?: (snapshot: SnapshotFrom<TMachine>) => void, errorListener?: (error: unknown) => void, completeListener?: () => void): Subscription;
216
301
  /**
217
- * Listen for events emitted by the wrapped XState actor via the `emit` action.
302
+ * Listens for the events that this actor emits with the `emit` action.
218
303
  *
219
- * @param type - Emitted event type to listen for, or `"*"` for all.
220
- * @param handler - Called with each matching emitted event.
221
- * @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.
222
307
  */
223
308
  on<TType extends EmittedFrom<TMachine>["type"] | "*">(type: TType, handler: (emitted: EmittedFrom<TMachine> & (TType extends "*" ? unknown : {
224
309
  type: TType;
225
310
  })) => void): Subscription;
226
311
  /**
227
- * Get the persisted snapshot of the wrapped XState actor.
312
+ * Returns the persisted snapshot of this actor.
228
313
  *
229
- * Suitable for serialization and later restoration via the factory's
230
- * `restore.snapshot` option.
314
+ * Use it to serialize the state, and to restore it later with the
315
+ * `restore.snapshot` option of the factory.
231
316
  */
232
- getPersistedSnapshot(): Snapshot<unknown>;
317
+ getPersistedSnapshot(options?: unknown): Snapshot<unknown>;
233
318
  /**
234
- * Validate view at state entry and cache result
235
- *
236
- * Per CONTEXT.md: "Prop validation: At state entry (when state becomes active)"
237
- * Validates once per transition and stores result in signal.
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.
238
322
  *
239
- * @param snapshot - Current XState snapshot
323
+ * @param snapshot - The current XState snapshot
240
324
  */
241
325
  private validateAndCacheView;
242
326
  /**
243
- * Convenience dispose method for cleanup
327
+ * The dispose method, for the cleanup. It is the alias of {@link stop}.
244
328
  *
245
- * Per CONTEXT.md: "Both .dispose() convenience method and manual machine.stop()"
329
+ * @deprecated Use {@link stop}. Will be removed in the next major.
246
330
  */
247
331
  dispose(): void;
248
332
  }
@@ -1 +1 @@
1
- {"version":3,"file":"player-actor.d.ts","sourceRoot":"","sources":["../src/player-actor.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,KAAK,eAAe,EACpB,KAAK,KAAK,EACV,KAAK,aAAa,EAElB,KAAK,WAAW,EAChB,KAAK,SAAS,EAEd,KAAK,QAAQ,EACb,KAAK,QAAQ,EACb,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,MAAM,QAAQ,CAAC;AAChB,OAAO,EAAE,aAAa,EAAE,KAAK,QAAQ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