react-state-basis 0.6.0 → 0.6.2

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 CHANGED
@@ -28,6 +28,8 @@ npm i react-state-basis
28
28
  Add the plugin to your `vite.config.ts`. The Babel plugin auto-labels your hooks—you continue importing from `react` as normal.
29
29
 
30
30
  ```ts
31
+ import { defineConfig } from 'vite';
32
+ import react from '@vitejs/plugin-react';
31
33
  import { basis } from 'react-state-basis/vite';
32
34
 
33
35
  export default defineConfig({
@@ -87,7 +89,7 @@ Fix: Derive b during the render phase (remove effect) or wrap in useMemo.
87
89
 
88
90
  ---
89
91
 
90
- ## Visual Proof
92
+ ## HUD
91
93
 
92
94
  The optional HUD shows your **State Basis Matrix** in real-time. Purple pulses ($\Omega$) are Context anchors; Red pulses (!) are redundant shadows.
93
95
 
@@ -101,12 +103,12 @@ The optional HUD shows your **State Basis Matrix** in real-time. Purple pulses (
101
103
 
102
104
  ## What Basis Detects
103
105
 
104
- Basis uses **Graph Theory**, **Signal Processing**, and **Linear Algebra** to identify architectural violations that static linters miss:
106
+ Basis draws on ideas from graph theory, signal processing, and linear algebra to flag architectural issues static linters miss:
105
107
 
106
108
  - **⚡ Double Renders (Sync Leaks)** - Detects when a `useEffect` triggers a state update immediately after a render, forcing the browser to paint twice.
107
109
  - **⚡ Prime Movers (Root Causes)** - Ignores downstream symptoms and points you to the exact hook or event that started the chain reaction.
108
110
  - **⚡ Fragmented Updates** - Detects when a single click forces updates in multiple different files/contexts simultaneously (Tearing risk).
109
- - **Ω Context Mirroring** - Detects when you redundanty copy Global Context data into Local State (creating two sources of truth).
111
+ - **Ω Context Mirroring** - Detects when you redundantly copy Global Context data into Local State (creating two sources of truth).
110
112
  - **♊ Duplicate State** - Identifies variables that always update at the exact same time and should be merged (e.g. `isLoading` + `isSuccess`).
111
113
  - **🛑 Infinite Loops** - A safety circuit-breaker that kills the auditor before a recursive update freezes your browser.
112
114
 
@@ -119,8 +121,8 @@ Basis uses **Graph Theory**, **Signal Processing**, and **Linear Algebra** to id
119
121
  ### Architectural Health Report
120
122
  Check your entire app's state architecture by running `window.printBasisReport()` in the console.
121
123
 
122
- * **Refactor Priorities:** Uses **Spectral Influence** (Eigenvector Centrality) to rank bugs by their systemic impact. It tells you *what* to fix first.
123
- * **Efficiency Score:** A calculated percentage of how "clean" your architecture is (Sources of Truth - Causal Leaks).
124
+ * **Refactor Priorities:** Ranks issues with eigenvector centrality on the update graph so you can see which hook or event fans out the most.
125
+ * **Efficiency Score:** A rough ratio of independent update sources vs effect-driven follow-up updates. Diagnostic, not a grade.
124
126
  * **Sync Issues:** Groups entangled variables into clusters (e.g., Boolean Explosions).
125
127
 
126
128
  ### Hardware Telemetry
@@ -132,8 +134,40 @@ Verify engine efficiency and heap stability in real-time via `window.getBasisMet
132
134
 
133
135
  Basis is verified against industry-standard codebases to ensure high-fidelity detection:
134
136
 
135
- * **Excalidraw (114k⭐)** - Caught a theme-sync leak forcing a double-render on every toggle. [**PR #10637**](https://github.com/excalidraw/excalidraw/pull/10637)
136
- * **shadcn-admin (10k⭐)** - Detected redundant state pattern in viewport detection hooks. [**PR #274**](https://github.com/satnaing/shadcn-admin/pull/274) (MERGED)
137
+ * **Excalidraw (114k⭐)** - Proposed a theme-sync fix [**PR #10637**](https://github.com/excalidraw/excalidraw/pull/10637) (not merged)
138
+ * **shadcn-admin (10k⭐)** - Detected redundant state pattern in viewport detection hooks. [**PR #274**](https://github.com/satnaing/shadcn-admin/pull/274) (merged)
139
+
140
+ ---
141
+
142
+ ## Integrations
143
+
144
+ ### Zustand
145
+
146
+ Wrap your store with `basisLogger` to give Basis visibility into external
147
+ store updates. Store signals appear as Σ in the HUD and health report.
148
+
149
+ ```typescript
150
+ import { create } from 'zustand';
151
+ import { basisLogger } from 'react-state-basis/zustand';
152
+
153
+ export const useStore = create(
154
+ basisLogger((set) => ({
155
+ theme: 'light',
156
+ toggleTheme: () => set((state) => ({
157
+ theme: state.theme === 'light' ? 'dark' : 'light'
158
+ })),
159
+ }), 'MyStore')
160
+ );
161
+ ```
162
+
163
+ This enables detection of **Store Mirroring**, **Store Sync Leaks**, and
164
+ **Global Event Fragmentation** across React and Zustand state simultaneously.
165
+
166
+ [See full Zustand example →](./examples/basis-zustand/)
167
+
168
+ ### More integrations coming
169
+
170
+ Planned: XState, React Query, Redux Toolkit. Community PRs welcome.
137
171
 
138
172
  ---
139
173
 
@@ -149,7 +183,7 @@ Basis is verified against industry-standard codebases to ensure high-fidelity de
149
183
 
150
184
  ## Documentation & Theory
151
185
 
152
- Basis is built on heuristics inspired by **Signal Processing**, **Linear Algebra**, and **Graph Theory**. To understand the underlying math, visit the [**Full Wiki**](https://github.com/liovic/react-state-basis/wiki).
186
+ Basis is built on heuristics inspired by **Signal Processing**, **Linear Algebra**, and **Graph Theory**. [**The wiki**](https://github.com/liovic/react-state-basis/wiki) explains the mental model and the engine. It is a heuristic, not a proof.
153
187
 
154
188
  ---
155
189