@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.
- package/README.md +114 -114
- package/dist/define-player.d.ts +16 -16
- package/dist/define-player.js +16 -16
- package/dist/errors.d.ts +84 -101
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +108 -108
- package/dist/errors.js.map +1 -1
- package/dist/guards/compose.d.ts +70 -77
- package/dist/guards/compose.d.ts.map +1 -1
- package/dist/guards/compose.js +90 -113
- package/dist/guards/compose.js.map +1 -1
- package/dist/guards/helpers.d.ts +22 -18
- package/dist/guards/helpers.d.ts.map +1 -1
- package/dist/guards/helpers.js +23 -19
- package/dist/guards/helpers.js.map +1 -1
- package/dist/guards/index.d.ts +10 -3
- package/dist/guards/index.d.ts.map +1 -1
- package/dist/guards/index.js +10 -3
- package/dist/guards/index.js.map +1 -1
- package/dist/guards/types.d.ts +9 -9
- package/dist/guards/types.d.ts.map +1 -1
- package/dist/index.d.ts +8 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -10
- package/dist/index.js.map +1 -1
- package/dist/player-actor.d.ts +197 -113
- package/dist/player-actor.d.ts.map +1 -1
- package/dist/player-actor.js +413 -401
- package/dist/player-actor.js.map +1 -1
- package/dist/routing/build-url.d.ts +19 -21
- package/dist/routing/build-url.d.ts.map +1 -1
- package/dist/routing/build-url.js +70 -71
- package/dist/routing/build-url.js.map +1 -1
- package/dist/routing/derive-current-route.d.ts +51 -13
- package/dist/routing/derive-current-route.d.ts.map +1 -1
- package/dist/routing/derive-current-route.js +69 -60
- package/dist/routing/derive-current-route.js.map +1 -1
- package/dist/routing/derive-initial-route.d.ts +23 -23
- package/dist/routing/derive-initial-route.js +27 -27
- 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 -71
- package/dist/routing/format-play-route-transitions.d.ts.map +1 -1
- package/dist/routing/format-play-route-transitions.js +74 -130
- package/dist/routing/format-play-route-transitions.js.map +1 -1
- package/dist/routing/index.d.ts +4 -8
- package/dist/routing/index.d.ts.map +1 -1
- package/dist/routing/index.js +4 -6
- package/dist/routing/index.js.map +1 -1
- package/dist/routing/types.d.ts +12 -11
- package/dist/routing/types.d.ts.map +1 -1
- package/dist/types.d.ts +97 -20
- package/dist/types.d.ts.map +1 -1
- package/dist/view/derive-current-view.d.ts +51 -0
- package/dist/view/derive-current-view.d.ts.map +1 -0
- package/dist/view/derive-current-view.js +119 -0
- package/dist/view/derive-current-view.js.map +1 -0
- package/package.json +22 -21
- package/dist/define-player.typecheck.d.ts +0 -2
- package/dist/define-player.typecheck.d.ts.map +0 -1
- package/dist/define-player.typecheck.js +0 -48
- package/dist/define-player.typecheck.js.map +0 -1
- package/dist/guards/compose.typecheck.d.ts +0 -2
- package/dist/guards/compose.typecheck.d.ts.map +0 -1
- package/dist/guards/compose.typecheck.js +0 -22
- package/dist/guards/compose.typecheck.js.map +0 -1
- package/dist/player-actor.typecheck.d.ts +0 -2
- package/dist/player-actor.typecheck.d.ts.map +0 -1
- package/dist/player-actor.typecheck.js +0 -30
- package/dist/player-actor.typecheck.js.map +0 -1
- package/dist/routing/create-routed-machine.d.ts +0 -71
- package/dist/routing/create-routed-machine.d.ts.map +0 -1
- package/dist/routing/create-routed-machine.js +0 -71
- package/dist/routing/create-routed-machine.js.map +0 -1
- package/dist/routing/play-route-event.typecheck.d.ts +0 -2
- package/dist/routing/play-route-event.typecheck.d.ts.map +0 -1
- package/dist/routing/play-route-event.typecheck.js +0 -43
- package/dist/routing/play-route-event.typecheck.js.map +0 -1
- package/dist/routing/schemas.d.ts +0 -99
- package/dist/routing/schemas.d.ts.map +0 -1
- package/dist/routing/schemas.js +0 -30
- package/dist/routing/schemas.js.map +0 -1
- package/dist/schemas.d.ts +0 -28
- package/dist/schemas.d.ts.map +0 -1
- package/dist/schemas.js +0 -29
- package/dist/schemas.js.map +0 -1
package/dist/player-actor.d.ts
CHANGED
|
@@ -1,28 +1,33 @@
|
|
|
1
|
-
import {
|
|
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
|
-
*
|
|
6
|
+
* The concrete XState actor. It implements the signal protocol of the Play Architecture
|
|
7
7
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
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:**
|
|
14
|
-
* {@link @xmachines/play-actor!
|
|
15
|
-
*
|
|
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
|
|
18
|
-
* XState machine
|
|
19
|
-
* the actor
|
|
20
|
-
*
|
|
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
|
|
27
|
+
* @typeParam TMachine - The type of the XState v5 state machine
|
|
23
28
|
*
|
|
24
29
|
* @example
|
|
25
|
-
*
|
|
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: {
|
|
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());
|
|
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
|
-
*
|
|
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
|
-
* //
|
|
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
|
|
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
|
-
* **
|
|
73
|
-
*
|
|
74
|
-
* `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.
|
|
75
88
|
*
|
|
76
|
-
* **
|
|
77
|
-
* `Signal.
|
|
78
|
-
*
|
|
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
|
|
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
|
-
*
|
|
97
|
+
* Tells you if this constructor returned already.
|
|
89
98
|
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
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
|
|
101
|
-
* 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.
|
|
102
164
|
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
* context
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
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
|
-
* //
|
|
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
|
|
120
|
-
* 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.
|
|
121
183
|
*
|
|
122
|
-
*
|
|
123
|
-
* (
|
|
124
|
-
* 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).
|
|
125
188
|
*
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
* `meta.route` templates are fixed at
|
|
129
|
-
* substitution uses the
|
|
130
|
-
*
|
|
131
|
-
* 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.
|
|
132
196
|
*/
|
|
133
197
|
readonly initialRoute: string | null;
|
|
134
198
|
/**
|
|
135
|
-
*
|
|
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
|
-
*
|
|
139
|
-
*
|
|
140
|
-
*
|
|
141
|
-
*
|
|
142
|
-
*
|
|
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
|
|
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
|
-
*
|
|
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); //
|
|
155
|
-
* 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
|
|
156
228
|
* }
|
|
157
229
|
* ```
|
|
158
230
|
*/
|
|
159
|
-
currentView: Signal.State<PlaySpec | null>;
|
|
160
|
-
constructor(machine: TMachine, options: PlayerOptions<TMachine>, input?: InputFrom<TMachine>, restoredSnapshot?:
|
|
231
|
+
readonly currentView: Signal.State<PlaySpec | null>;
|
|
232
|
+
constructor(machine: TMachine, options: PlayerOptions<TMachine>, input?: InputFrom<TMachine>, restoredSnapshot?: ActorOptions<TMachine>["snapshot"]);
|
|
161
233
|
/**
|
|
162
|
-
*
|
|
234
|
+
* Starts the actor.
|
|
163
235
|
*
|
|
164
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
255
|
+
* Sends an event to this actor.
|
|
173
256
|
*
|
|
174
|
-
* The
|
|
175
|
-
*
|
|
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
|
|
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
|
|
180
|
-
* 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`.
|
|
181
266
|
*
|
|
182
267
|
* @example
|
|
183
268
|
* ```typescript
|
|
184
|
-
* //
|
|
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
|
-
* //
|
|
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
|
-
*
|
|
278
|
+
* Returns the current snapshot
|
|
194
279
|
*/
|
|
195
280
|
getSnapshot(): ReturnType<Actor<TMachine>["getSnapshot"]>;
|
|
196
281
|
/**
|
|
197
|
-
*
|
|
282
|
+
* Subscribes to the snapshot updates of this actor.
|
|
198
283
|
*
|
|
199
|
-
*
|
|
284
|
+
* The method accepts an observer object, exactly like `Actor.subscribe` of XState.
|
|
200
285
|
*
|
|
201
|
-
* @param observer -
|
|
202
|
-
* @returns
|
|
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
|
-
*
|
|
291
|
+
* Subscribes to the snapshot updates of this actor.
|
|
207
292
|
*
|
|
208
|
-
*
|
|
293
|
+
* The method accepts listener functions, exactly like `Actor.subscribe` of XState.
|
|
209
294
|
*
|
|
210
|
-
* @param nextListener -
|
|
211
|
-
* @param errorListener -
|
|
212
|
-
* @param completeListener -
|
|
213
|
-
* @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.
|
|
214
299
|
*/
|
|
215
300
|
subscribe(nextListener?: (snapshot: SnapshotFrom<TMachine>) => void, errorListener?: (error: unknown) => void, completeListener?: () => void): Subscription;
|
|
216
301
|
/**
|
|
217
|
-
*
|
|
302
|
+
* Listens for the events that this actor emits with the `emit` action.
|
|
218
303
|
*
|
|
219
|
-
* @param type -
|
|
220
|
-
* @param handler -
|
|
221
|
-
* @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.
|
|
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
|
-
*
|
|
312
|
+
* Returns the persisted snapshot of this actor.
|
|
228
313
|
*
|
|
229
|
-
*
|
|
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
|
-
*
|
|
235
|
-
*
|
|
236
|
-
*
|
|
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 -
|
|
323
|
+
* @param snapshot - The current XState snapshot
|
|
240
324
|
*/
|
|
241
325
|
private validateAndCacheView;
|
|
242
326
|
/**
|
|
243
|
-
*
|
|
327
|
+
* The dispose method, for the cleanup. It is the alias of {@link stop}.
|
|
244
328
|
*
|
|
245
|
-
*
|
|
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,
|
|
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;AAuFhD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwFG;AACH,qBAAa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