react-state-basis 0.1.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Petar Liovic
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,395 @@
1
+ [![npm version](https://badge.fury.io/js/react-state-basis.svg)](https://www.npmjs.com/package/react-state-basis)
2
+
3
+ # πŸ“ REACT-STATE-BASIS
4
+ ### **Behavioral State Analysis for React**
5
+
6
+ It observes how state variables change over time to identify strong correlations that indicate architectural redundancy.
7
+
8
+ ---
9
+
10
+ **TL;DR:**
11
+ React-State-Basis watches your state like a mathematician: every `useState`, `useReducer`, and even `useEffect`-driven update becomes a tracked signal that turns into a time-series vector. When two signals move identically over time, they're collinear (redundant) - and Basis instantly flags it with location, math details, and a copy-paste refactor to derived state.
12
+
13
+ ---
14
+
15
+ **React-State-Basis** is a real-time architectural auditing engine that treats a React application as a **dynamic system of discrete-time vectors**. Instead of static linting, which only analyzes syntax, Basis monitors the **State Space Topology** of your application to detect mathematical redundancy (collinearity) and synchronization anti-patterns in real-time.
16
+
17
+ Inspired by the work of **Sheldon Axler** (*"Linear Algebra Done Right"*), Basis aims to enforce a mathematically optimal "Source of Truth" by ensuring your application state forms a **Basis**.
18
+
19
+ ---
20
+
21
+ ## 🧠 The Philosophy: State as a Vector Space
22
+
23
+ In a perfectly architected application, every state variable should represent a **unique dimension of information**.
24
+
25
+ Mathematically, your state variables $\{v_1, v_2, \dots, v_n\}$ should form a **Basis** for your application's state space $V$. A Basis must be **linearly independent**. If two variables update in perfect synchronization, they are **collinear** (linearly dependent). This creates:
26
+ 1. **Redundant Renders:** Multiple cycles for a single logical change.
27
+ 2. **State Desynchronization:** High risk of "impossible states" (e.g., `user` exists but `isLoggedIn` is false).
28
+ 3. **Architectural Entropy:** High cognitive load in tracing data causality.
29
+
30
+ ---
31
+ ## πŸš€ See It In Action
32
+
33
+ > ### πŸ’‘ Detecting Causal Links & Double Renders
34
+ ![alt text](./example/screenshots/causal.gif)
35
+
36
+ **The Problem:** Manually syncing `fahrenheit` via `useEffect` creates a "Double Render Cycle" (React renders once for Celsius, then again for Fahrenheit).
37
+
38
+ **The Basis Solution:** Basis identifies this sequential dependency in real-time. It flags the `Causal Link` and provides a copy-paste refactor to move from expensive state synchronization to a pure **Mathematical Projection** (`useMemo`).
39
+
40
+ > ### πŸ•ΈοΈ Identifying Boolean Entanglement
41
+ ![alt text](./example/screenshots/booleanEntanglement.gif)
42
+
43
+ **The Problem:** Using multiple boolean flags (`isLoading`, `isSuccess`, `hasData`) often leads to "impossible states" and redundant updates.
44
+
45
+ **The Basis Discovery:** Even though these are separate variables, Basis monitors their transition vectors and detects they are **perfectly synchronized**.
46
+
47
+ **The Insight:** It flags a **Dimension Collapse**, alerting you that 3 independent state variables are actually spanning only 1 dimension of information. It suggests consolidating them into a single state machine or a status string.
48
+
49
+ > ### πŸ›‘ Circuit Breaker (Infinite Loop Protection)
50
+ ![Infinite Loop GIF](./example/screenshots/infiniteLoopTrap.gif)
51
+
52
+ **The Trap:** A recursive `useEffect` that triggers an infinite state oscillation, a common mistake that usually freezes the browser's main thread.
53
+
54
+ **The Intervention:** Basis acts as a real-time stability monitor. If it detects a high-frequency state oscillation (e.g., 25 updates within 500ms), it automatically activates the **Circuit Breaker**.
55
+
56
+ **The Result:** The engine forcefully halts the update chain before the browser locks up. It provides a critical diagnostic report with the exact location of the loop, allowing you to fix the bug without having to kill the browser process.
57
+
58
+ > ### 🌐 Cross-Context Dependency Audit
59
+ ![Cross-Context Sync GIF](./example/screenshots/initiateGlobalSync.gif)
60
+
61
+ **The Scenario:** Modern apps often split state into multiple providers (e.g., `AuthContext` and `ThemeContext`). While architecturally decoupled, they are often **manually synchronized** in logic (e.g., switching to "dark theme" every time a user logs in).
62
+
63
+ **The Global Discovery:** Basis performs a **Global State Space Audit**. It doesn't care where your state lives in the component tree; it only cares about the **temporal signals**.
64
+
65
+ **The Insight:** By initiating a "Global Sync," Basis identifies that `user` and `theme` are moving in perfect synchronization. It exposes **hidden coupling** between disparate parts of your architecture.
66
+
67
+ **The Benefit:** This helps architects identify states that should potentially be merged or derived from a single source of truth, even when they are physically separated across different providers.
68
+
69
+ > ### πŸ“Š System Health & Structural Audit
70
+ ![System Health Report](./example/screenshots/systemHealthReport.gif)
71
+
72
+ **System Rank & Efficiency:** Basis performs a global audit of your state space to calculate its **Mathematical Rank**β€”the actual number of independent information dimensions. An efficiency of **40% (Rank: 4/10)** warns you that 60% of your state is mathematically redundant.
73
+
74
+ **Redundancy Clusters:** Instead of a raw matrix, Basis automatically groups "entangled" variables into **Redundancy Clusters**. Whether they are booleans in a single component or states across different contexts, Basis identifies them as a single, collapsed dimension if they move in perfect sync.
75
+
76
+ **Cross-Context Discovery:** The report exposes hidden dependencies across your entire tree (e.g., identifying that `theme` in one context is perfectly correlated with `user` in another).
77
+
78
+ **Architectural KPI:** Use the **Efficiency Score** as a real-time health metric. Your goal is to reach **100% Efficiency**, where every state variable in your application is linearly independent and serves as a true "Source of Truth."
79
+
80
+ Try the full interactive demo here: [/example](./example)
81
+
82
+ ---
83
+
84
+ ## How react-state-basis is different from existing tools
85
+
86
+ There are many great tools for React state management and debugging. Basis doesn't try to replace them - it solves a very specific pain point that most of them don't address directly: detecting behavioral redundancy at runtime (when two or more states always change together, even if they contain different values).
87
+
88
+ Here's a quick comparison:
89
+
90
+ | Tool / Approach | Static analysis | Runtime behavior tracking | Detects temporal synchronization | Gives refactor suggestions | Overhead in production | Focus on mathematical independence |
91
+ |----------------------------------|-----------------|----------------------------|----------------------------------|----------------------------|------------------------|-------------------------------------|
92
+ | ESLint + plugins (no-redundant-state, etc.) | βœ… | ❌ | ❌ | Partial (rules only) | None | ❌ |
93
+ | React DevTools | ❌ | Partial (component tree) | ❌ | No | Low | ❌ |
94
+ | Why Did You Render | ❌ | βœ… (render tracking) | Partial (render causes) | No | Removable | ❌ |
95
+ | Redux/Zustand DevTools | ❌ | βœ… (store changes) | ❌ (only store level) | No | Removable | ❌ |
96
+ | react-state-basis (Basis) | Partial (Babel) | βœ… | βœ… (tick-based sync detection) | βœ… (copy-paste useMemo) | Zero (change imports) | βœ… (inspired by linear algebra) |
97
+
98
+ Basis shines when:
99
+ - You have manual state syncing (`setA β†’ setB` in effects/onClick/etc.)
100
+ - Multiple booleans or flags that are always updated together
101
+ - You want to know which state is the true "source of truth" without guessing
102
+ - You want runtime insights that linters can't see (because they don't run the code)
103
+
104
+ It is not trying to be a full state manager, linter replacement, or performance profiler.
105
+ It is a specialized diagnostic tool for one very common anti-pattern - and it tries to do that one thing really well.
106
+
107
+
108
+ ---
109
+
110
+ ## πŸš€ Setup & Integration
111
+
112
+ To enable the mathematical monitoring of your application, follow these two steps:
113
+
114
+ ### 1. Initialize the Basis Monitor
115
+ Wrap your application root (e.g., `main.tsx` or `App.tsx`) with the `BasisProvider`. Setting `debug={true}` enables the real-time diagnostic dashboard and the visual system status monitor.
116
+
117
+ ```tsx
118
+ import { BasisProvider } from 'react-state-basis';
119
+
120
+ export default function Root() {
121
+ return (
122
+ <BasisProvider debug={true}>
123
+ <App />
124
+ </BasisProvider>
125
+ );
126
+ }
127
+ ```
128
+
129
+ ### 2. Use Drop-in Replacement Imports
130
+ Replace your standard React hook imports with `react-state-basis`. This allows the engine to instrument your state updates without changing your component logic.
131
+
132
+ ```tsx
133
+ // ❌ Change this:
134
+ // import { useState, useEffect } from 'react';
135
+
136
+ // βœ… To this:
137
+ import { useState, useEffect, useMemo, useContext } from 'react-state-basis';
138
+
139
+ function MyComponent() {
140
+ const [data, setData] = useState([]); // Automatically vectorized and tracked
141
+ }
142
+ ```
143
+
144
+ > Note: React-State-Basis includes an optional Babel plugin that automatically labels state variables for richer diagnostics.
145
+
146
+
147
+ ---
148
+
149
+ ## πŸ•΅οΈβ€β™‚οΈ Technical Architecture
150
+
151
+ React-State-Basis utilizes a three-tier instrumentation pipeline to audit your system:
152
+
153
+ ### 1. The Compiler Layer (Babel AST)
154
+ A build-time plugin performs static analysis, injecting the **filename** and **variable name** directly into the runtime calls. This transforms an anonymous execution graph into a **structured state map**.
155
+
156
+ ### 2. The Runtime Layer (Signal Mapping)
157
+ Every state transition is intercepted. Basis groups updates occurring within a **16ms window** into a single "System Tick." Each state variable is mapped to a vector in $\mathbb{R}^{50}$.
158
+ * `1` = State transition occurred in this tick.
159
+ * `0` = State remained stagnant.
160
+
161
+ React-State-Basis does not compare state values. It analyzes the timing and synchronization of updates, treating each state variable as a discrete activation signal over time.
162
+
163
+ ### 3. The Analysis Layer (The Heuristic)
164
+ In pure Linear Algebra, proving linear independence for $N$ variables requires solving the system $a_1v_1 + \dots + a_nv_n = 0$. Using algorithms like Gaussian elimination or SVD to determine the **Rank** of the state matrix has a computational complexity of $O(N^3)$. Running this in a browser runtime for every state update would be prohibitively expensive.
165
+
166
+ To maintain real-time performance, React-State-Basis uses **Cosine Similarity** as a high-speed heuristic ($O(D)$, where $D$ is the vector dimension) to detect **pairwise collinearity**:
167
+
168
+ $$ \text{similarity} = \cos(\theta) = \frac{\mathbf{A} \cdot \mathbf{B}}{\Vert \mathbf{A} \Vert \Vert \mathbf{B} \Vert} $$
169
+
170
+ If $\cos(\theta) \approx 1.00$, the vectors are collinear (linearly dependent), and the engine triggers a redundancy alert.
171
+
172
+ ---
173
+
174
+ ## πŸ“ Real-World Demonstration: The Auth Anti-Pattern
175
+
176
+ Developers often manually sync related states, creating a redundant dimension in the Basis:
177
+
178
+ ### ❌ Redundant Basis (State Bloat)
179
+ ```tsx
180
+ const [user, setUser] = useState(null);
181
+ const [isLogged, setIsLogged] = useState(false);
182
+
183
+ const onLogin = (userData) => {
184
+ setUser(userData);
185
+ setIsLogged(true); // ⚠️ BASIS ALERT: Always updated in sync with 'user'
186
+ };
187
+ ```
188
+ **Engine Analysis:** The Engine calculates that `user` and `isLogged` are perfectly synchronized. It warns you that you are using two dimensions to describe a 1D problem.
189
+
190
+ ### βœ… Independent Basis (Optimal Design)
191
+ Basis suggests a **Projection**-transforming a basis vector into a derived value.
192
+ ```tsx
193
+ const [user, setUser] = useState(null);
194
+ const isLogged = useMemo(() => !!user, [user]); // Mathematically clean
195
+ ```
196
+
197
+ ---
198
+
199
+ ## πŸ–₯️ Diagnostic Dashboard
200
+
201
+ Basis provides high-end diagnostic feedback directly in your browser console:
202
+
203
+ * **πŸ“ Location Tracking:** Identifies exact files and variable names causing redundancy.
204
+ * **πŸ› οΈ Refactor Snippets:** Provides dark-themed code blocks you can copy-paste to fix your state architecture.
205
+ * **πŸ“Š Health Matrix:** Call `printBasisReport()` to see your **Efficiency Score** and the full **Correlation Matrix** of your application.
206
+
207
+ ---
208
+
209
+ ## ✨ Key Features
210
+
211
+ * **πŸ•΅οΈβ€β™‚οΈ Content-Agnostic:** Identifies logical links through temporal synchronization, not data types.
212
+ * **πŸ›‘οΈ Circuit Breaker:** Halts high-frequency state oscillations (Infinite Loops) to protect the browser thread.
213
+ * **πŸ’‘ Causal Detective:** Tracks causality chains from `useEffect` to `useState` to identify cascading renders.
214
+ * **πŸ”„ Zero Lock-in:** Simply point your imports back to `'react'` in production. Basis is a **Development-time verification infrastructure**.
215
+
216
+ ---
217
+
218
+ ## πŸŽ“ Mathematical Inspiration
219
+
220
+ ### πŸ“œ The Basis Theorem
221
+ According to Axler (*Linear Algebra Done Right, Definition 2.27*):
222
+
223
+ > A **basis** of $V$ is a list of vectors in $V$ that is **linearly independent** and **spans** $V$.
224
+
225
+ To satisfy this theorem in the context of application state:
226
+
227
+ 1. **Linear Independence:** No state variable in the list can be expressed as a linear combination of the others. If a state $v_n$ can be derived from $\{v_1, \dots, v_{n-1}\}$, the list is linearly dependent and contains redundancy.
228
+ 2. **Spanning the Space:** The list of state variables must contain enough information to represent every possible configuration of the user interface.
229
+
230
+ React-State-Basis ensures that your state list is a true Basis by identifying and flagging vectors that fail the test of linear independence.
231
+
232
+ > *"Linear algebra is the study of linear maps on finite-dimensional vector spaces."*
233
+ > - **Sheldon Axler**
234
+
235
+ React-State-Basis bridges the gap between abstract algebra and UI engineering.
236
+ By ensuring your application state forms an independent, non-redundant basis, it helps you build software that is inherently more stable, efficient, and easier to reason about.
237
+ ---
238
+
239
+ ### πŸ“œ Implementation of the Linear Dependency Lemma
240
+ According to Axler (*Lemma 2.21*), in a linearly dependent **list** of vectors, there exists an index $j$ such that $v_j$ is in the span of the **preceding** vectors ($v_1, \dots, v_{j-1}$).
241
+
242
+ **React-State-Basis** implements this sequential logic to audit your state:
243
+
244
+ 1. **The Ordered List:** Every state variable is treated as an element in an ordered list $(v_1, v_2, \dots, v_n)$ based on its registration order in the application.
245
+ 2. **Sequential Discovery:** As time progresses, the engine monitors the list. It doesn't just look for "similar" vectors; it looks for vectors that **fail to add a new dimension** to the subspace generated by the vectors that came before them.
246
+ 3. **Identifying the Redundant Element:** If $v_{isLogged}$ is perfectly correlated with $v_{user}$, the engine identifies that $v_{isLogged} \in \text{span}(v_{user})$. Since $v_{user}$ preceded it, $v_{isLogged}$ is mathematically the redundant element.
247
+ 4. **Basis Reduction:** Following the lemma's second conclusion, the engine advises removing $v_j$, proving that the "information span" of your app remains identical while the complexity of the Basis decreases.
248
+
249
+ ---
250
+
251
+ ## ⚠️ Design Constraints & Heuristics
252
+
253
+ React-State-Basis uses probabilistic, time-windowed heuristics to approximate linear dependence.
254
+ As with any runtime analysis:
255
+
256
+ - Rarely-updated states may appear correlated by chance
257
+ - High-frequency UI interactions may trigger conservative warnings
258
+ - Results are advisory, not prescriptive
259
+
260
+ React-State-Basis is designed to **surface architectural questions**, not enforce correctness.
261
+
262
+ ---
263
+
264
+ ## ❓ Frequently Asked Questions
265
+
266
+ ### **Is React-State-Basis a replacement for React DevTools or linters?**
267
+ No.
268
+
269
+ React-State-Basis complements existing tools.
270
+ Linters analyze **code structure**, and React DevTools show **component behavior**. React-State-Basis analyzes **state relationships over time**-something neither tool is designed to detect.
271
+
272
+ It answers questions like:
273
+ - *β€œWhy do these two states always change together?”*
274
+ - *β€œWhich state is the true source of truth?”*
275
+ - *β€œAm I manually synchronizing derived data?”*
276
+
277
+ ---
278
+
279
+ ### **Does this change React behavior or execution order?**
280
+ No.
281
+
282
+ React-State-Basis **does not modify React’s scheduling, rendering, or reconciliation**.
283
+ It observes state updates at runtime and logs diagnostics during development.
284
+
285
+ Removing React-State-Basis restores your application to standard React behavior with no residual effects.
286
+
287
+ ---
288
+
289
+ ### **Is this safe to use in production?**
290
+ React-State-Basis is designed for **development-time analysis**.
291
+
292
+ While it is technically safe to run in production, it:
293
+ - adds runtime overhead
294
+ - logs diagnostic output
295
+ - performs continuous analysis
296
+
297
+ For production builds, simply switch your imports back to `'react'`.
298
+
299
+ ---
300
+
301
+ ### **How accurate is the redundancy detection?**
302
+ React-State-Basis uses **time-windowed behavioral analysis**, not formal proofs.
303
+
304
+ This means:
305
+ - Strong, consistent correlations are highly reliable indicators of redundancy
306
+ - Rare or coincidental correlations may trigger conservative warnings
307
+
308
+ All results are **advisory** and should be interpreted as architectural signals, not errors.
309
+
310
+ ---
311
+
312
+ ### **Can this detect all redundant state?**
313
+ No-and that’s intentional.
314
+
315
+ React-State-Basis detects **behavioral redundancy**, not semantic equivalence.
316
+ Two states may contain the same *data* but update independently, which is architecturally valid.
317
+
318
+ React-State-Basis only flags redundancy when two states behave as a single information dimension over time.
319
+
320
+ ---
321
+
322
+ ### **Why not just use selectors or derived state manually?**
323
+ You should-and React-State-Basis encourages that.
324
+
325
+ The challenge is *finding* where derived state should exist in large or evolving codebases. React-State-Basis helps identify:
326
+ - state that should be derived
327
+ - state that is unintentionally synchronized
328
+ - state that adds no new information
329
+
330
+ It surfaces opportunities for refactoring, not rules you must follow.
331
+
332
+ ---
333
+
334
+ ### **Does this work with Redux, Zustand, or other state managers?**
335
+ React-State-Basis currently instruments **React hooks directly**.
336
+
337
+ However, the underlying model is store-agnostic. Any system with:
338
+ - discrete state updates
339
+ - identifiable update points
340
+ - consistent labeling
341
+
342
+ could theoretically be analyzed using the same approach.
343
+
344
+ ---
345
+
346
+ ### **What about performance?**
347
+ React-State-Basis is optimized for real-time use in development.
348
+
349
+ Key design choices:
350
+ - Fixed-size sliding windows
351
+ - O(D) similarity checks
352
+ - Batched analysis every N ticks
353
+
354
+ For typical applications, overhead is negligible. For extremely high-frequency updates (e.g., animations), React-State-Basis may emit conservative warnings.
355
+
356
+ ---
357
+
358
+ ### **Is this β€œformal verification”?**
359
+ No.
360
+
361
+ React-State-Basis performs **runtime architectural auditing**, not formal mathematical verification.
362
+ It applies concepts from linear algebra to **observe and analyze behavior**, not to prove correctness.
363
+
364
+ ---
365
+
366
+ ### **Who is this tool for?**
367
+ React-State-Basis is best suited for:
368
+ - Medium to large React applications
369
+ - Codebases with complex state interactions
370
+ - Engineers debugging synchronization bugs
371
+ - Teams prioritizing architectural clarity
372
+
373
+ It may be unnecessary for small or short-lived projects.
374
+
375
+ ---
376
+
377
+ ### **Why linear algebra?**
378
+ Because state redundancy *is* linear dependence.
379
+
380
+ If two state variables always change together, they span the same dimension of information. Linear algebra provides a precise language-and useful tools-for detecting and reasoning about that relationship.
381
+
382
+ ---
383
+
384
+ ### **Will this ever produce false positives?**
385
+ Yes.
386
+
387
+ React-State-Basis favors **visibility over silence**.
388
+ When in doubt, it surfaces potential issues so developers can make informed decisions.
389
+
390
+ Think of it as an architectural smoke detector-not a fire marshal.
391
+
392
+
393
+ ---
394
+ *Developed by LP*
395
+ *For engineers who treat software as applied mathematics.* πŸš€πŸ“
@@ -0,0 +1,47 @@
1
+ import React, { Dispatch, SetStateAction, DependencyList, EffectCallback, Reducer, Context, ReactNode } from 'react';
2
+ export { CSSProperties, Context, DependencyList, Dispatch, EffectCallback, FC, PropsWithChildren, ReactElement, ReactNode, Reducer, SetStateAction } from 'react';
3
+
4
+ declare const history: Map<string, number[]>;
5
+ declare const currentTickBatch: Set<string>;
6
+ declare const printBasisHealthReport: (threshold?: number) => void;
7
+ declare const beginEffectTracking: (label: string) => void;
8
+ declare const endEffectTracking: () => void;
9
+ declare const registerVariable: (label: string) => void;
10
+ declare const unregisterVariable: (label: string) => void;
11
+ declare const recordUpdate: (label: string) => boolean;
12
+ declare const __testEngine__: {
13
+ history: Map<string, number[]>;
14
+ currentTickBatch: Set<string>;
15
+ registerVariable: (label: string) => void;
16
+ recordUpdate: (label: string) => boolean;
17
+ printBasisHealthReport: (threshold?: number) => void;
18
+ beginEffectTracking: (label: string) => void;
19
+ endEffectTracking: () => void;
20
+ };
21
+
22
+ declare function useState<T>(initialValue: T, label?: string): [T, Dispatch<SetStateAction<T>>];
23
+ declare function useMemo<T>(factory: () => T, deps: DependencyList | undefined, label?: string): T;
24
+ declare function useEffect(effect: EffectCallback, deps?: DependencyList, label?: string): void;
25
+ declare function useReducer<S, A, I>(reducer: Reducer<S, A>, initialArg: I & S, init?: any, label?: string): [S, Dispatch<A>];
26
+ declare function createContext<T>(defaultValue: T, label?: string): Context<T>;
27
+ declare function useContext<T>(context: Context<T>): T;
28
+ declare const __test__: {
29
+ registerVariable: (label: string) => void;
30
+ unregisterVariable: (label: string) => void;
31
+ recordUpdate: (label: string) => boolean;
32
+ beginEffectTracking: (label: string) => void;
33
+ endEffectTracking: () => void;
34
+ history: any;
35
+ currentTickBatch: any;
36
+ };
37
+
38
+ interface BasisProviderProps {
39
+ children: ReactNode;
40
+ debug?: boolean;
41
+ }
42
+ declare const BasisProvider: React.FC<BasisProviderProps>;
43
+ declare const useBasisConfig: () => {
44
+ debug: boolean;
45
+ };
46
+
47
+ export { BasisProvider, __testEngine__, __test__, beginEffectTracking, createContext, currentTickBatch, endEffectTracking, history, printBasisHealthReport, recordUpdate, registerVariable, unregisterVariable, useBasisConfig, useContext, useEffect, useMemo, useReducer, useState };
@@ -0,0 +1,47 @@
1
+ import React, { Dispatch, SetStateAction, DependencyList, EffectCallback, Reducer, Context, ReactNode } from 'react';
2
+ export { CSSProperties, Context, DependencyList, Dispatch, EffectCallback, FC, PropsWithChildren, ReactElement, ReactNode, Reducer, SetStateAction } from 'react';
3
+
4
+ declare const history: Map<string, number[]>;
5
+ declare const currentTickBatch: Set<string>;
6
+ declare const printBasisHealthReport: (threshold?: number) => void;
7
+ declare const beginEffectTracking: (label: string) => void;
8
+ declare const endEffectTracking: () => void;
9
+ declare const registerVariable: (label: string) => void;
10
+ declare const unregisterVariable: (label: string) => void;
11
+ declare const recordUpdate: (label: string) => boolean;
12
+ declare const __testEngine__: {
13
+ history: Map<string, number[]>;
14
+ currentTickBatch: Set<string>;
15
+ registerVariable: (label: string) => void;
16
+ recordUpdate: (label: string) => boolean;
17
+ printBasisHealthReport: (threshold?: number) => void;
18
+ beginEffectTracking: (label: string) => void;
19
+ endEffectTracking: () => void;
20
+ };
21
+
22
+ declare function useState<T>(initialValue: T, label?: string): [T, Dispatch<SetStateAction<T>>];
23
+ declare function useMemo<T>(factory: () => T, deps: DependencyList | undefined, label?: string): T;
24
+ declare function useEffect(effect: EffectCallback, deps?: DependencyList, label?: string): void;
25
+ declare function useReducer<S, A, I>(reducer: Reducer<S, A>, initialArg: I & S, init?: any, label?: string): [S, Dispatch<A>];
26
+ declare function createContext<T>(defaultValue: T, label?: string): Context<T>;
27
+ declare function useContext<T>(context: Context<T>): T;
28
+ declare const __test__: {
29
+ registerVariable: (label: string) => void;
30
+ unregisterVariable: (label: string) => void;
31
+ recordUpdate: (label: string) => boolean;
32
+ beginEffectTracking: (label: string) => void;
33
+ endEffectTracking: () => void;
34
+ history: any;
35
+ currentTickBatch: any;
36
+ };
37
+
38
+ interface BasisProviderProps {
39
+ children: ReactNode;
40
+ debug?: boolean;
41
+ }
42
+ declare const BasisProvider: React.FC<BasisProviderProps>;
43
+ declare const useBasisConfig: () => {
44
+ debug: boolean;
45
+ };
46
+
47
+ export { BasisProvider, __testEngine__, __test__, beginEffectTracking, createContext, currentTickBatch, endEffectTracking, history, printBasisHealthReport, recordUpdate, registerVariable, unregisterVariable, useBasisConfig, useContext, useEffect, useMemo, useReducer, useState };