@xmachines/play-react 1.0.0-beta.8 → 1.0.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.
@@ -0,0 +1,73 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ /**
3
+ * PlayUIProvider — batteries-included composite provider for actor-driven UI rendering.
4
+ *
5
+ * Wraps ActorProvider + JSONUIProvider (from @xmachines/json-render-react) to provide a single
6
+ * entry point for all actor lifecycle and UI rendering concerns.
7
+ *
8
+ * Standard usage:
9
+ * ```tsx
10
+ * <PlayUIProvider actor={actor} registryResult={registryResult}>
11
+ * <PlayRenderer />
12
+ * </PlayUIProvider>
13
+ * ```
14
+ *
15
+ * For custom provider composition (escape hatch), use <ActorProvider> directly.
16
+ *
17
+ * @packageDocumentation
18
+ */
19
+ import React from "react";
20
+ import { JSONUIProvider } from "@xmachines/json-render-react";
21
+ import { ActorProvider, usePlayView } from "./ActorProvider.js";
22
+ /**
23
+ * Inner bridge component — reads ViewContext (usePlayView) to get the resolved handlers,
24
+ * registry, and store, then passes them to JSONUIProvider. The store is passed explicitly
25
+ * so JSONUIProvider's internal StateProvider uses the same store ActorProvider set up —
26
+ * without this, JSONUIProvider would create a fresh empty store, shadowing the seeded one.
27
+ *
28
+ * Must be inside ActorProvider's tree so usePlayView() has access to ViewContextValue.
29
+ */
30
+ function JSONUIBridge({ validationFunctions, navigate, functions, children, }) {
31
+ const view = usePlayView();
32
+ return (_jsx(JSONUIProvider, { registry: view.registry, handlers: view.handlers, store: view.store, ...(validationFunctions && { validationFunctions }), ...(navigate && { navigate }), ...(functions && { functions }), children: children }));
33
+ }
34
+ /**
35
+ * PlayUIProvider — batteries-included entry point for actor-driven UI rendering.
36
+ *
37
+ * Combines actor lifecycle management (ActorProvider) with full UI provider setup
38
+ * (JSONUIProvider including ActionProvider, ValidationProvider, VisibilityProvider,
39
+ * StateProvider, and ConfirmDialogManager).
40
+ *
41
+ * @example
42
+ * ```tsx
43
+ * import { PlayUIProvider, PlayRenderer } from "@xmachines/play-react";
44
+ *
45
+ * const registryResult = defineRegistry(catalog, {
46
+ * components: { Login, Dashboard },
47
+ * actions: {
48
+ * login: async ({ username }) => actor.send({ type: 'auth.login', username }),
49
+ * logout: async () => actor.send({ type: 'auth.logout' }),
50
+ * },
51
+ * });
52
+ *
53
+ * <PlayUIProvider actor={actor} registryResult={registryResult}>
54
+ * <PlayRenderer />
55
+ * </PlayUIProvider>
56
+ *
57
+ * // With JSONUIProvider options:
58
+ * <PlayUIProvider
59
+ * actor={actor}
60
+ * registryResult={registryResult}
61
+ * navigate={(path) => router.push(path)}
62
+ * validationFunctions={{ isEmail: (v) => /^.+@.+$/.test(String(v)) }}
63
+ * >
64
+ * <PlayRenderer />
65
+ * </PlayUIProvider>
66
+ * ```
67
+ *
68
+ * @public
69
+ */
70
+ export const PlayUIProvider = ({ validationFunctions, navigate, functions, ...actorProps }) => {
71
+ return (_jsx(ActorProvider, { ...actorProps, children: _jsx(JSONUIBridge, { ...(validationFunctions && { validationFunctions }), ...(navigate && { navigate }), ...(functions && { functions }), children: actorProps.children }) }));
72
+ };
73
+ //# sourceMappingURL=PlayUIProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PlayUIProvider.js","sourceRoot":"","sources":["../src/PlayUIProvider.tsx"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,cAAc,EAA4B,MAAM,8BAA8B,CAAC;AACxF,OAAO,EAAE,aAAa,EAAE,WAAW,EAA2B,MAAM,oBAAoB,CAAC;AAezF;;;;;;;GAOG;AACH,SAAS,YAAY,CAAC,EACrB,mBAAmB,EACnB,QAAQ,EACR,SAAS,EACT,QAAQ,GACuD;IAC/D,MAAM,IAAI,GAAG,WAAW,EAAE,CAAC;IAE3B,OAAO,CACN,KAAC,cAAc,IACd,QAAQ,EAAE,IAAI,CAAC,QAAQ,EACvB,QAAQ,EAAE,IAAI,CAAC,QAAQ,EACvB,KAAK,EAAE,IAAI,CAAC,KAAK,KACb,CAAC,mBAAmB,IAAI,EAAE,mBAAmB,EAAE,CAAC,KAChD,CAAC,QAAQ,IAAI,EAAE,QAAQ,EAAE,CAAC,KAC1B,CAAC,SAAS,IAAI,EAAE,SAAS,EAAE,CAAC,YAE/B,QAAQ,GACO,CACjB,CAAC;AACH,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,MAAM,CAAC,MAAM,cAAc,GAAkC,CAAC,EAC7D,mBAAmB,EACnB,QAAQ,EACR,SAAS,EACT,GAAG,UAAU,EACb,EAAE,EAAE;IACJ,OAAO,CACN,KAAC,aAAa,OAAK,UAAU,YAC5B,KAAC,YAAY,OACR,CAAC,mBAAmB,IAAI,EAAE,mBAAmB,EAAE,CAAC,KAChD,CAAC,QAAQ,IAAI,EAAE,QAAQ,EAAE,CAAC,KAC1B,CAAC,SAAS,IAAI,EAAE,SAAS,EAAE,CAAC,YAE/B,UAAU,CAAC,QAAQ,GACN,GACA,CAChB,CAAC;AACH,CAAC,CAAC"}
@@ -0,0 +1,23 @@
1
+ import { PlayError } from "@xmachines/play";
2
+ /**
3
+ * Error class for renderer-level errors in the Play architecture.
4
+ *
5
+ * **Note (Phase 29):** `PlayErrorBoundary.componentDidCatch()` no longer throws
6
+ * this error. Re-throwing from `componentDidCatch` can unmount the entire React 19
7
+ * root. `RendererError` is retained for programmatic use in custom error handlers
8
+ * and parent boundaries — it is no longer emitted by the built-in boundary itself.
9
+ *
10
+ * **Error code:** `PLAY_REACT_RENDER_ERROR`
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * import { RendererError } from "@xmachines/play-react/errors";
15
+ *
16
+ * // Create a RendererError programmatically in a custom boundary:
17
+ * throw new RendererError("Custom render failure", { cause: originalError });
18
+ * ```
19
+ */
20
+ export declare class RendererError extends PlayError {
21
+ constructor(message: string, options?: ErrorOptions);
22
+ }
23
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,aAAc,SAAQ,SAAS;gBAC/B,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY;CAInD"}
package/dist/errors.js ADDED
@@ -0,0 +1,26 @@
1
+ import { PlayError } from "@xmachines/play";
2
+ /**
3
+ * Error class for renderer-level errors in the Play architecture.
4
+ *
5
+ * **Note (Phase 29):** `PlayErrorBoundary.componentDidCatch()` no longer throws
6
+ * this error. Re-throwing from `componentDidCatch` can unmount the entire React 19
7
+ * root. `RendererError` is retained for programmatic use in custom error handlers
8
+ * and parent boundaries — it is no longer emitted by the built-in boundary itself.
9
+ *
10
+ * **Error code:** `PLAY_REACT_RENDER_ERROR`
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * import { RendererError } from "@xmachines/play-react/errors";
15
+ *
16
+ * // Create a RendererError programmatically in a custom boundary:
17
+ * throw new RendererError("Custom render failure", { cause: originalError });
18
+ * ```
19
+ */
20
+ export class RendererError extends PlayError {
21
+ constructor(message, options) {
22
+ super("PlayRenderer", "PLAY_REACT_RENDER_ERROR", message, options);
23
+ this.name = "RendererError";
24
+ }
25
+ }
26
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,OAAO,aAAc,SAAQ,SAAS;IAC3C,YAAY,OAAe,EAAE,OAAsB;QAClD,KAAK,CAAC,cAAc,EAAE,yBAAyB,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;QACnE,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;IAC7B,CAAC;CACD"}
package/dist/index.d.ts CHANGED
@@ -1,18 +1,46 @@
1
1
  /**
2
2
  * @xmachines/play-react - React renderer for XMachines Play architecture
3
3
  *
4
- * Provides a thin React rendering layer that passively observes actor signals
5
- * and renders UI components from catalog definitions. This package enables
4
+ * Provides a provider-based React rendering layer that passively observes actor signals
5
+ * and renders UI components via @xmachines/json-render-react. This package enables
6
6
  * framework-swappable architecture where React is just a rendering target
7
7
  * that subscribes to signal changes.
8
8
  *
9
9
  * **Key principle:** React state is NEVER used for business logic—only for
10
10
  * triggering React's render cycle. Signals are the source of truth.
11
11
  *
12
+ * **Standard usage:**
13
+ * ```tsx
14
+ * <PlayUIProvider actor={actor} registryResult={registryResult}>
15
+ * <PlayRenderer />
16
+ * </PlayUIProvider>
17
+ * ```
18
+ *
19
+ * **Escape hatch (custom composition):**
20
+ * ```tsx
21
+ * <ActorProvider actor={actor} registryResult={registryResult}>
22
+ * <JSONUIProvider registry={registryResult.registry}>
23
+ * <PlayRenderer />
24
+ * </JSONUIProvider>
25
+ * </ActorProvider>
26
+ * ```
27
+ *
12
28
  * @packageDocumentation
13
29
  * @module @xmachines/play-react
14
30
  */
15
31
  export { PlayRenderer } from "./PlayRenderer.js";
32
+ export { ActorProvider } from "./ActorProvider.js";
33
+ export type { ActorProviderProps, ViewContextValue } from "./ActorProvider.js";
34
+ export { usePlayView } from "./ActorProvider.js";
35
+ export { PlayUIProvider } from "./PlayUIProvider.js";
36
+ export type { PlayUIProviderProps } from "./PlayUIProvider.js";
16
37
  export { useSignalEffect } from "./useSignalEffect.js";
17
- export type { PlayRendererProps } from "./types.js";
38
+ export { PlayErrorBoundary } from "./PlayErrorBoundary.js";
39
+ export { useActor } from "./useActor.js";
40
+ export type { AnyPlayActor } from "./useActor.js";
41
+ export { defineRegistry, useBoundProp, JSONUIProvider, StateProvider, ActionProvider, VisibilityProvider, ValidationProvider, Renderer, } from "@xmachines/json-render-react";
42
+ export type { ComponentFn, ComponentContext, JSONUIProviderProps, StateProviderProps, ActionProviderProps, VisibilityProviderProps, ValidationProviderProps, RendererProps, } from "@xmachines/json-render-react";
43
+ export type { ActorProviderProps as PlayRendererProps } from "./ActorProvider.js";
44
+ export type { RenderErrorHandler } from "./types.js";
45
+ export type { PlayErrorBoundaryProps, PlayErrorBoundaryState } from "./PlayErrorBoundary.js";
18
46
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAGH,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAGvD,YAAY,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAGH,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,YAAY,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC/E,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,YAAY,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,YAAY,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAGlD,OAAO,EACN,cAAc,EACd,YAAY,EACZ,cAAc,EACd,aAAa,EACb,cAAc,EACd,kBAAkB,EAClB,kBAAkB,EAClB,QAAQ,GACR,MAAM,8BAA8B,CAAC;AACtC,YAAY,EACX,WAAW,EACX,gBAAgB,EAChB,mBAAmB,EACnB,kBAAkB,EAClB,mBAAmB,EACnB,uBAAuB,EACvB,uBAAuB,EACvB,aAAa,GACb,MAAM,8BAA8B,CAAC;AAGtC,YAAY,EAAE,kBAAkB,IAAI,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAClF,YAAY,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AACrD,YAAY,EAAE,sBAAsB,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC"}
package/dist/index.js CHANGED
@@ -1,18 +1,41 @@
1
1
  /**
2
2
  * @xmachines/play-react - React renderer for XMachines Play architecture
3
3
  *
4
- * Provides a thin React rendering layer that passively observes actor signals
5
- * and renders UI components from catalog definitions. This package enables
4
+ * Provides a provider-based React rendering layer that passively observes actor signals
5
+ * and renders UI components via @xmachines/json-render-react. This package enables
6
6
  * framework-swappable architecture where React is just a rendering target
7
7
  * that subscribes to signal changes.
8
8
  *
9
9
  * **Key principle:** React state is NEVER used for business logic—only for
10
10
  * triggering React's render cycle. Signals are the source of truth.
11
11
  *
12
+ * **Standard usage:**
13
+ * ```tsx
14
+ * <PlayUIProvider actor={actor} registryResult={registryResult}>
15
+ * <PlayRenderer />
16
+ * </PlayUIProvider>
17
+ * ```
18
+ *
19
+ * **Escape hatch (custom composition):**
20
+ * ```tsx
21
+ * <ActorProvider actor={actor} registryResult={registryResult}>
22
+ * <JSONUIProvider registry={registryResult.registry}>
23
+ * <PlayRenderer />
24
+ * </JSONUIProvider>
25
+ * </ActorProvider>
26
+ * ```
27
+ *
12
28
  * @packageDocumentation
13
29
  * @module @xmachines/play-react
14
30
  */
15
31
  // Main exports
16
32
  export { PlayRenderer } from "./PlayRenderer.js";
33
+ export { ActorProvider } from "./ActorProvider.js";
34
+ export { usePlayView } from "./ActorProvider.js";
35
+ export { PlayUIProvider } from "./PlayUIProvider.js";
17
36
  export { useSignalEffect } from "./useSignalEffect.js";
37
+ export { PlayErrorBoundary } from "./PlayErrorBoundary.js";
38
+ export { useActor } from "./useActor.js";
39
+ // Re-exports from @xmachines/json-render-react (per D-14)
40
+ export { defineRegistry, useBoundProp, JSONUIProvider, StateProvider, ActionProvider, VisibilityProvider, ValidationProvider, Renderer, } from "@xmachines/json-render-react";
18
41
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,eAAe;AACf,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,eAAe;AACf,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAGzC,0DAA0D;AAC1D,OAAO,EACN,cAAc,EACd,YAAY,EACZ,cAAc,EACd,aAAa,EACb,cAAc,EACd,kBAAkB,EAClB,kBAAkB,EAClB,QAAQ,GACR,MAAM,8BAA8B,CAAC"}
package/dist/types.d.ts CHANGED
@@ -1,24 +1,12 @@
1
1
  /**
2
2
  * TypeScript type definitions for play-react
3
3
  *
4
- * @packageDocumentation
5
- */
6
- import type { AbstractActor, Viewable } from "@xmachines/play-actor";
7
- import type React from "react";
8
- import type { AnyActorLogic } from "xstate";
9
- /**
10
- * Props for PlayRenderer component
4
+ * PlayRendererProps has been removed — use ActorProviderProps or PlayUIProviderProps instead.
5
+ * See ActorProvider.tsx and PlayUIProvider.tsx.
11
6
  *
12
- * @property actor - Actor instance with currentView signal (requires Viewable capability)
13
- * @property components - Map of component names to React components
14
- * @property fallback - Optional component shown when currentView is null
7
+ * @packageDocumentation
15
8
  */
16
- export interface PlayRendererProps {
17
- /** Actor instance with currentView signal (requires Viewable capability) */
18
- actor: AbstractActor<AnyActorLogic> & Viewable;
19
- /** Map of component names to React components */
20
- components: Record<string, React.ElementType>;
21
- /** Optional component shown when currentView is null */
22
- fallback?: React.ReactNode;
23
- }
9
+ export type { ActorProviderProps } from "./ActorProvider.js";
10
+ export type { PlayUIProviderProps } from "./PlayUIProvider.js";
11
+ export type { RenderErrorHandler } from "@xmachines/json-render-react";
24
12
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACrE,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAE5C;;;;;;GAMG;AACH,MAAM,WAAW,iBAAiB;IACjC,4EAA4E;IAC5E,KAAK,EAAE,aAAa,CAAC,aAAa,CAAC,GAAG,QAAQ,CAAC;IAE/C,iDAAiD;IACjD,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,WAAW,CAAC,CAAC;IAE9C,wDAAwD;IACxD,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,YAAY,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAC7D,YAAY,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC/D,YAAY,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC"}
package/dist/types.js CHANGED
@@ -1,6 +1,9 @@
1
1
  /**
2
2
  * TypeScript type definitions for play-react
3
3
  *
4
+ * PlayRendererProps has been removed — use ActorProviderProps or PlayUIProviderProps instead.
5
+ * See ActorProvider.tsx and PlayUIProvider.tsx.
6
+ *
4
7
  * @packageDocumentation
5
8
  */
6
9
  export {};
package/dist/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG"}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * useActor — React hook for accessing the raw actor inside a PlayRenderer tree.
3
+ *
4
+ * Components rendered inside PlayRenderer can call useActor() to get direct
5
+ * access to the actor instance without prop drilling.
6
+ *
7
+ * @throws {NonNullableError} If called outside an ActorProvider/PlayUIProvider tree
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * import { useActor } from "@xmachines/play-react";
12
+ *
13
+ * function MyComponent() {
14
+ * const actor = useActor();
15
+ * return <button onClick={() => actor.send({ type: "SUBMIT" })}>Submit</button>;
16
+ * }
17
+ * ```
18
+ *
19
+ * @packageDocumentation
20
+ */
21
+ import type { AbstractActor } from "@xmachines/play-actor";
22
+ import type { AnyActorLogic } from "xstate";
23
+ /** Bare actor type accepted by React context providers. For the full routing + view shape, use `PlayActor` from `@xmachines/play-router`. */
24
+ export type AnyPlayActor = AbstractActor<AnyActorLogic>;
25
+ export declare const ActorContext: import("react").Context<AnyPlayActor | null>;
26
+ export declare function useActor(): AnyPlayActor;
27
+ //# sourceMappingURL=useActor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useActor.d.ts","sourceRoot":"","sources":["../src/useActor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAIH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAE5C,6IAA6I;AAC7I,MAAM,MAAM,YAAY,GAAG,aAAa,CAAC,aAAa,CAAC,CAAC;AAExD,eAAO,MAAM,YAAY,8CAA2C,CAAC;AAErE,wBAAgB,QAAQ,IAAI,YAAY,CAEvC"}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * useActor — React hook for accessing the raw actor inside a PlayRenderer tree.
3
+ *
4
+ * Components rendered inside PlayRenderer can call useActor() to get direct
5
+ * access to the actor instance without prop drilling.
6
+ *
7
+ * @throws {NonNullableError} If called outside an ActorProvider/PlayUIProvider tree
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * import { useActor } from "@xmachines/play-react";
12
+ *
13
+ * function MyComponent() {
14
+ * const actor = useActor();
15
+ * return <button onClick={() => actor.send({ type: "SUBMIT" })}>Submit</button>;
16
+ * }
17
+ * ```
18
+ *
19
+ * @packageDocumentation
20
+ */
21
+ import { createContext, useContext } from "react";
22
+ import { assertNonNullable } from "@xmachines/play";
23
+ export const ActorContext = createContext(null);
24
+ export function useActor() {
25
+ return assertNonNullable(useContext(ActorContext), "ActorContext");
26
+ }
27
+ //# sourceMappingURL=useActor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useActor.js","sourceRoot":"","sources":["../src/useActor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAClD,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAOpD,MAAM,CAAC,MAAM,YAAY,GAAG,aAAa,CAAsB,IAAI,CAAC,CAAC;AAErE,MAAM,UAAU,QAAQ;IACvB,OAAO,iBAAiB,CAAC,UAAU,CAAC,YAAY,CAAC,EAAE,cAAc,CAAC,CAAC;AACpE,CAAC"}
@@ -3,35 +3,44 @@
3
3
  *
4
4
  * @packageDocumentation
5
5
  */
6
+ import type { DependencyList } from "react";
6
7
  /**
7
8
  * React hook that subscribes to signal changes and runs effect callback
8
9
  *
9
- * Wraps Signal.subtle.Watcher to automatically track signal dependencies
10
- * accessed in the callback. When any tracked signal changes, the callback
11
- * re-runs and React component re-renders.
10
+ * Wraps the callback in a Signal.Computed to automatically track signal
11
+ * dependencies accessed inside it, then delegates the watcher lifecycle
12
+ * (microtask batching, re-arming, disposal) to `watchSignal` from
13
+ * `@xmachines/play-signals` — the single canonical implementation shared
14
+ * across framework renderers.
12
15
  *
13
- * Architecture (per RESEARCH.md Pattern 3):
16
+ * Architecture:
14
17
  * - Uses Signal.Computed to wrap callback for automatic dependency tracking
15
- * - Signal.subtle.Watcher monitors the Computed for changes
18
+ * - watchSignal owns the Signal.subtle.Watcher lifecycle (Phase 29 memory safety)
16
19
  * - Microtask batching coalesces rapid signal updates
17
- * - Forces React re-render via useReducer when signals change
20
+ * - Re-rendering is driven by the callback's own setState (see remarks)
18
21
  * - Handles cleanup on unmount to prevent memory leaks
19
22
  *
20
23
  * Invariant: Signal-Only Reactivity - Signals accessed in callback are watched.
21
24
  * Invariant: Passive Infrastructure - React observes signals and does not control them.
22
25
  *
23
26
  * @param callback - Effect function that accesses signals. Can return cleanup function.
27
+ * @param deps - Optional dependency list (like useEffect). When any dependency
28
+ * changes, the watcher and Computed are torn down and recreated, re-tracking
29
+ * signals from scratch. Defaults to `[]` (subscribe once per mount). Pass this
30
+ * when the identity of the object whose signals you read can change over the
31
+ * component's lifetime (e.g. an `actor` prop) — otherwise the watcher keeps
32
+ * tracking the OLD object's signals forever.
24
33
  *
25
34
  * @example
26
35
  * ```typescript
27
36
  * const MyComponent = ({ actor }) => {
28
37
  * const [view, setView] = useState(null);
29
38
  *
30
- * // Subscribe to actor.currentView signal
39
+ * // Subscribe to actor.currentView signal; re-subscribe if the actor swaps
31
40
  * useSignalEffect(() => {
32
41
  * const currentView = actor.currentView.get();
33
42
  * setView(currentView);
34
- * });
43
+ * }, [actor]);
35
44
  *
36
45
  * return <div>{view?.component}</div>;
37
46
  * };
@@ -41,16 +50,22 @@
41
50
  * **CRITICAL:** Signals must be accessed unconditionally (no if statements).
42
51
  * Conditional signal access breaks automatic dependency tracking.
43
52
  *
44
- * **Performance:** Microtask batching (queueMicrotask) prevents React thrashing
45
- * when multiple signals update rapidly. Per signal-polyfill README pattern.
53
+ * **Performance:** Microtask batching (queueMicrotask, inside watchSignal)
54
+ * prevents React thrashing when multiple signals update rapidly.
46
55
  *
47
- * **Why forceUpdate:** React needs useState/useReducer to trigger re-render cycle.
48
- * Signal changes won't automatically re-render React components without forcing
49
- * update via state change.
56
+ * **Re-rendering:** the hook itself does NOT force a React render on signal
57
+ * change the callback drives re-rendering by calling setState with the new
58
+ * signal value (as in the example above). This lets React's setState bailout
59
+ * skip renders when the derived value is unchanged; an unconditional
60
+ * force-update here previously caused a wasted render per notification even
61
+ * when the callback's setState bailed. If you need to re-render on every
62
+ * notification while reading signals during render, mirror the signal value
63
+ * into React state inside the callback.
50
64
  *
51
65
  * **Implementation note:** We wrap the callback in Signal.Computed because
52
66
  * Signal.subtle.Watcher cannot automatically track arbitrary function calls.
53
- * The Computed handles dependency tracking, and the Watcher monitors it.
67
+ * The Computed handles dependency tracking; watchSignal evaluates it (which
68
+ * runs the callback) whenever any tracked signal changes.
54
69
  */
55
- export declare const useSignalEffect: (callback: () => void | (() => void)) => void;
70
+ export declare const useSignalEffect: (callback: () => void | (() => void), deps?: DependencyList) => void;
56
71
  //# sourceMappingURL=useSignalEffect.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useSignalEffect.d.ts","sourceRoot":"","sources":["../src/useSignalEffect.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAWH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AACH,eAAO,MAAM,eAAe,GAAI,UAAU,MAAM,IAAI,GAAG,CAAC,MAAM,IAAI,CAAC,KAAG,IAuDrE,CAAC"}
1
+ {"version":3,"file":"useSignalEffect.d.ts","sourceRoot":"","sources":["../src/useSignalEffect.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AAS5C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8DG;AACH,eAAO,MAAM,eAAe,GAC3B,UAAU,MAAM,IAAI,GAAG,CAAC,MAAM,IAAI,CAAC,EACnC,OAAM,cAAmB,KACvB,IA0CF,CAAC"}
@@ -3,8 +3,8 @@
3
3
  *
4
4
  * @packageDocumentation
5
5
  */
6
- import { useEffect, useReducer } from "react";
7
- import { Signal } from "@xmachines/play-signals";
6
+ import { useEffect, useRef } from "react";
7
+ import { Signal, watchSignal } from "@xmachines/play-signals";
8
8
  /**
9
9
  * Marker symbol returned by effect Computed to satisfy type requirements
10
10
  * The actual value doesn't matter - we only care about side effects
@@ -13,32 +13,40 @@ const EFFECT_RUN_MARKER = Symbol("effect-run");
13
13
  /**
14
14
  * React hook that subscribes to signal changes and runs effect callback
15
15
  *
16
- * Wraps Signal.subtle.Watcher to automatically track signal dependencies
17
- * accessed in the callback. When any tracked signal changes, the callback
18
- * re-runs and React component re-renders.
16
+ * Wraps the callback in a Signal.Computed to automatically track signal
17
+ * dependencies accessed inside it, then delegates the watcher lifecycle
18
+ * (microtask batching, re-arming, disposal) to `watchSignal` from
19
+ * `@xmachines/play-signals` — the single canonical implementation shared
20
+ * across framework renderers.
19
21
  *
20
- * Architecture (per RESEARCH.md Pattern 3):
22
+ * Architecture:
21
23
  * - Uses Signal.Computed to wrap callback for automatic dependency tracking
22
- * - Signal.subtle.Watcher monitors the Computed for changes
24
+ * - watchSignal owns the Signal.subtle.Watcher lifecycle (Phase 29 memory safety)
23
25
  * - Microtask batching coalesces rapid signal updates
24
- * - Forces React re-render via useReducer when signals change
26
+ * - Re-rendering is driven by the callback's own setState (see remarks)
25
27
  * - Handles cleanup on unmount to prevent memory leaks
26
28
  *
27
29
  * Invariant: Signal-Only Reactivity - Signals accessed in callback are watched.
28
30
  * Invariant: Passive Infrastructure - React observes signals and does not control them.
29
31
  *
30
32
  * @param callback - Effect function that accesses signals. Can return cleanup function.
33
+ * @param deps - Optional dependency list (like useEffect). When any dependency
34
+ * changes, the watcher and Computed are torn down and recreated, re-tracking
35
+ * signals from scratch. Defaults to `[]` (subscribe once per mount). Pass this
36
+ * when the identity of the object whose signals you read can change over the
37
+ * component's lifetime (e.g. an `actor` prop) — otherwise the watcher keeps
38
+ * tracking the OLD object's signals forever.
31
39
  *
32
40
  * @example
33
41
  * ```typescript
34
42
  * const MyComponent = ({ actor }) => {
35
43
  * const [view, setView] = useState(null);
36
44
  *
37
- * // Subscribe to actor.currentView signal
45
+ * // Subscribe to actor.currentView signal; re-subscribe if the actor swaps
38
46
  * useSignalEffect(() => {
39
47
  * const currentView = actor.currentView.get();
40
48
  * setView(currentView);
41
- * });
49
+ * }, [actor]);
42
50
  *
43
51
  * return <div>{view?.component}</div>;
44
52
  * };
@@ -48,60 +56,59 @@ const EFFECT_RUN_MARKER = Symbol("effect-run");
48
56
  * **CRITICAL:** Signals must be accessed unconditionally (no if statements).
49
57
  * Conditional signal access breaks automatic dependency tracking.
50
58
  *
51
- * **Performance:** Microtask batching (queueMicrotask) prevents React thrashing
52
- * when multiple signals update rapidly. Per signal-polyfill README pattern.
59
+ * **Performance:** Microtask batching (queueMicrotask, inside watchSignal)
60
+ * prevents React thrashing when multiple signals update rapidly.
53
61
  *
54
- * **Why forceUpdate:** React needs useState/useReducer to trigger re-render cycle.
55
- * Signal changes won't automatically re-render React components without forcing
56
- * update via state change.
62
+ * **Re-rendering:** the hook itself does NOT force a React render on signal
63
+ * change the callback drives re-rendering by calling setState with the new
64
+ * signal value (as in the example above). This lets React's setState bailout
65
+ * skip renders when the derived value is unchanged; an unconditional
66
+ * force-update here previously caused a wasted render per notification even
67
+ * when the callback's setState bailed. If you need to re-render on every
68
+ * notification while reading signals during render, mirror the signal value
69
+ * into React state inside the callback.
57
70
  *
58
71
  * **Implementation note:** We wrap the callback in Signal.Computed because
59
72
  * Signal.subtle.Watcher cannot automatically track arbitrary function calls.
60
- * The Computed handles dependency tracking, and the Watcher monitors it.
73
+ * The Computed handles dependency tracking; watchSignal evaluates it (which
74
+ * runs the callback) whenever any tracked signal changes.
61
75
  */
62
- export const useSignalEffect = (callback) => {
63
- // Force re-render when signal changes (React needs state change to re-render)
64
- const [, forceUpdate] = useReducer((x) => x + 1, 0);
76
+ export const useSignalEffect = (callback, deps = []) => {
77
+ // Store callback in a ref so the effect closure always calls the latest version
78
+ // WITHOUT triggering watcher teardown/re-setup on each render (standard React ref pattern)
79
+ const callbackRef = useRef(callback);
80
+ // Assignment outside useEffect keeps ref current without triggering re-effect
81
+ callbackRef.current = callback;
65
82
  useEffect(() => {
66
83
  let cleanup;
67
- let needsEnqueue = true;
68
84
  // Wrap callback in a Computed to automatically track dependencies
69
85
  // The Computed will re-evaluate when any accessed signal changes
70
86
  const effect = new Signal.Computed(() => {
71
87
  // Run cleanup from previous effect
72
- cleanup?.();
73
- // Run user callback (may access signals, return cleanup)
74
- cleanup = callback();
88
+ if (typeof cleanup === "function")
89
+ cleanup();
90
+ // Run user callback via ref (always latest version, no dep churn)
91
+ cleanup = callbackRef.current();
75
92
  // Return marker value (Computed requires a return value)
76
93
  return EFFECT_RUN_MARKER;
77
94
  });
78
- // Create watcher to detect when Computed needs re-evaluation
79
- const watcher = new Signal.subtle.Watcher(() => {
80
- // Batching flag prevents multiple microtasks for rapid changes
81
- if (needsEnqueue) {
82
- needsEnqueue = false;
83
- // Schedule microtask to batch updates (prevent React thrashing)
84
- queueMicrotask(() => {
85
- needsEnqueue = true;
86
- // Re-evaluate the Computed (runs callback with new signal values)
87
- effect.get();
88
- // Force React re-render
89
- forceUpdate();
90
- // Re-watch for next change
91
- watcher.watch();
92
- });
93
- }
94
- });
95
- // Watch the Computed signal
96
- watcher.watch(effect);
95
+ // watchSignal owns the watcher lifecycle: microtask batching, disposed
96
+ // guard, and re-arming after each notification (Phase 29 memory safety
97
+ // lives there single source of truth, no copy-pasted watcher code).
98
+ // Reading the Computed inside watchSignal re-evaluates it, which runs the
99
+ // user callback; re-rendering is the callback's job (setState), so no
100
+ // extra work is needed in onValue.
101
+ const unwatch = watchSignal(effect, () => { });
97
102
  // Initial run of callback (via Computed)
98
103
  effect.get();
99
- // Cleanup on unmount
104
+ // Cleanup on unmount or deps change
100
105
  return () => {
101
- cleanup?.();
102
- // Unwatch to stop receiving signal updates
103
- watcher.unwatch(effect);
106
+ // Stop receiving signal updates (idempotent, disposes pending microtasks)
107
+ unwatch();
108
+ if (typeof cleanup === "function")
109
+ cleanup();
104
110
  };
105
- }, [callback]);
111
+ // oxlint-disable-next-line exhaustive-deps -- deps forwarded from caller; callback intentionally excluded (ref pattern)
112
+ }, deps);
106
113
  };
107
114
  //# sourceMappingURL=useSignalEffect.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useSignalEffect.js","sourceRoot":"","sources":["../src/useSignalEffect.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAEjD;;;GAGG;AACH,MAAM,iBAAiB,GAAG,MAAM,CAAC,YAAY,CAAC,CAAC;AAE/C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,QAAm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