@xmachines/play-solid 1.0.0-beta.51 → 1.0.0-beta.52
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 +17 -19
- package/dist/ActorProvider.js.map +1 -1
- package/dist/useActor.js.map +1 -1
- package/package.json +8 -5
package/README.md
CHANGED
|
@@ -28,14 +28,8 @@ import { definePlayer } from "@xmachines/play-xstate";
|
|
|
28
28
|
import { defineCatalog } from "@json-render/core";
|
|
29
29
|
import { schema } from "@json-render/solid/schema";
|
|
30
30
|
|
|
31
|
-
// 1. Define a catalog
|
|
32
|
-
const catalog = defineCatalog(schema,
|
|
33
|
-
components: {
|
|
34
|
-
Home: { props: z.object({}), description: "Home screen" },
|
|
35
|
-
Login: { props: z.object({ error: z.string().optional() }), description: "Login screen" },
|
|
36
|
-
},
|
|
37
|
-
actions: {},
|
|
38
|
-
});
|
|
31
|
+
// 1. Define a catalog (authCatalogDef is a plain object describing components/actions)
|
|
32
|
+
const catalog = defineCatalog(schema, authCatalogDef);
|
|
39
33
|
|
|
40
34
|
// 2. Build a component registry
|
|
41
35
|
const registryResult = defineRegistry(catalog, {
|
|
@@ -43,6 +37,10 @@ const registryResult = defineRegistry(catalog, {
|
|
|
43
37
|
Home: () => <div>Welcome home!</div>,
|
|
44
38
|
Login: (ctx) => <div>Login {ctx.props.error && <span>{ctx.props.error}</span>}</div>,
|
|
45
39
|
},
|
|
40
|
+
actions: {
|
|
41
|
+
login: async (args) => actor.send({ type: "auth.login", username: args.username }),
|
|
42
|
+
logout: async () => actor.send({ type: "auth.logout" }),
|
|
43
|
+
},
|
|
46
44
|
});
|
|
47
45
|
|
|
48
46
|
// 3. Create and start an actor
|
|
@@ -108,7 +106,7 @@ function SubmitButton() {
|
|
|
108
106
|
|
|
109
107
|
### `usePlayView` hook
|
|
110
108
|
|
|
111
|
-
Access the resolved view context (spec, handlers, registry) from within the provider tree:
|
|
109
|
+
Access the resolved view context (spec, handlers, registry, store) from within the provider tree:
|
|
112
110
|
|
|
113
111
|
```tsx
|
|
114
112
|
import { usePlayView } from "@xmachines/play-solid";
|
|
@@ -132,10 +130,10 @@ const MyRenderer = () => {
|
|
|
132
130
|
|
|
133
131
|
### Hooks
|
|
134
132
|
|
|
135
|
-
| Export | Description
|
|
136
|
-
| --------------- |
|
|
137
|
-
| `useActor()` | Returns the raw `
|
|
138
|
-
| `usePlayView()` | Returns the current `ViewContextValue` (spec, handlers, registry, store)
|
|
133
|
+
| Export | Description |
|
|
134
|
+
| --------------- | --------------------------------------------------------------------------------------------- |
|
|
135
|
+
| `useActor()` | Returns the raw `AnyPlayActor` instance from context; throws outside a provider tree |
|
|
136
|
+
| `usePlayView()` | Returns the current `ViewContextValue` (spec, handlers, registry, store); throws outside tree |
|
|
139
137
|
|
|
140
138
|
### Context
|
|
141
139
|
|
|
@@ -174,12 +172,12 @@ import {
|
|
|
174
172
|
|
|
175
173
|
### Key Types
|
|
176
174
|
|
|
177
|
-
| Type | Description
|
|
178
|
-
| --------------------- |
|
|
179
|
-
| `PlayUIProviderProps` | Props for `PlayUIProvider`
|
|
180
|
-
| `ActorProviderProps` | Props for `ActorProvider`
|
|
181
|
-
| `ViewContextValue` | Shape of the context value from `usePlayView()`
|
|
182
|
-
| `
|
|
175
|
+
| Type | Description |
|
|
176
|
+
| --------------------- | ------------------------------------------------------------------------------ |
|
|
177
|
+
| `PlayUIProviderProps` | Props for `PlayUIProvider` |
|
|
178
|
+
| `ActorProviderProps` | Props for `ActorProvider` |
|
|
179
|
+
| `ViewContextValue` | Shape of the context value from `usePlayView()` |
|
|
180
|
+
| `AnyPlayActor` | `AbstractActor<AnyActorLogic>` — bare actor type accepted by context providers |
|
|
183
181
|
|
|
184
182
|
## Testing
|
|
185
183
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ActorProvider.js","names":["createSignal","createEffect","createMemo","onCleanup","createContext","useContext","ErrorBoundary","Component","JSX","StateProvider","useStateStore","DefineRegistryResult","SetState","StateStore","ComponentRegistry","createAtom","xstateStoreStateStore","watchSignal","assertNonNullable","PlaySpec","BaseActorProviderProps","BaseViewContextValue","ActorContext","PlayActor","ViewContextValue","ViewContext","usePlayView","ActorProviderProps","fallback","Element","onError","error","children","ActorProviderInner","registryResult","spec","store","innerProps","stateCtx","setStateAdapter","updater","prev","getSnapshot","update","handlers","viewValue","registry","_$createComponent","Provider","value","ActorProvider","props","view","setView","resolvedRegistryResult","onRenderError","r","Object","defineProperty","enumerable","configurable","internalStore","lastView","nextView","actor","currentView","get","unwatch","err","rawState","state","initialState","Array","isArray","getPrototypeOf","prototype","Record","atom"],"sources":["../src/ActorProvider.tsx"],"sourcesContent":["/**\n * ActorProvider — Smart SolidJS provider component for the XMachines Play actor lifecycle.\n *\n * Escape hatch primitive for library authors who need direct control. Most users should\n * use PlayUIProvider (batteries-included composite) instead.\n *\n * This component:\n * - Subscribes to actor.currentView signal via watchSignal (in component body per Phase 29)\n * - Manages per-view StateStore lifecycle (controlled/uncontrolled)\n * - Resolves action handlers via inner component pattern (inside StateProvider)\n * - Injects onRenderError into registry if provided\n * - Provides ActorContext (actor) and ViewContext (spec + handlers + registry) to children\n * - Wraps render path in SolidJS ErrorBoundary\n *\n * Per D-11: The old `ActorProvider = ActorContext.Provider` alias is removed. This new smart\n * component takes the name. Use `ActorContext.Provider` directly for escape-hatch access.\n *\n * @packageDocumentation\n */\n\nimport {\n\tcreateSignal,\n\tcreateEffect,\n\tcreateMemo,\n\tonCleanup,\n\tcreateContext,\n\tuseContext,\n\tErrorBoundary,\n} from \"solid-js\";\nimport type { Component, JSX } from \"solid-js\";\nimport { StateProvider, useStateStore } from \"@json-render/solid\";\nimport type { DefineRegistryResult, SetState } from \"@json-render/solid\";\nimport type { StateStore } from \"@json-render/core\";\nimport type { ComponentRegistry } from \"@json-render/solid\";\nimport { createAtom } from \"@xstate/store\";\nimport { xstateStoreStateStore } from \"@json-render/xstate\";\nimport { watchSignal } from \"@xmachines/play-signals\";\nimport { assertNonNullable } from \"@xmachines/play\";\nimport type { PlaySpec, BaseActorProviderProps, BaseViewContextValue } from \"@xmachines/play-actor\";\nimport { ActorContext, type PlayActor } from \"./useActor.js\";\n\n// ---------------------------------------------------------------------------\n// ViewContextValue — shape of the context value provided by ActorProvider\n// ---------------------------------------------------------------------------\n\n/**\n * Value provided by ActorProvider's ViewContext.\n * Access via usePlayView() inside the ActorProvider tree.\n */\nexport interface ViewContextValue extends BaseViewContextValue<ComponentRegistry> {}\n\nconst ViewContext = createContext<ViewContextValue | null>(null);\n\n/**\n * Hook to access the current view context inside an ActorProvider tree.\n *\n * @throws {Error} If called outside an ActorProvider (or PlayUIProvider) tree\n *\n * @example\n * ```tsx\n * import { usePlayView } from \"@xmachines/play-solid\";\n *\n * const MyRenderer: Component = () => {\n * const view = usePlayView();\n * return <Renderer spec={view.spec} registry={view.registry} />;\n * };\n * ```\n */\nexport function usePlayView(): ViewContextValue {\n\treturn assertNonNullable(useContext(ViewContext), \"ViewContext\");\n}\n\n// ---------------------------------------------------------------------------\n// ActorProviderProps\n// ---------------------------------------------------------------------------\n\n/**\n * Props for ActorProvider — the escape hatch primitive.\n *\n * For batteries-included usage, prefer PlayUIProvider which wraps ActorProvider\n * with JSONUIProvider and all required sub-providers.\n */\nexport interface ActorProviderProps extends BaseActorProviderProps<DefineRegistryResult> {\n\t/** Optional fallback element shown when currentView is null or ErrorBoundary catches */\n\tfallback?: JSX.Element;\n\n\t/** Optional callback invoked when SolidJS ErrorBoundary catches an error */\n\tonError?: (error: unknown) => void;\n\n\t/** Children — required; must include <PlayRenderer /> (or use PlayUIProvider shorthand) */\n\tchildren: JSX.Element;\n}\n\n// ---------------------------------------------------------------------------\n// ActorProviderInner — resolves handlers inside StateProvider tree\n// ---------------------------------------------------------------------------\n\n/**\n * Inner component that runs inside StateProvider so it can call useStateStore()\n * to get live set/getSnapshot for handler resolution.\n */\nconst ActorProviderInner: Component<{\n\tregistryResult: DefineRegistryResult;\n\tspec: PlaySpec;\n\tstore: StateStore;\n\tchildren: JSX.Element;\n}> = (innerProps) => {\n\tconst stateCtx = useStateStore();\n\n\t// Build SetState adapter bridging stateCtx.update/getSnapshot\n\tconst setStateAdapter: SetState = (updater) => {\n\t\tconst prev = stateCtx.getSnapshot();\n\t\tstateCtx.update(updater(prev));\n\t};\n\n\tconst handlers = innerProps.registryResult.handlers(\n\t\t() => setStateAdapter,\n\t\t() => stateCtx.getSnapshot(),\n\t);\n\n\tconst viewValue: ViewContextValue = {\n\t\tspec: innerProps.spec,\n\t\thandlers,\n\t\tregistry: innerProps.registryResult.registry,\n\t\tstore: innerProps.store,\n\t};\n\n\treturn <ViewContext.Provider value={viewValue}>{innerProps.children}</ViewContext.Provider>;\n};\n\n// ---------------------------------------------------------------------------\n// ActorProvider — the smart component (per D-11 takes the ActorProvider name)\n// ---------------------------------------------------------------------------\n\n/**\n * Smart ActorProvider component — owns actor bridging, signal subscription,\n * StateStore lifecycle, handler resolution, and error boundary.\n *\n * Per D-11: Replaces the old raw alias `ActorProvider = ActorContext.Provider`.\n * Consumers who previously used `<ActorProvider value={actor}>` should now use\n * `<ActorContext.Provider value={actor}>` for raw provider access, or migrate to\n * this smart component / PlayUIProvider.\n *\n * @example\n * ```tsx\n * import { ActorProvider, PlayRenderer } from \"@xmachines/play-solid\";\n *\n * <ActorProvider actor={myActor} registryResult={registryResult}>\n * <PlayRenderer />\n * </ActorProvider>\n * ```\n */\nexport const ActorProvider: Component<ActorProviderProps> = (props) => {\n\t// SolidJS signal for current view (PlaySpec | null)\n\tconst [view, setView] = createSignal<PlaySpec | null>(null);\n\n\t// Inject onRenderError into registry if provided (non-enumerable override).\n\t// Memoized so that creating a new object on every reactive evaluation does not\n\t// cause unnecessary re-renders of child components that receive this as a prop.\n\tconst resolvedRegistryResult = createMemo(() => {\n\t\tif (!props.onRenderError) return props.registryResult;\n\t\tconst r = { ...props.registryResult.registry };\n\t\tObject.defineProperty(r, \"onRenderError\", {\n\t\t\tvalue: props.onRenderError,\n\t\t\tenumerable: false,\n\t\t\tconfigurable: true,\n\t\t});\n\t\treturn { ...props.registryResult, registry: r };\n\t});\n\n\t// Per-view internal store — recreated on each view transition (uncontrolled mode)\n\tlet internalStore: StateStore | null = null;\n\tlet lastView: PlaySpec | null = null;\n\n\t// Bridge TC39 Signal to SolidJS signal — seed AND watch atomically inside a single\n\t// createEffect to eliminate the race window between .get() and watcher registration.\n\t// If the TC39 signal changes between the initial .get() and first watcher notification,\n\t// the update function captures the latest value without missing it.\n\tcreateEffect(() => {\n\t\tconst update = (nextView: PlaySpec | null) => setView(nextView);\n\t\tupdate(props.actor.currentView.get() as PlaySpec | null);\n\t\tconst unwatch = watchSignal(props.actor.currentView, (nextView) => {\n\t\t\tupdate(nextView as PlaySpec | null);\n\t\t});\n\t\tonCleanup(() => unwatch());\n\t});\n\n\treturn (\n\t\t<ActorContext.Provider value={props.actor as PlayActor}>\n\t\t\t<ErrorBoundary\n\t\t\t\tfallback={(err: unknown) => {\n\t\t\t\t\tprops.onError?.(err);\n\t\t\t\t\treturn props.fallback ?? null;\n\t\t\t\t}}\n\t\t\t>\n\t\t\t\t{(() => {\n\t\t\t\t\tconst currentView = view();\n\t\t\t\t\tif (!currentView) return props.fallback ?? null;\n\n\t\t\t\t\t// Resolve store: external (controlled) or internal per-view atom\n\t\t\t\t\tlet store: StateStore;\n\t\t\t\t\tif (props.store) {\n\t\t\t\t\t\tstore = props.store;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tif (internalStore === null || lastView !== currentView) {\n\t\t\t\t\t\t\t// Proto-safe guard: spec.state must be a plain object (T-37-05-02)\n\t\t\t\t\t\t\tconst rawState = currentView.state;\n\t\t\t\t\t\t\tconst initialState =\n\t\t\t\t\t\t\t\trawState !== null &&\n\t\t\t\t\t\t\t\ttypeof rawState === \"object\" &&\n\t\t\t\t\t\t\t\t!Array.isArray(rawState) &&\n\t\t\t\t\t\t\t\t(Object.getPrototypeOf(rawState) === Object.prototype ||\n\t\t\t\t\t\t\t\t\tObject.getPrototypeOf(rawState) === null)\n\t\t\t\t\t\t\t\t\t? (rawState as Record<string, unknown>)\n\t\t\t\t\t\t\t\t\t: {};\n\t\t\t\t\t\t\tinternalStore = xstateStoreStateStore({\n\t\t\t\t\t\t\t\tatom: createAtom(initialState),\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\tlastView = currentView;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tstore = internalStore;\n\t\t\t\t\t}\n\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<StateProvider store={store}>\n\t\t\t\t\t\t\t<ActorProviderInner\n\t\t\t\t\t\t\t\tregistryResult={resolvedRegistryResult()}\n\t\t\t\t\t\t\t\tspec={currentView}\n\t\t\t\t\t\t\t\tstore={store}\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{props.children}\n\t\t\t\t\t\t\t</ActorProviderInner>\n\t\t\t\t\t\t</StateProvider>\n\t\t\t\t\t);\n\t\t\t\t})()}\n\t\t\t</ErrorBoundary>\n\t\t</ActorContext.Provider>\n\t);\n};\n"],"mappings":";;;;;;;;;AAmDA,IAAMyB,IAAcrB,EAAuC,KAAK;AAiBhE,SAAgBsB,IAAgC;AAC/C,QAAOR,EAAkBb,EAAWoB,EAAY,EAAE,cAAc;;AAgCjE,IAAMQ,KAKAI,MAAe;CACpB,IAAMC,IAAW5B,GAAe,EAG1B6B,KAA6BC,MAAY;EAC9C,IAAMC,IAAOH,EAASI,aAAa;AACnCJ,IAASK,OAAOH,EAAQC,EAAK,CAAC;IAGzBG,IAAWP,EAAWH,eAAeU,eACpCL,SACAD,EAASI,aAChB,CAAC,EAEKG,IAA8B;EACnCV,MAAME,EAAWF;EACjBS;EACAE,UAAUT,EAAWH,eAAeY;EACpCV,OAAOC,EAAWD;EAClB;AAED,QAAAW,EAAQtB,EAAYuB,UAAQ;EAACC,OAAOJ;EAAS,IAAAb,WAAA;AAAA,UAAGK,EAAWL;;EAAQ,CAAA;GAyBvDkB,KAAgDC,MA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CA,IACD,EAAE,CAEwB,EAC7B,CAAC,EACFP,IAAWG;;AAEZ7B,WAAQyB;;AAGT,aAAAd,EACEtC,GAAa;OAAQ2B;OAAK,IAAAJ,WAAA;AAAA,eAAAe,EACzBd,GAAkB;SAAA,IAClBC,iBAAc;AAAA,iBAAEoB,GAAwB;;SACxCnB,MAAM8B;SACC7B;SAAK,IAAAJ,WAAA;AAAA,iBAEXmB,EAAMnB;;SAAQ,CAAA;;OAAA,CAAA;SAIf;;IAAA,CAAA;;EAAA,CAAA"}
|
|
1
|
+
{"version":3,"file":"ActorProvider.js","names":["createSignal","createEffect","createMemo","onCleanup","createContext","useContext","ErrorBoundary","Component","JSX","StateProvider","useStateStore","DefineRegistryResult","SetState","StateStore","ComponentRegistry","createAtom","xstateStoreStateStore","watchSignal","assertNonNullable","PlaySpec","BaseActorProviderProps","BaseViewContextValue","ActorContext","AnyPlayActor","ViewContextValue","ViewContext","usePlayView","ActorProviderProps","fallback","Element","onError","error","children","ActorProviderInner","registryResult","spec","store","innerProps","stateCtx","setStateAdapter","updater","prev","getSnapshot","update","handlers","viewValue","registry","_$createComponent","Provider","value","ActorProvider","props","view","setView","resolvedRegistryResult","onRenderError","r","Object","defineProperty","enumerable","configurable","internalStore","lastView","nextView","actor","currentView","get","unwatch","err","rawState","state","initialState","Array","isArray","getPrototypeOf","prototype","Record","atom"],"sources":["../src/ActorProvider.tsx"],"sourcesContent":["/**\n * ActorProvider — Smart SolidJS provider component for the XMachines Play actor lifecycle.\n *\n * Escape hatch primitive for library authors who need direct control. Most users should\n * use PlayUIProvider (batteries-included composite) instead.\n *\n * This component:\n * - Subscribes to actor.currentView signal via watchSignal (in component body per Phase 29)\n * - Manages per-view StateStore lifecycle (controlled/uncontrolled)\n * - Resolves action handlers via inner component pattern (inside StateProvider)\n * - Injects onRenderError into registry if provided\n * - Provides ActorContext (actor) and ViewContext (spec + handlers + registry) to children\n * - Wraps render path in SolidJS ErrorBoundary\n *\n * Per D-11: The old `ActorProvider = ActorContext.Provider` alias is removed. This new smart\n * component takes the name. Use `ActorContext.Provider` directly for escape-hatch access.\n *\n * @packageDocumentation\n */\n\nimport {\n\tcreateSignal,\n\tcreateEffect,\n\tcreateMemo,\n\tonCleanup,\n\tcreateContext,\n\tuseContext,\n\tErrorBoundary,\n} from \"solid-js\";\nimport type { Component, JSX } from \"solid-js\";\nimport { StateProvider, useStateStore } from \"@json-render/solid\";\nimport type { DefineRegistryResult, SetState } from \"@json-render/solid\";\nimport type { StateStore } from \"@json-render/core\";\nimport type { ComponentRegistry } from \"@json-render/solid\";\nimport { createAtom } from \"@xstate/store\";\nimport { xstateStoreStateStore } from \"@json-render/xstate\";\nimport { watchSignal } from \"@xmachines/play-signals\";\nimport { assertNonNullable } from \"@xmachines/play\";\nimport type { PlaySpec, BaseActorProviderProps, BaseViewContextValue } from \"@xmachines/play-actor\";\nimport { ActorContext, type AnyPlayActor } from \"./useActor.js\";\n\n// ---------------------------------------------------------------------------\n// ViewContextValue — shape of the context value provided by ActorProvider\n// ---------------------------------------------------------------------------\n\n/**\n * Value provided by ActorProvider's ViewContext.\n * Access via usePlayView() inside the ActorProvider tree.\n */\nexport interface ViewContextValue extends BaseViewContextValue<ComponentRegistry> {}\n\nconst ViewContext = createContext<ViewContextValue | null>(null);\n\n/**\n * Hook to access the current view context inside an ActorProvider tree.\n *\n * @throws {Error} If called outside an ActorProvider (or PlayUIProvider) tree\n *\n * @example\n * ```tsx\n * import { usePlayView } from \"@xmachines/play-solid\";\n *\n * const MyRenderer: Component = () => {\n * const view = usePlayView();\n * return <Renderer spec={view.spec} registry={view.registry} />;\n * };\n * ```\n */\nexport function usePlayView(): ViewContextValue {\n\treturn assertNonNullable(useContext(ViewContext), \"ViewContext\");\n}\n\n// ---------------------------------------------------------------------------\n// ActorProviderProps\n// ---------------------------------------------------------------------------\n\n/**\n * Props for ActorProvider — the escape hatch primitive.\n *\n * For batteries-included usage, prefer PlayUIProvider which wraps ActorProvider\n * with JSONUIProvider and all required sub-providers.\n */\nexport interface ActorProviderProps extends BaseActorProviderProps<DefineRegistryResult> {\n\t/** Optional fallback element shown when currentView is null or ErrorBoundary catches */\n\tfallback?: JSX.Element;\n\n\t/** Optional callback invoked when SolidJS ErrorBoundary catches an error */\n\tonError?: (error: unknown) => void;\n\n\t/** Children — required; must include <PlayRenderer /> (or use PlayUIProvider shorthand) */\n\tchildren: JSX.Element;\n}\n\n// ---------------------------------------------------------------------------\n// ActorProviderInner — resolves handlers inside StateProvider tree\n// ---------------------------------------------------------------------------\n\n/**\n * Inner component that runs inside StateProvider so it can call useStateStore()\n * to get live set/getSnapshot for handler resolution.\n */\nconst ActorProviderInner: Component<{\n\tregistryResult: DefineRegistryResult;\n\tspec: PlaySpec;\n\tstore: StateStore;\n\tchildren: JSX.Element;\n}> = (innerProps) => {\n\tconst stateCtx = useStateStore();\n\n\t// Build SetState adapter bridging stateCtx.update/getSnapshot\n\tconst setStateAdapter: SetState = (updater) => {\n\t\tconst prev = stateCtx.getSnapshot();\n\t\tstateCtx.update(updater(prev));\n\t};\n\n\tconst handlers = innerProps.registryResult.handlers(\n\t\t() => setStateAdapter,\n\t\t() => stateCtx.getSnapshot(),\n\t);\n\n\tconst viewValue: ViewContextValue = {\n\t\tspec: innerProps.spec,\n\t\thandlers,\n\t\tregistry: innerProps.registryResult.registry,\n\t\tstore: innerProps.store,\n\t};\n\n\treturn <ViewContext.Provider value={viewValue}>{innerProps.children}</ViewContext.Provider>;\n};\n\n// ---------------------------------------------------------------------------\n// ActorProvider — the smart component (per D-11 takes the ActorProvider name)\n// ---------------------------------------------------------------------------\n\n/**\n * Smart ActorProvider component — owns actor bridging, signal subscription,\n * StateStore lifecycle, handler resolution, and error boundary.\n *\n * Per D-11: Replaces the old raw alias `ActorProvider = ActorContext.Provider`.\n * Consumers who previously used `<ActorProvider value={actor}>` should now use\n * `<ActorContext.Provider value={actor}>` for raw provider access, or migrate to\n * this smart component / PlayUIProvider.\n *\n * @example\n * ```tsx\n * import { ActorProvider, PlayRenderer } from \"@xmachines/play-solid\";\n *\n * <ActorProvider actor={myActor} registryResult={registryResult}>\n * <PlayRenderer />\n * </ActorProvider>\n * ```\n */\nexport const ActorProvider: Component<ActorProviderProps> = (props) => {\n\t// SolidJS signal for current view (PlaySpec | null)\n\tconst [view, setView] = createSignal<PlaySpec | null>(null);\n\n\t// Inject onRenderError into registry if provided (non-enumerable override).\n\t// Memoized so that creating a new object on every reactive evaluation does not\n\t// cause unnecessary re-renders of child components that receive this as a prop.\n\tconst resolvedRegistryResult = createMemo(() => {\n\t\tif (!props.onRenderError) return props.registryResult;\n\t\tconst r = { ...props.registryResult.registry };\n\t\tObject.defineProperty(r, \"onRenderError\", {\n\t\t\tvalue: props.onRenderError,\n\t\t\tenumerable: false,\n\t\t\tconfigurable: true,\n\t\t});\n\t\treturn { ...props.registryResult, registry: r };\n\t});\n\n\t// Per-view internal store — recreated on each view transition (uncontrolled mode)\n\tlet internalStore: StateStore | null = null;\n\tlet lastView: PlaySpec | null = null;\n\n\t// Bridge TC39 Signal to SolidJS signal — seed AND watch atomically inside a single\n\t// createEffect to eliminate the race window between .get() and watcher registration.\n\t// If the TC39 signal changes between the initial .get() and first watcher notification,\n\t// the update function captures the latest value without missing it.\n\tcreateEffect(() => {\n\t\tconst update = (nextView: PlaySpec | null) => setView(nextView);\n\t\tupdate(props.actor.currentView.get() as PlaySpec | null);\n\t\tconst unwatch = watchSignal(props.actor.currentView, (nextView) => {\n\t\t\tupdate(nextView as PlaySpec | null);\n\t\t});\n\t\tonCleanup(() => unwatch());\n\t});\n\n\treturn (\n\t\t<ActorContext.Provider value={props.actor as AnyPlayActor}>\n\t\t\t<ErrorBoundary\n\t\t\t\tfallback={(err: unknown) => {\n\t\t\t\t\tprops.onError?.(err);\n\t\t\t\t\treturn props.fallback ?? null;\n\t\t\t\t}}\n\t\t\t>\n\t\t\t\t{(() => {\n\t\t\t\t\tconst currentView = view();\n\t\t\t\t\tif (!currentView) return props.fallback ?? null;\n\n\t\t\t\t\t// Resolve store: external (controlled) or internal per-view atom\n\t\t\t\t\tlet store: StateStore;\n\t\t\t\t\tif (props.store) {\n\t\t\t\t\t\tstore = props.store;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tif (internalStore === null || lastView !== currentView) {\n\t\t\t\t\t\t\t// Proto-safe guard: spec.state must be a plain object (T-37-05-02)\n\t\t\t\t\t\t\tconst rawState = currentView.state;\n\t\t\t\t\t\t\tconst initialState =\n\t\t\t\t\t\t\t\trawState !== null &&\n\t\t\t\t\t\t\t\ttypeof rawState === \"object\" &&\n\t\t\t\t\t\t\t\t!Array.isArray(rawState) &&\n\t\t\t\t\t\t\t\t(Object.getPrototypeOf(rawState) === Object.prototype ||\n\t\t\t\t\t\t\t\t\tObject.getPrototypeOf(rawState) === null)\n\t\t\t\t\t\t\t\t\t? (rawState as Record<string, unknown>)\n\t\t\t\t\t\t\t\t\t: {};\n\t\t\t\t\t\t\tinternalStore = xstateStoreStateStore({\n\t\t\t\t\t\t\t\tatom: createAtom(initialState),\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\tlastView = currentView;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tstore = internalStore;\n\t\t\t\t\t}\n\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<StateProvider store={store}>\n\t\t\t\t\t\t\t<ActorProviderInner\n\t\t\t\t\t\t\t\tregistryResult={resolvedRegistryResult()}\n\t\t\t\t\t\t\t\tspec={currentView}\n\t\t\t\t\t\t\t\tstore={store}\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{props.children}\n\t\t\t\t\t\t\t</ActorProviderInner>\n\t\t\t\t\t\t</StateProvider>\n\t\t\t\t\t);\n\t\t\t\t})()}\n\t\t\t</ErrorBoundary>\n\t\t</ActorContext.Provider>\n\t);\n};\n"],"mappings":";;;;;;;;;AAmDA,IAAMyB,IAAcrB,EAAuC,KAAK;AAiBhE,SAAgBsB,IAAgC;AAC/C,QAAOR,EAAkBb,EAAWoB,EAAY,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jB,EAAMvB,YAAY;IACzB,IAAAI,WAAA;AAAA,mBAEO;MACP,IAAMiC,IAAcb,GAAM;AAC1B,UAAI,CAACa,EAAa,QAAOd,EAAMvB,YAAY;MAG3C,IAAIQ;AACJ,UAAIe,EAAMf,MACTA,KAAQe,EAAMf;WACR;AACN,WAAIyB,MAAkB,QAAQC,MAAaG,GAAa;QAEvD,IAAMI,IAAWJ,EAAYK;AAY7BR,QAHAD,IAAgB7C,EAAsB,EACrC6D,MAAM9D,EAPN,OAAOsD,KAAa,YADpBA,KAEA,CAACG,MAAMC,QAAQJ,EAAS,KACvBZ,OAAOiB,eAAeL,EAAS,KAAKZ,OAAOkB,aAC3ClB,OAAOiB,eAAeL,EAAS,KAAK,QACjCA,IACD,EAAE,CAEwB,EAC7B,CAAC,EACFP,IAAWG;;AAEZ7B,WAAQyB;;AAGT,aAAAd,EACEtC,GAAa;OAAQ2B;OAAK,IAAAJ,WAAA;AAAA,eAAAe,EACzBd,GAAkB;SAAA,IAClBC,iBAAc;AAAA,iBAAEoB,GAAwB;;SACxCnB,MAAM8B;SACC7B;SAAK,IAAAJ,WAAA;AAAA,iBAEXmB,EAAMnB;;SAAQ,CAAA;;OAAA,CAAA;SAIf;;IAAA,CAAA;;EAAA,CAAA"}
|
package/dist/useActor.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useActor.js","names":[],"sources":["../src/useActor.ts"],"sourcesContent":["/**\n * useActor — SolidJS hook for accessing the raw actor inside an ActorProvider tree.\n *\n * Components rendered inside ActorProvider (or PlayUIProvider) can call useActor()\n * to get direct access to the actor instance without prop drilling.\n *\n * @throws {Error} If called outside an ActorProvider tree\n *\n * @example\n * ```typescript\n * import { useActor } from \"@xmachines/play-solid\";\n *\n * function MyComponent() {\n * const actor = useActor();\n * return <button onClick={() => actor.send({ type: \"SUBMIT\" })}>Submit</button>;\n * }\n * ```\n *\n * @packageDocumentation\n */\n\nimport { createContext, useContext } from \"solid-js\";\nimport { assertNonNullable } from \"@xmachines/play\";\nimport type { AbstractActor } from \"@xmachines/play-actor\";\nimport type { AnyActorLogic } from \"xstate\";\n\
|
|
1
|
+
{"version":3,"file":"useActor.js","names":[],"sources":["../src/useActor.ts"],"sourcesContent":["/**\n * useActor — SolidJS hook for accessing the raw actor inside an ActorProvider tree.\n *\n * Components rendered inside ActorProvider (or PlayUIProvider) can call useActor()\n * to get direct access to the actor instance without prop drilling.\n *\n * @throws {Error} If called outside an ActorProvider tree\n *\n * @example\n * ```typescript\n * import { useActor } from \"@xmachines/play-solid\";\n *\n * function MyComponent() {\n * const actor = useActor();\n * return <button onClick={() => actor.send({ type: \"SUBMIT\" })}>Submit</button>;\n * }\n * ```\n *\n * @packageDocumentation\n */\n\nimport { createContext, useContext } from \"solid-js\";\nimport { assertNonNullable } from \"@xmachines/play\";\nimport type { AbstractActor } from \"@xmachines/play-actor\";\nimport type { AnyActorLogic } from \"xstate\";\n\n/** Bare actor type accepted by Solid context providers. For the full routing + view shape, use `PlayActor` from `@xmachines/play-router`. */\nexport type AnyPlayActor = AbstractActor<AnyActorLogic>;\n\n/**\n * SolidJS context for the actor — exported so consumers can use ActorContext.Provider\n * directly as an escape hatch (per D-11). The smart ActorProvider component takes\n * the name \"ActorProvider\" and is the recommended entry point.\n */\nexport const ActorContext = createContext<AnyPlayActor | null>(null);\n\nexport function useActor(): AnyPlayActor {\n\treturn assertNonNullable(useContext(ActorContext), \"ActorContext\");\n}\n"],"mappings":";;;AAkCA,IAAa,IAAe,EAAmC,KAAK;AAEpE,SAAgB,IAAyB;AACxC,QAAO,EAAkB,EAAW,EAAa,EAAE,eAAe"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xmachines/play-solid",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.52",
|
|
4
4
|
"description": "Solid renderer for XMachines Play architecture",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"catalog",
|
|
@@ -39,9 +39,9 @@
|
|
|
39
39
|
"prepublishOnly": "npm run build"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@xmachines/play": "1.0.0-beta.
|
|
43
|
-
"@xmachines/play-actor": "1.0.0-beta.
|
|
44
|
-
"@xmachines/play-signals": "1.0.0-beta.
|
|
42
|
+
"@xmachines/play": "1.0.0-beta.52",
|
|
43
|
+
"@xmachines/play-actor": "1.0.0-beta.52",
|
|
44
|
+
"@xmachines/play-signals": "1.0.0-beta.52"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@json-render/core": "^0.18.0",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"@solidjs/testing-library": "^0.8.10",
|
|
51
51
|
"@testing-library/jest-dom": "^6.9.1",
|
|
52
52
|
"@types/node": "^25.6.0",
|
|
53
|
-
"@xmachines/shared": "1.0.0-beta.
|
|
53
|
+
"@xmachines/shared": "1.0.0-beta.52",
|
|
54
54
|
"@xstate/store": "^3.17.0",
|
|
55
55
|
"jsdom": "^29.1.0",
|
|
56
56
|
"oxfmt": "^0.47.0",
|
|
@@ -69,5 +69,8 @@
|
|
|
69
69
|
"@xstate/store": "^3.17.0",
|
|
70
70
|
"solid-js": "^1.8.0",
|
|
71
71
|
"xstate": "^5.31.0"
|
|
72
|
+
},
|
|
73
|
+
"engines": {
|
|
74
|
+
"node": ">=22.0.0"
|
|
72
75
|
}
|
|
73
76
|
}
|