@xmachines/play-dom 1.0.0-beta.32 → 1.0.0-beta.34
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 +286 -34
- package/dist/PlayRenderer.d.ts +46 -17
- package/dist/PlayRenderer.d.ts.map +1 -1
- package/dist/PlayRenderer.js +113 -24
- package/dist/PlayRenderer.js.map +1 -1
- package/dist/connect-renderer.d.ts +37 -18
- package/dist/connect-renderer.d.ts.map +1 -1
- package/dist/connect-renderer.js +54 -32
- package/dist/connect-renderer.js.map +1 -1
- package/dist/create-play-ui.d.ts +56 -0
- package/dist/create-play-ui.d.ts.map +1 -0
- package/dist/create-play-ui.js +74 -0
- package/dist/create-play-ui.js.map +1 -0
- package/dist/create-renderer.d.ts +80 -0
- package/dist/create-renderer.d.ts.map +1 -0
- package/dist/create-renderer.js +87 -0
- package/dist/create-renderer.js.map +1 -0
- package/dist/index.d.ts +11 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -2
- package/dist/index.js.map +1 -1
- package/dist/json-render/index.d.ts +4 -3
- package/dist/json-render/index.d.ts.map +1 -1
- package/dist/json-render/index.js +2 -2
- package/dist/json-render/renderer.d.ts +43 -9
- package/dist/json-render/renderer.d.ts.map +1 -1
- package/dist/json-render/renderer.js +273 -18
- package/dist/json-render/renderer.js.map +1 -1
- package/dist/json-render/types.d.ts +172 -27
- package/dist/json-render/types.d.ts.map +1 -1
- package/dist/json-render/types.js +30 -5
- package/dist/json-render/types.js.map +1 -1
- package/dist/types.d.ts +133 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/{xm-types.js → types.js} +2 -2
- package/dist/types.js.map +1 -0
- package/package.json +6 -6
- package/dist/xm-types.d.ts +0 -55
- package/dist/xm-types.d.ts.map +0 -1
- package/dist/xm-types.js.map +0 -1
package/README.md
CHANGED
|
@@ -2,73 +2,325 @@
|
|
|
2
2
|
|
|
3
3
|
**Vanilla DOM renderer for XMachines**
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Framework-free view rendering driven by an XState v5 actor's `currentView` TC39 Signal. Implements the same catalog-typed `defineRegistry` / `ComponentFn` / `ActionFn` API surface as `@json-render/react`, `/solid`, `/vue`, and `/svelte`.
|
|
6
6
|
|
|
7
7
|
## Installation
|
|
8
8
|
|
|
9
9
|
```bash
|
|
10
|
-
npm install @xmachines/play-dom
|
|
10
|
+
npm install @xmachines/play-dom @json-render/core zod
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
## Key Exports
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
15
|
+
| Export | Description |
|
|
16
|
+
| --------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------- |
|
|
17
|
+
| `createPlayUI(registryResult, options?)` | Batteries-included factory: returns `mount(actor, container) → disconnect` — parallel to `PlayUIProvider` in framework packages |
|
|
18
|
+
| `createRenderer(catalog, componentMap)` | One-call factory: returns `mount(actor, container, options?) → disconnect` |
|
|
19
|
+
| `connectRenderer(options)` | Functional API: connect actor → DOM with full options |
|
|
20
|
+
| `defineRegistry(catalog, { components, actions })` | Build a catalog-typed `DomRegistry` with typed action handlers |
|
|
21
|
+
| `UIProviderOptions` | Standard options interface: `validationFunctions`, `navigate`, `functions`, `onRenderError`, `fallback` |
|
|
22
|
+
| `PlayRenderer` | Class-based renderer — `connect()` / `disconnect()` lifecycle |
|
|
23
|
+
| `schema` | DOM schema for `defineCatalog` (mirrors `@json-render/react/schema`) |
|
|
24
|
+
| `ComponentFn<C, K>` | Catalog-typed DOM component function type |
|
|
25
|
+
| `ComponentContext<C, K>` | Context passed to each `ComponentFn` — `props`, `on`, `emit`, `children`, `bindings`, `ctx` |
|
|
26
|
+
| `ActionFn<C, K>` | `(params, setState, state) => Promise<void>` — catalog-typed action handler |
|
|
27
|
+
| `SetState` | `(updater: prev => next) => void` — write to the local state store |
|
|
28
|
+
| `BaseComponentProps<P>` | Base type for catalog component prop definitions |
|
|
29
|
+
| `CatalogHasActions<C>` | Conditional type: `true` when catalog declares actions |
|
|
30
|
+
| `renderSpec(spec, store, registry, send, handlers)` | Pure Spec → DOM renderer (advanced use) |
|
|
22
31
|
|
|
23
|
-
##
|
|
32
|
+
## Quick Start — `createPlayUI`
|
|
24
33
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
34
|
+
The standard entry point — mirrors `PlayUIProvider` in framework packages. Pass a `registryResult` (from `defineRegistry`) plus optional `UIProviderOptions`, and get back a `mount` function:
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
import { defineRegistry, createPlayUI, schema } from "@xmachines/play-dom";
|
|
28
38
|
import { defineCatalog } from "@json-render/core";
|
|
29
|
-
import {
|
|
39
|
+
import { z } from "zod";
|
|
30
40
|
import type { ComponentFn } from "@xmachines/play-dom";
|
|
31
41
|
|
|
32
|
-
// 1.
|
|
33
|
-
const
|
|
34
|
-
|
|
42
|
+
// 1. Define catalog
|
|
43
|
+
const catalog = defineCatalog(schema, {
|
|
44
|
+
components: {
|
|
45
|
+
Home: { props: z.object({ title: z.string() }) },
|
|
46
|
+
Login: { props: z.object({ title: z.string(), username: z.string().optional() }) },
|
|
47
|
+
},
|
|
48
|
+
actions: {
|
|
49
|
+
login: { params: z.object({ username: z.string() }) },
|
|
50
|
+
logout: {},
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
// 2. Build registry with typed action handlers
|
|
55
|
+
const registryResult = defineRegistry(catalog, {
|
|
56
|
+
components: {
|
|
57
|
+
Home: ({ props }) => {
|
|
58
|
+
const el = document.createElement("section");
|
|
59
|
+
el.textContent = props.title;
|
|
60
|
+
return el;
|
|
61
|
+
},
|
|
62
|
+
Login: ({ props, on }) => {
|
|
63
|
+
const section = document.createElement("section");
|
|
64
|
+
const button = document.createElement("button");
|
|
65
|
+
button.textContent = "Log In";
|
|
66
|
+
const submit = on("submit");
|
|
67
|
+
button.addEventListener("click", () => submit.emit());
|
|
68
|
+
section.append(button);
|
|
69
|
+
return section;
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
actions: {
|
|
73
|
+
login: async (params) => {
|
|
74
|
+
if (!params) return;
|
|
75
|
+
actor.send({ type: "auth.login", username: params.username });
|
|
76
|
+
},
|
|
77
|
+
logout: async () => actor.send({ type: "auth.logout" }),
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
// 3. Create the UI factory (once, at module level)
|
|
82
|
+
const ui = createPlayUI(registryResult, {
|
|
83
|
+
onRenderError: (error, elementType) => console.warn(`<${elementType}> crashed:`, error),
|
|
84
|
+
fallback: (() => {
|
|
85
|
+
const el = document.createElement("p");
|
|
86
|
+
el.textContent = "Loading…";
|
|
87
|
+
return el;
|
|
88
|
+
})(),
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
// 4. Mount when actor and container are ready
|
|
92
|
+
const actor = createPlayer()();
|
|
93
|
+
actor.start();
|
|
94
|
+
|
|
95
|
+
const disconnect = ui.mount(actor, document.getElementById("app")!);
|
|
96
|
+
|
|
97
|
+
// Cleanup:
|
|
98
|
+
disconnect();
|
|
99
|
+
```
|
|
35
100
|
|
|
36
|
-
|
|
37
|
-
|
|
101
|
+
## Quick Start — `createRenderer`
|
|
102
|
+
|
|
103
|
+
The lower-level one-call pattern — takes a catalog and component map directly:
|
|
104
|
+
|
|
105
|
+
```typescript
|
|
106
|
+
import { createRenderer, schema } from "@xmachines/play-dom";
|
|
107
|
+
import { defineCatalog } from "@json-render/core";
|
|
108
|
+
import { z } from "zod";
|
|
109
|
+
import type { ComponentFn } from "@xmachines/play-dom";
|
|
110
|
+
|
|
111
|
+
// 1. Define catalog
|
|
112
|
+
const catalog = defineCatalog(schema, {
|
|
113
|
+
components: {
|
|
114
|
+
Home: { props: z.object({ title: z.string() }) },
|
|
115
|
+
Login: { props: z.object({ title: z.string(), username: z.string().optional() }) },
|
|
116
|
+
},
|
|
117
|
+
actions: {
|
|
118
|
+
login: { params: z.object({ username: z.string() }) },
|
|
119
|
+
logout: {},
|
|
120
|
+
},
|
|
121
|
+
});
|
|
122
|
+
type AppCatalog = typeof catalog;
|
|
123
|
+
|
|
124
|
+
// 2. Implement components
|
|
125
|
+
const Home: ComponentFn<AppCatalog, "Home"> = ({ props }) => {
|
|
38
126
|
const el = document.createElement("section");
|
|
39
127
|
el.textContent = props.title;
|
|
40
128
|
return el;
|
|
41
129
|
};
|
|
42
130
|
|
|
43
|
-
|
|
44
|
-
const
|
|
45
|
-
|
|
131
|
+
const Login: ComponentFn<AppCatalog, "Login"> = ({ props, on }) => {
|
|
132
|
+
const section = document.createElement("section");
|
|
133
|
+
const input = document.createElement("input");
|
|
134
|
+
input.value = props.username ?? "";
|
|
135
|
+
input.addEventListener("input", () => ctx.store.update((s) => ({ ...s, username: input.value })));
|
|
136
|
+
|
|
137
|
+
const button = document.createElement("button");
|
|
138
|
+
button.textContent = "Log In";
|
|
139
|
+
const submit = on("submit");
|
|
140
|
+
button.addEventListener("click", () => submit.emit());
|
|
141
|
+
|
|
142
|
+
section.append(input, button);
|
|
143
|
+
return section;
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
// 3. Create the renderer factory (once, at module level)
|
|
147
|
+
const mount = createRenderer(catalog, { Home, Login });
|
|
148
|
+
|
|
149
|
+
// 4. Mount when actor and container are ready
|
|
150
|
+
const actor = createPlayer()();
|
|
151
|
+
actor.start();
|
|
152
|
+
|
|
153
|
+
const disconnect = mount(actor, document.getElementById("app")!);
|
|
154
|
+
|
|
155
|
+
// Cleanup:
|
|
156
|
+
disconnect();
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
## `defineRegistry` — Full Control
|
|
160
|
+
|
|
161
|
+
When you need `registryResult.executeAction()` or want to share the registry with `connectRenderer`:
|
|
162
|
+
|
|
163
|
+
```typescript
|
|
164
|
+
import { defineRegistry, connectRenderer, schema } from "@xmachines/play-dom";
|
|
165
|
+
import { defineCatalog } from "@json-render/core";
|
|
166
|
+
import { z } from "zod";
|
|
167
|
+
|
|
168
|
+
const catalog = defineCatalog(schema, {
|
|
169
|
+
components: {
|
|
170
|
+
Home: { props: z.object({ title: z.string() }) },
|
|
171
|
+
},
|
|
46
172
|
actions: {
|
|
47
|
-
login:
|
|
173
|
+
login: { params: z.object({ username: z.string() }) },
|
|
174
|
+
logout: {},
|
|
175
|
+
},
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
// Action handlers receive (params, setState, state)
|
|
179
|
+
// - params: resolved from the spec's on.submit.params (e.g. { $state: "/username" })
|
|
180
|
+
// - setState: write to the local state store (e.g. to clear a form)
|
|
181
|
+
// - state: current local state store snapshot
|
|
182
|
+
const registryResult = defineRegistry(catalog, {
|
|
183
|
+
components: {
|
|
184
|
+
Home: ({ props }) => {
|
|
185
|
+
const el = document.createElement("section");
|
|
186
|
+
el.textContent = props.title;
|
|
187
|
+
return el;
|
|
188
|
+
},
|
|
189
|
+
},
|
|
190
|
+
actions: {
|
|
191
|
+
login: async (params, setState) => {
|
|
48
192
|
if (!params) return;
|
|
49
193
|
actor.send({ type: "auth.login", username: params.username });
|
|
194
|
+
setState((prev) => ({ ...prev, username: "" })); // clear the form
|
|
50
195
|
},
|
|
51
196
|
logout: async () => actor.send({ type: "auth.logout" }),
|
|
52
197
|
},
|
|
53
198
|
});
|
|
54
199
|
|
|
55
|
-
// 4. Resolve handlers and connect
|
|
56
|
-
const actor = definePlayer({ machine: authMachine })();
|
|
57
|
-
actor.start();
|
|
58
|
-
|
|
59
|
-
const handlers = registryResult.handlers(
|
|
60
|
-
() => undefined,
|
|
61
|
-
() => ({}),
|
|
62
|
-
);
|
|
63
|
-
const container = document.getElementById("app")!;
|
|
64
200
|
const disconnect = connectRenderer({
|
|
65
201
|
actor,
|
|
66
202
|
registry: registryResult.registry,
|
|
67
|
-
|
|
68
|
-
|
|
203
|
+
registryResult, // wires setState/state from xstate store automatically
|
|
204
|
+
container: document.getElementById("app")!,
|
|
205
|
+
});
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
## Component API
|
|
209
|
+
|
|
210
|
+
### `ComponentFn<C, K>` — component function signature
|
|
211
|
+
|
|
212
|
+
```typescript
|
|
213
|
+
const MyCard: ComponentFn<AppCatalog, "Card"> = ({
|
|
214
|
+
props, // catalog-typed props for this component
|
|
215
|
+
children, // Node[] — rendered child nodes
|
|
216
|
+
on, // (eventName) => EventHandle — get emit() for catalog-declared events
|
|
217
|
+
emit, // (eventName) => void — fire an event directly
|
|
218
|
+
bindings, // Record<string, string> — $bindState paths for two-way bindings
|
|
219
|
+
ctx, // DomRenderContext — store, send, handlers, loading, functions
|
|
220
|
+
}) => {
|
|
221
|
+
const el = document.createElement("div");
|
|
222
|
+
el.append(...children);
|
|
223
|
+
return el;
|
|
224
|
+
};
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
### Two-way binding with `$bindState`
|
|
228
|
+
|
|
229
|
+
In the view spec:
|
|
230
|
+
|
|
231
|
+
```json
|
|
232
|
+
{ "username": { "$bindState": "/username" } }
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
In the component:
|
|
236
|
+
|
|
237
|
+
```typescript
|
|
238
|
+
const Login: ComponentFn<AppCatalog, "Login"> = ({ props, ctx }) => {
|
|
239
|
+
const input = document.createElement("input");
|
|
240
|
+
input.value = props.username ?? "";
|
|
241
|
+
// Write back to the store on user input
|
|
242
|
+
input.addEventListener("input", () => {
|
|
243
|
+
ctx.store.update((s) => ({ ...s, username: input.value }));
|
|
244
|
+
});
|
|
245
|
+
return input;
|
|
246
|
+
};
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
### `on()` — event handle
|
|
250
|
+
|
|
251
|
+
```typescript
|
|
252
|
+
const submit = on("submit"); // EventHandle
|
|
253
|
+
if (submit.bound) {
|
|
254
|
+
button.addEventListener("click", (e) => {
|
|
255
|
+
if (submit.shouldPreventDefault) e.preventDefault();
|
|
256
|
+
submit.emit(); // resolves params from store, calls action handler
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
### `ActionFn` — action handler signature
|
|
262
|
+
|
|
263
|
+
```typescript
|
|
264
|
+
// Full signature — all three params are available
|
|
265
|
+
login: async (params, setState, state) => {
|
|
266
|
+
actor.send({ type: "auth.login", username: params!.username });
|
|
267
|
+
setState(prev => ({ ...prev, username: "" }));
|
|
268
|
+
console.log("previous state was:", state);
|
|
269
|
+
},
|
|
270
|
+
|
|
271
|
+
// Params-only — setState/state can be omitted if unused
|
|
272
|
+
logout: async () => actor.send({ type: "auth.logout" }),
|
|
273
|
+
route: async (params) => actor.send({ type: "play.route", to: params!.to }),
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
## Spec Features
|
|
277
|
+
|
|
278
|
+
`renderSpec` / `renderElement` supports these spec directives:
|
|
279
|
+
|
|
280
|
+
| Directive | Description |
|
|
281
|
+
| ------------------------------------------------------ | ------------------------------------------------------------------------------------- |
|
|
282
|
+
| `visible` | Boolean or `{ $state: "/path" }` — hide element when false |
|
|
283
|
+
| `on.submit` / `on.click` | Action binding — `{ action: "login", params: { username: { $state: "/username" } } }` |
|
|
284
|
+
| `repeat: { statePath, key? }` | Render children once per item in the state array at `statePath` |
|
|
285
|
+
| `watch: { "/path": actionBinding }` | Fire action when store path changes after mount |
|
|
286
|
+
| `props.username: { $bindState: "/username" }` | Two-way binding — read from store, write back via `ctx.store.update()` |
|
|
287
|
+
| `props.value: { $state: "/value" }` | Read-only store reference |
|
|
288
|
+
| `props.label: { $computed: "computeFn", args: [...] }` | Computed prop via `functions` map |
|
|
289
|
+
|
|
290
|
+
## `PlayRenderer` — class API
|
|
291
|
+
|
|
292
|
+
```typescript
|
|
293
|
+
import { PlayRenderer, defineRegistry } from "@xmachines/play-dom";
|
|
294
|
+
|
|
295
|
+
const { registry, registryResult } = defineRegistry(catalog, { components, actions });
|
|
296
|
+
|
|
297
|
+
const renderer = new PlayRenderer(document.getElementById("app")!, actor, registry, {
|
|
298
|
+
registryResult,
|
|
69
299
|
});
|
|
300
|
+
|
|
301
|
+
renderer.connect(); // starts watching actor.currentView
|
|
302
|
+
renderer.disconnect(); // stops watching, clears container
|
|
303
|
+
|
|
304
|
+
// double-connect is safe — connect() calls disconnect() internally if already connected
|
|
70
305
|
```
|
|
71
306
|
|
|
307
|
+
## Options Reference
|
|
308
|
+
|
|
309
|
+
### `ConnectRendererOptions` / `PlayDomOptions`
|
|
310
|
+
|
|
311
|
+
| Option | Type | Description |
|
|
312
|
+
| ---------------- | ------------------------------- | ----------------------------------------------------------------------------- |
|
|
313
|
+
| `actor` | `AbstractActor & Viewable` | Actor providing `currentView` signal |
|
|
314
|
+
| `registry` | `DomRegistry` | Component renderer map from `defineRegistry` |
|
|
315
|
+
| `registryResult` | `DefineRegistryResult` | Preferred — auto-wires `setState`/`state` from xstate store |
|
|
316
|
+
| `handlers` | `Record<string, ActionHandler>` | Pre-resolved handlers (legacy / advanced) |
|
|
317
|
+
| `container` | `HTMLElement` | DOM element to render into |
|
|
318
|
+
| `fallback` | `HTMLElement \| null` | Shown on initial mount when view is `null` (initial mount only) |
|
|
319
|
+
| `store` | `StateStore` | External store — controlled mode, overrides `spec.state` |
|
|
320
|
+
| `loading` | `boolean` | Streaming mode — suppresses missing-child warnings, exposes `ctx.ctx.loading` |
|
|
321
|
+
|
|
72
322
|
## Learn More
|
|
73
323
|
|
|
74
324
|
- [DOM Router adapter `@xmachines/play-dom-router`](../play-dom-router/README.md)
|
|
325
|
+
- [API reference](../../packages/docs/api/@xmachines/play-dom/README.md)
|
|
326
|
+
- [Play RFC](../../packages/docs/rfc/play.md)
|
package/dist/PlayRenderer.d.ts
CHANGED
|
@@ -11,26 +11,39 @@
|
|
|
11
11
|
import type { AbstractActor, Viewable } from "@xmachines/play-actor";
|
|
12
12
|
import type { AnyActorLogic } from "xstate";
|
|
13
13
|
import type { DomRegistry } from "./json-render/types.js";
|
|
14
|
-
import type { PlayDomOptions } from "./
|
|
14
|
+
import type { PlayDomOptions } from "./types.js";
|
|
15
15
|
/**
|
|
16
|
-
* PlayRenderer connects an actor's currentView signal to the DOM renderer.
|
|
16
|
+
* PlayRenderer connects an actor's `currentView` signal to the DOM renderer.
|
|
17
17
|
*
|
|
18
|
-
*
|
|
18
|
+
* Watches `actor.currentView` via TC39 Signals and renders `DomComponentRenderer`
|
|
19
|
+
* functions into `container` on every view transition. Cleared on `disconnect()`.
|
|
20
|
+
*
|
|
21
|
+
* **Preferred usage — via `registryResult`:**
|
|
19
22
|
* ```typescript
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* const
|
|
23
|
+
* import { PlayRenderer, defineRegistry } from "@xmachines/play-dom";
|
|
24
|
+
*
|
|
25
|
+
* const registryResult = defineRegistry(catalog, { components, actions });
|
|
26
|
+
* const renderer = new PlayRenderer(container, actor, registryResult.registry, {
|
|
27
|
+
* registryResult, // wires setState/getState from xstate store automatically
|
|
28
|
+
* });
|
|
23
29
|
* renderer.connect();
|
|
30
|
+
* // Later:
|
|
31
|
+
* renderer.disconnect();
|
|
32
|
+
* ```
|
|
24
33
|
*
|
|
25
|
-
*
|
|
34
|
+
* **Controlled store mode** — bring your own `StateStore`:
|
|
35
|
+
* ```typescript
|
|
26
36
|
* import { createAtom } from "@xstate/store";
|
|
27
37
|
* import { xstateStoreStateStore } from "@json-render/xstate";
|
|
28
|
-
* const store = xstateStoreStateStore({ atom: createAtom({ username: "" }) });
|
|
29
|
-
* const renderer = new PlayRenderer(container, actor, registry, { store, handlers: resolvedHandlers });
|
|
30
38
|
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
39
|
+
* const atom = createAtom({ username: "" });
|
|
40
|
+
* const store = xstateStoreStateStore({ atom });
|
|
41
|
+
* const renderer = new PlayRenderer(container, actor, registry, { registryResult, store });
|
|
42
|
+
* renderer.connect();
|
|
33
43
|
* ```
|
|
44
|
+
*
|
|
45
|
+
* Double `connect()` is safe — calling `connect()` while already connected
|
|
46
|
+
* automatically disconnects first, preventing double-render subscriptions.
|
|
34
47
|
*/
|
|
35
48
|
export declare class PlayRenderer {
|
|
36
49
|
private readonly container;
|
|
@@ -39,18 +52,34 @@ export declare class PlayRenderer {
|
|
|
39
52
|
private readonly options;
|
|
40
53
|
private _unwatch;
|
|
41
54
|
private _storeUnsubscribe;
|
|
55
|
+
private _watchCleanups;
|
|
56
|
+
/**
|
|
57
|
+
* Set to `false` in `disconnect()` before calling `storeUnsub()`.
|
|
58
|
+
* The `rerender` closure checks this flag at entry so that any synchronous
|
|
59
|
+
* callback fired by the `StateStore` implementation within its own
|
|
60
|
+
* `unsubscribe()` call (an edge-case but valid contract) does not mutate a
|
|
61
|
+
* detached DOM tree.
|
|
62
|
+
*/
|
|
63
|
+
private _alive;
|
|
42
64
|
/**
|
|
43
|
-
* @param container -
|
|
44
|
-
* @param actor
|
|
45
|
-
* @param registry
|
|
46
|
-
* @param options
|
|
47
|
-
*
|
|
48
|
-
*
|
|
65
|
+
* @param container - `HTMLElement` to render into. Cleared and repopulated on every view transition.
|
|
66
|
+
* @param actor - Actor providing the `currentView` signal (must implement `Viewable`).
|
|
67
|
+
* @param registry - Component renderer map — typically `registryResult.registry` from `defineRegistry`.
|
|
68
|
+
* @param options - Configuration:
|
|
69
|
+
* - `registryResult` — preferred; auto-wires `setState`/`state` from the xstate store.
|
|
70
|
+
* - `handlers` — pre-resolved handler map (legacy; used when `registryResult` is absent).
|
|
71
|
+
* - `store` — external `StateStore` (controlled mode; overrides `spec.state` seeding).
|
|
72
|
+
* - `loading` — streaming mode flag; suppresses missing-child warnings.
|
|
49
73
|
*/
|
|
50
74
|
constructor(container: HTMLElement, actor: AbstractActor<AnyActorLogic> & Viewable, registry: DomRegistry, options?: PlayDomOptions);
|
|
51
75
|
/**
|
|
52
76
|
* Start watching actor.currentView and render to container.
|
|
53
77
|
* Renders the initial view synchronously, then subscribes to signal changes.
|
|
78
|
+
*
|
|
79
|
+
* Calling `connect()` on an already-connected renderer (where a previous
|
|
80
|
+
* `connect()` was never followed by `disconnect()`) would silently install a
|
|
81
|
+
* second `watchSignal` subscription, causing double-renders on every view
|
|
82
|
+
* change. Guard against this by auto-disconnecting first.
|
|
54
83
|
*/
|
|
55
84
|
connect(): void;
|
|
56
85
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlayRenderer.d.ts","sourceRoot":"","sources":["../src/PlayRenderer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAMH,OAAO,KAAK,EAAE,aAAa,EAAE,QAAQ,
|
|
1
|
+
{"version":3,"file":"PlayRenderer.d.ts","sourceRoot":"","sources":["../src/PlayRenderer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAMH,OAAO,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAY,MAAM,uBAAuB,CAAC;AAC/E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAE5C,OAAO,KAAK,EAAE,WAAW,EAAY,MAAM,wBAAwB,CAAC;AACpE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAyBjD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,qBAAa,YAAY;IAwBvB,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,KAAK;IACtB,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,OAAO;IA1BzB,OAAO,CAAC,QAAQ,CAA6B;IAC7C,OAAO,CAAC,iBAAiB,CAA6B;IACtD,OAAO,CAAC,cAAc,CAAsB;IAC5C;;;;;;OAMG;IACH,OAAO,CAAC,MAAM,CAAQ;IAEtB;;;;;;;;;OASG;gBAEe,SAAS,EAAE,WAAW,EACtB,KAAK,EAAE,aAAa,CAAC,aAAa,CAAC,GAAG,QAAQ,EAC9C,QAAQ,EAAE,WAAW,EACrB,OAAO,GAAE,cAAmB;IAG9C;;;;;;;;OAQG;IACH,OAAO,IAAI,IAAI;IAMf;;OAEG;IACH,UAAU,IAAI,IAAI;IAmBlB,OAAO,CAAC,OAAO;CAuFf"}
|