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 +42 -8
- package/dist/chunk-E3D6YEKB.mjs +877 -0
- package/dist/chunk-E3D6YEKB.mjs.map +1 -0
- package/dist/index.js +121 -73
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +84 -884
- package/dist/index.mjs.map +1 -1
- package/dist/integrations/zustand-production.d.mts +3 -0
- package/dist/integrations/zustand-production.d.ts +3 -0
- package/dist/integrations/zustand-production.js +31 -0
- package/dist/integrations/zustand-production.js.map +1 -0
- package/dist/integrations/zustand-production.mjs +6 -0
- package/dist/integrations/zustand-production.mjs.map +1 -0
- package/dist/integrations/zustand.d.mts +6 -0
- package/dist/integrations/zustand.d.ts +6 -0
- package/dist/integrations/zustand.js +893 -0
- package/dist/integrations/zustand.js.map +1 -0
- package/dist/integrations/zustand.mjs +33 -0
- package/dist/integrations/zustand.mjs.map +1 -0
- package/package.json +22 -3
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
|
-
##
|
|
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
|
|
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
|
|
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:**
|
|
123
|
-
* **Efficiency Score:** A
|
|
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⭐)** -
|
|
136
|
-
* **shadcn-admin (10k⭐)** - Detected redundant state pattern in viewport detection hooks. [**PR #274**](https://github.com/satnaing/shadcn-admin/pull/274) (
|
|
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**.
|
|
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
|
|