@c.a.f/infrastructure-react 1.0.2 → 1.0.3

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.
@@ -1,15 +1,20 @@
1
1
  import type { Ploc } from "@c.a.f/core";
2
+ /** Infers the state type S from a Ploc subclass P (P extends Ploc<S>) */
3
+ type PlocState<P> = P extends Ploc<infer S> ? S : never;
2
4
  /**
3
5
  * React hook that subscribes to a Ploc and returns the current state and the Ploc instance.
4
6
  * Handles subscription on mount, syncs when the ploc reference changes, and unsubscribes on unmount.
7
+ * The return type preserves the concrete ploc type (e.g. UserPloc) so methods like loadUsers() are typed.
5
8
  *
6
9
  * @param ploc - A Ploc instance (from @c.a.f/core)
7
- * @returns A tuple of [currentState, ploc]
10
+ * @returns A tuple of [currentState, ploc] with the same ploc type as passed in
8
11
  *
9
12
  * @example
10
13
  * ```tsx
11
14
  * const [state, userPloc] = usePloc(userPloc);
15
+ * await userPloc.loadUsers(); // typed correctly
12
16
  * return <span>{state.name}</span>;
13
17
  * ```
14
18
  */
15
- export declare function usePloc<T>(ploc: Ploc<T>): [T, Ploc<T>];
19
+ export declare function usePloc<P extends Ploc<PlocState<P>>>(ploc: P): [PlocState<P>, P];
20
+ export {};
@@ -2,13 +2,15 @@ import { useEffect, useState } from "react";
2
2
  /**
3
3
  * React hook that subscribes to a Ploc and returns the current state and the Ploc instance.
4
4
  * Handles subscription on mount, syncs when the ploc reference changes, and unsubscribes on unmount.
5
+ * The return type preserves the concrete ploc type (e.g. UserPloc) so methods like loadUsers() are typed.
5
6
  *
6
7
  * @param ploc - A Ploc instance (from @c.a.f/core)
7
- * @returns A tuple of [currentState, ploc]
8
+ * @returns A tuple of [currentState, ploc] with the same ploc type as passed in
8
9
  *
9
10
  * @example
10
11
  * ```tsx
11
12
  * const [state, userPloc] = usePloc(userPloc);
13
+ * await userPloc.loadUsers(); // typed correctly
12
14
  * return <span>{state.name}</span>;
13
15
  * ```
14
16
  */
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@c.a.f/infrastructure-react",
3
3
  "type": "module",
4
- "version": "1.0.2",
4
+ "version": "1.0.3",
5
5
  "description": "Clean Architecture Frontend (CAF) — React adapters: usePloc, useUseCase, CAFErrorBoundary, DevTools, useRouteManager, useRouteRepository.",
6
6
  "keywords": [
7
7
  "clean-architecture-frontend",