@xmachines/play-solid 1.0.0-beta.1
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 +110 -0
- package/dist/PlayRenderer.js +30 -0
- package/dist/PlayRenderer.js.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/package.json +54 -0
package/README.md
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# @xmachines/play-solid
|
|
2
|
+
|
|
3
|
+
SolidJS renderer for XMachines Play architecture. Enables catalog-driven view rendering with actor-owned business state.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @xmachines/play-solid solid-js
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Current Exports
|
|
12
|
+
|
|
13
|
+
- `PlayRenderer`
|
|
14
|
+
- `PlayRendererProps` (type)
|
|
15
|
+
|
|
16
|
+
## Usage
|
|
17
|
+
|
|
18
|
+
```typescript
|
|
19
|
+
import { PlayRenderer } from '@xmachines/play-solid';
|
|
20
|
+
import { definePlayer } from '@xmachines/play-xstate';
|
|
21
|
+
import { defineCatalog } from '@xmachines/play-catalog';
|
|
22
|
+
|
|
23
|
+
// Define catalog
|
|
24
|
+
const catalog = defineCatalog({
|
|
25
|
+
Home: { component: 'Home', props: {} },
|
|
26
|
+
Login: { component: 'Login', props: { error: { type: 'string' } } }
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
// Create player
|
|
30
|
+
const createPlayer = definePlayer({
|
|
31
|
+
machine: authMachine,
|
|
32
|
+
catalog
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
const actor = createPlayer();
|
|
36
|
+
actor.start();
|
|
37
|
+
|
|
38
|
+
// Define components
|
|
39
|
+
const components = {
|
|
40
|
+
Home: (props) => <div>Home</div>,
|
|
41
|
+
Login: (props) => (
|
|
42
|
+
<form onSubmit={(e) => {
|
|
43
|
+
e.preventDefault();
|
|
44
|
+
props.send({ type: 'auth.login', payload: {...} });
|
|
45
|
+
}}>
|
|
46
|
+
{props.error && <p>{props.error}</p>}
|
|
47
|
+
<input type="text" name="username" />
|
|
48
|
+
<button type="submit">Login</button>
|
|
49
|
+
</form>
|
|
50
|
+
)
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
// Render
|
|
54
|
+
<PlayRenderer actor={actor} components={components} />
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## API
|
|
58
|
+
|
|
59
|
+
### PlayRenderer
|
|
60
|
+
|
|
61
|
+
Component that observes `actor.currentView` signal and renders the appropriate component from the catalog.
|
|
62
|
+
|
|
63
|
+
**Props:**
|
|
64
|
+
|
|
65
|
+
- `actor: AbstractActor & Viewable` - Actor instance with currentView signal
|
|
66
|
+
- `components: Record<string, Component<any>>` - Map of component names to SolidJS components
|
|
67
|
+
- `fallback?: JSX.Element` - Optional fallback to show when currentView is null
|
|
68
|
+
|
|
69
|
+
**Features:**
|
|
70
|
+
|
|
71
|
+
- Automatically bridges TC39 Signals to SolidJS reactivity
|
|
72
|
+
- Passes `send` function to components for event forwarding
|
|
73
|
+
- Handles missing components gracefully with error logging
|
|
74
|
+
- Uses one-shot watcher re-watch pattern for proper signal observation
|
|
75
|
+
|
|
76
|
+
## Canonical Watcher Lifecycle
|
|
77
|
+
|
|
78
|
+
Use the same watcher flow as React/Vue/router packages:
|
|
79
|
+
|
|
80
|
+
1. `notify`
|
|
81
|
+
2. `queueMicrotask`
|
|
82
|
+
3. `getPending()`
|
|
83
|
+
4. read actor signals and update framework-local render trigger
|
|
84
|
+
5. re-arm with `watch(...)` or `watch()`
|
|
85
|
+
|
|
86
|
+
Watcher notifications are one-shot, so re-arm is mandatory.
|
|
87
|
+
|
|
88
|
+
## Cleanup Contract
|
|
89
|
+
|
|
90
|
+
Solid integrations must perform explicit teardown:
|
|
91
|
+
|
|
92
|
+
- Use `onCleanup` for lifecycle teardown.
|
|
93
|
+
- Call `unwatch(...)` on teardown, not only reference nulling.
|
|
94
|
+
- Keep adapters/renderers passive; state validity remains actor-owned.
|
|
95
|
+
|
|
96
|
+
## Architecture
|
|
97
|
+
|
|
98
|
+
PlayRenderer follows the XMachines Play architecture:
|
|
99
|
+
|
|
100
|
+
- **Actor Authority**: Actor controls all state transitions via guards
|
|
101
|
+
- **Passive Infrastructure**: Renderer observes signals, sends events
|
|
102
|
+
- **Signal-Only Reactivity**: Business logic state lives in actor signals
|
|
103
|
+
|
|
104
|
+
The renderer bridges TC39 Signals (used by XMachines actors) to SolidJS's reactivity system using `Signal.subtle.Watcher` with a one-shot re-watch pattern.
|
|
105
|
+
|
|
106
|
+
Signals remain observation plumbing, not an alternate mutation channel.
|
|
107
|
+
|
|
108
|
+
## License
|
|
109
|
+
|
|
110
|
+
MIT
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { memo as o, insert as r, createComponent as i, Dynamic as u, mergeProps as s, template as d } from "solid-js/web";
|
|
2
|
+
import { createSignal as g, onMount as b } from "solid-js";
|
|
3
|
+
import { Signal as w } from "@xmachines/play-signals";
|
|
4
|
+
var f = /* @__PURE__ */ d('<div class=play-renderer-error>Component "<!>" not found in catalog. Available: ');
|
|
5
|
+
const h = (n) => {
|
|
6
|
+
const [e, a] = g(n.actor.currentView.get());
|
|
7
|
+
b(() => {
|
|
8
|
+
const t = new w.subtle.Watcher(() => {
|
|
9
|
+
queueMicrotask(() => {
|
|
10
|
+
t.getPending(), a(n.actor.currentView.get()), t.watch(n.actor.currentView);
|
|
11
|
+
});
|
|
12
|
+
});
|
|
13
|
+
t.watch(n.actor.currentView);
|
|
14
|
+
});
|
|
15
|
+
const l = n.actor.send.bind(n.actor);
|
|
16
|
+
return [o(() => o(() => !e())() && (n.fallback || null)), o(() => o(() => !!(e() && !n.components))() && (console.error(`Components catalog is ${n.components === null ? "null" : "undefined"}. Cannot render component "${e().component}".`), n.fallback || null)), o(() => o(() => !!(e() && n.components && !n.components[e().component]))() && (console.error(`Component "${e().component}" not found in catalog. Available components: ${Object.keys(n.components).join(", ")}`), (() => {
|
|
17
|
+
var t = f(), m = t.firstChild, c = m.nextSibling;
|
|
18
|
+
return c.nextSibling, r(t, () => e().component, c), r(t, () => Object.keys(n.components).join(", "), null), t;
|
|
19
|
+
})())), o(() => o(() => !!(e() && n.components && n.components[e().component]))() && i(u, s({
|
|
20
|
+
get component() {
|
|
21
|
+
return n.components[e().component];
|
|
22
|
+
}
|
|
23
|
+
}, () => e().props, {
|
|
24
|
+
send: l
|
|
25
|
+
})))];
|
|
26
|
+
};
|
|
27
|
+
export {
|
|
28
|
+
h as PlayRenderer
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=PlayRenderer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PlayRenderer.js","sources":["../src/PlayRenderer.tsx"],"sourcesContent":["/**\n * PlayRenderer - Main SolidJS renderer component for XMachines Play architecture\n *\n * @packageDocumentation\n */\n\nimport { createSignal, onMount, type Component } from \"solid-js\";\nimport { Dynamic } from \"solid-js/web\";\nimport { Signal } from \"@xmachines/play-signals\";\nimport type { PlayRendererProps, SolidView } from \"./types.js\";\n\n/**\n * Main renderer component that subscribes to actor signals and renders UI\n *\n * Architecture (per XMachines Play patterns):\n * - Subscribes to actor.currentView signal via TC39 Signal.subtle.Watcher\n * - Dynamically renders catalog components based on view.component string\n * - Forwards user events to actor via actor.send()\n * - SolidJS signal only for triggering renders, NOT business logic\n *\n * Invariant: Actor Authority - Actor decides all state transitions via guards.\n * Invariant: Passive Infrastructure - Component observes signals and sends events.\n * Invariant: Signal-Only Reactivity - Business logic state lives in actor signals.\n *\n * @example\n * ```typescript\n * import { PlayRenderer } from \"@xmachines/play-solidjs\";\n * import { definePlayer } from \"@xmachines/play-xstate\";\n *\n * const actor = definePlayer({ machine, catalog })();\n * actor.start();\n *\n * const components = {\n * Dashboard: (props) => <div>User: {props.userId}</div>,\n * LoginForm: (props) => (\n * <form onSubmit={(e) => {\n * e.preventDefault();\n * props.send({ type: \"auth.login\", payload: {...} });\n * }}>...</form>\n * )\n * };\n *\n * <PlayRenderer actor={actor} components={components} />\n * ```\n *\n * @param props - Component props\n * @returns SolidJS element rendering current view from actor\n *\n * @remarks\n * **Component lookup:** Dynamically looks up component from `components` map\n * using `view.component` string from actor.currentView signal.\n *\n * **Event forwarding:** Injects `send` function as prop to components. Components\n * call `send(event)` to forward intents to actor. Actor guards decide validity.\n *\n * **Error handling:** If component not found in catalog, logs error and shows\n * fallback. This indicates missing component registration, not runtime error.\n *\n * **Signal bridge:** Uses one-shot re-watch pattern. TC39 Signal watchers stop\n * watching after notification, so watcher.watch() must be called in microtask\n * after getPending() to re-arm for next notification.\n *\n * **CRITICAL:** Never call actor.send() during render - only in event handlers.\n * Calling send during render causes infinite render loops.\n */\nexport const PlayRenderer: Component<PlayRendererProps> = (props) => {\n\t// Create SolidJS signal for view\n\t// Signal is NOT business logic state - it's just SolidJS's render trigger\n\tconst [view, setView] = createSignal<SolidView>(props.actor.currentView.get() as SolidView);\n\n\t// Bridge TC39 Signal to SolidJS signal\n\t// Uses one-shot re-watch pattern (must re-watch after each notification)\n\tonMount(() => {\n\t\tconst watcher = new Signal.subtle.Watcher(() => {\n\t\t\tqueueMicrotask(() => {\n\t\t\t\t// Acknowledge the notification\n\t\t\t\twatcher.getPending();\n\n\t\t\t\t// Update SolidJS signal (triggers SolidJS reactivity)\n\t\t\t\tsetView(props.actor.currentView.get() as SolidView);\n\n\t\t\t\t// Re-watch for next notification (one-shot pattern)\n\t\t\t\t// TC39 Signal watchers stop watching after notification\n\t\t\t\twatcher.watch(props.actor.currentView);\n\t\t\t});\n\t\t});\n\n\t\t// Watch actor.currentView for changes\n\t\twatcher.watch(props.actor.currentView);\n\n\t\t// Note: TC39 Signal watchers don't have explicit disposal\n\t\t// The watcher will be garbage collected when the component unmounts\n\t});\n\n\t// Bind send function (ensures correct 'this' context)\n\tconst sendBound = props.actor.send.bind(props.actor);\n\n\treturn (\n\t\t<>\n\t\t\t{/* No view - show fallback */}\n\t\t\t{!view() && (props.fallback || null)}\n\n\t\t\t{/* Handle null/undefined components catalog gracefully */}\n\t\t\t{view() &&\n\t\t\t\t!props.components &&\n\t\t\t\t(() => {\n\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t`Components catalog is ${props.components === null ? \"null\" : \"undefined\"}. ` +\n\t\t\t\t\t\t\t`Cannot render component \"${view()!.component}\".`,\n\t\t\t\t\t);\n\t\t\t\t\treturn props.fallback || null;\n\t\t\t\t})()}\n\n\t\t\t{/* View exists but component not found */}\n\t\t\t{view() &&\n\t\t\t\tprops.components &&\n\t\t\t\t!props.components[view()!.component] &&\n\t\t\t\t(() => {\n\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t`Component \"${view()!.component}\" not found in catalog. ` +\n\t\t\t\t\t\t\t`Available components: ${Object.keys(props.components).join(\", \")}`,\n\t\t\t\t\t);\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<div class=\"play-renderer-error\">\n\t\t\t\t\t\t\tComponent \"{view()!.component}\" not found in catalog. Available:{\" \"}\n\t\t\t\t\t\t\t{Object.keys(props.components).join(\", \")}\n\t\t\t\t\t\t</div>\n\t\t\t\t\t);\n\t\t\t\t})()}\n\n\t\t\t{/* Render matched component dynamically */}\n\t\t\t{view() && props.components && props.components[view()!.component] && (\n\t\t\t\t<Dynamic\n\t\t\t\t\tcomponent={props.components[view()!.component]}\n\t\t\t\t\t{...view()!.props}\n\t\t\t\t\tsend={sendBound}\n\t\t\t\t/>\n\t\t\t)}\n\t\t</>\n\t);\n};\n"],"names":["PlayRenderer","props","view","setView","createSignal","actor","currentView","get","onMount","watcher","Signal","subtle","Watcher","queueMicrotask","getPending","watch","sendBound","send","bind","_$memo","fallback","components","console","error","component","Object","keys","join","_el$","_tmpl$","_el$2","firstChild","_el$5","nextSibling","_$insert","_$createComponent","Dynamic","_$mergeProps"],"mappings":";;;;AAiEO,MAAMA,IAA8CC,CAAAA,MAAU;AAGpE,QAAM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B,UAAU,EAAEM,KAAK,IAAI,GAAC,IAAA,GAAAC;AAAAA,EAAA,GAAA,EAGxC,GAAAT,EAAA,MAGJA,EAAA,MAAA,CAAA,EAAAjB,EAAAA,KAAUD,EAAMoB,cAAcpB,EAAMoB,WAAWnB,EAAAA,EAAQsB,SAAS,EAAC,OAAAW,EAChEC,GAAOC,EAAA;AAAA,IAAA,IACPb,YAAS;AAAA,aAAEvB,EAAMoB,WAAWnB,EAAAA,EAAQsB,SAAS;AAAA,IAAC;AAAA,EAAA,GAAA,MAC1CtB,EAAAA,EAAQD,OAAK;AAAA,IACjBgB,MAAMD;AAAAA,EAAAA,CAAS,CAAA,CAEhB,CAAA;AAGJ;"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@xmachines/play-solid",
|
|
3
|
+
"version": "1.0.0-beta.1",
|
|
4
|
+
"description": "SolidJS renderer for XMachines Play architecture",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"catalog",
|
|
7
|
+
"play",
|
|
8
|
+
"renderer",
|
|
9
|
+
"signals",
|
|
10
|
+
"solidjs",
|
|
11
|
+
"xmachines"
|
|
12
|
+
],
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"author": "XMachines Contributors",
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"type": "module",
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"default": "./dist/index.js"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "vite build && tsc --build",
|
|
27
|
+
"clean": "rm -rf dist tsconfig.tsbuildinfo",
|
|
28
|
+
"typecheck": "tsc --noEmit",
|
|
29
|
+
"test": "vitest run",
|
|
30
|
+
"test:watch": "vitest",
|
|
31
|
+
"test:ui": "vitest --ui",
|
|
32
|
+
"prepublishOnly": "npm run build"
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@xmachines/play-actor": "1.0.0-beta.1",
|
|
36
|
+
"@xmachines/play-catalog": "1.0.0-beta.1",
|
|
37
|
+
"@xmachines/play-signals": "1.0.0-beta.1"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@solidjs/testing-library": "^0.8.10",
|
|
41
|
+
"@types/node": "^25.4.0",
|
|
42
|
+
"solid-js": "^1.9.3",
|
|
43
|
+
"typescript": "^5.7.0",
|
|
44
|
+
"vite": "^7.3.1",
|
|
45
|
+
"vite-plugin-solid": "^2.11.4",
|
|
46
|
+
"vitest": "^4.0.18"
|
|
47
|
+
},
|
|
48
|
+
"peerDependencies": {
|
|
49
|
+
"solid-js": "^1.8.0 || ^1.9.0"
|
|
50
|
+
},
|
|
51
|
+
"publishConfig": {
|
|
52
|
+
"access": "public"
|
|
53
|
+
}
|
|
54
|
+
}
|