react-state-custom 1.0.19 → 1.0.20

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,42 @@
1
+ ## Project Snapshot
2
+ - `react-state-custom` is a hook-first state management library; entrypoint `src/index.ts` re-exports context factories and subscription hooks.
3
+ - TypeScript only; consumers are expected to be React 19 apps (see `package.json` peerDependencies).
4
+ - Library build artifacts live in `dist/`; all source utilities reside under `src/state-utils/`.
5
+
6
+ ## Context Core
7
+ - `Context` (`src/state-utils/ctx.ts`) extends `EventTarget`; `data` stores the latest values and `publish` fires per-key DOM events when a loose `!=` comparison detects change.
8
+ - `getContext` memoizes by context name; `useDataContext(name)` memoizes the lookup via React `useMemo`.
9
+ - `useDataSource`/`useDataSourceMultiple` publish new values and register keys in `ctx.registry`; duplicate sources log via `useRegistryChecker`.
10
+
11
+ ## Root Contexts
12
+ - `createRootCtx(name, useFn)` (`src/state-utils/createRootCtx.tsx`) wraps your hook (`useFn`) in a hidden `Root` component that pushes its result into a derived context namespace.
13
+ - Context names come from `name` plus sorted prop key/value pairs; keep props serializable and stable to avoid collisions.
14
+ - `ctxMountedCheck` blocks multiple `Root` instances for the same name; duplicates throw with the original call stack.
15
+ - Use `useCtxStateStrict` to hard-fail when the `Root` is missing, or `useCtxState` to surface a delayed console error instead.
16
+
17
+ ## Auto Context Lifecycle
18
+ - `AutoRootCtx` (`src/state-utils/createAutoCtx.tsx`) maintains a global `'auto-ctx'` context exposing `subscribe(Root, params)` and reference counts for each instance.
19
+ - Mount `<AutoRootCtx Wrapper={YourErrorBoundary}>` once near the app root; it renders requested `Root` components inside the optional wrapper.
20
+ - `createAutoCtx(rootCtx, unmountTime?)` returns `useCtxState(params)` that subscribes through `'auto-ctx'` and hands back `useDataContext` for the resolved name.
21
+ - Multiple callers with identical params share a single `Root`; `unmountTime` delays teardown to absorb rapid mount/unmount cycles.
22
+
23
+ ## Subscription Patterns
24
+ - `useDataSourceMultiple(ctx, ...entries)` expects stable `[key, value]` tuples; internal `useArrayHash` hashes length and reference equality only.
25
+ - Use `useDataSubscribe(ctx, key, debounceMs)` or `useDataSubscribeMultiple(ctx, ...keys)` for keyed reads; debounce variants batch updates when values bounce.
26
+ - `useDataSubscribeWithTransform` recomputes the transformed shape only on change; memoize the `transform` fn to avoid churn.
27
+ - `useQuickSubscribe(ctx)` returns a proxy over `ctx.data`; destructure needed fields immediately during render and avoid storing the proxy for later use.
28
+
29
+ ## Utilities and Gotchas
30
+ - Value comparisons are shallow; mutate objects before republishing or provide new references so `publish` sees changes.
31
+ - `useArrayHash`/`useObjectHash` generate random hashes when array/object shape changes; they do not deep-compare nested content.
32
+ - The reserved `'auto-ctx'` namespace powers `AutoRootCtx`; do not manually reuse this context name.
33
+
34
+ ## Build and Tooling
35
+ - `yarn build` runs Vite with `@vitejs/plugin-react`, `vite-plugin-dts`, and `vite-bundle-analyzer`; the analyzer spins up a server after builds—stop it in CI if unused.
36
+ - `yarn dev` starts the Vite dev server on port 3000; useful for manual inspection of bundle output.
37
+ - Tests are stubbed (`yarn test` exits 0 after printing "No tests specified"); add coverage before depending on test gates.
38
+ - Repo is Yarn 4 (PnP); if editors struggle with module resolution, run `./fix-vscode-yarn-pnp.sh`.
39
+
40
+ ## Reference Docs
41
+ - README (`README.md`) offers narrative examples and positioning.
42
+ - API reference (`API_DOCUMENTATION.md`) documents every export; update alongside code changes.
@@ -0,0 +1,4 @@
1
+ export declare const DevToolContainer: ({ toggleButton, ...props }: {
2
+ [x: string]: any;
3
+ toggleButton?: string | undefined;
4
+ }) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,11 @@
1
+ import { default as React } from 'react';
2
+ export declare const DevToolState: ({}: {}) => import("react/jsx-runtime").JSX.Element;
3
+ export declare const StateView: React.FC<{
4
+ dataKey: string;
5
+ }>;
6
+ export declare const JSONView: React.FC<{
7
+ value: any;
8
+ name?: string;
9
+ style?: any;
10
+ expandLevel?: number | boolean;
11
+ }>;
package/dist/Test.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare const Test: ({}: {}) => import("react/jsx-runtime").JSX.Element;
package/dist/dev.d.ts ADDED
@@ -0,0 +1 @@
1
+ export {};
package/dist/index.d.ts CHANGED
@@ -3,3 +3,4 @@ export { createRootCtx } from './state-utils/createRootCtx';
3
3
  export { AutoRootCtx, createAutoCtx } from './state-utils/createAutoCtx';
4
4
  export { useArrayHash } from './state-utils/useArrayHash';
5
5
  export { useQuickSubscribe } from './state-utils/useQuickSubscribe';
6
+ export { DevToolContainer } from './DevTool';