@braine/quantum-query 1.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/README.md ADDED
@@ -0,0 +1,128 @@
1
+ # @braine/quantum-query
2
+
3
+ **State Management at the Speed of Light.**
4
+ > A unified architecture that merges Store, Actions, and API Logic into single, high-performance "Smart Models".
5
+
6
+ [![npm version](https://img.shields.io/npm/v/@braine/quantum-query.svg)](https://www.npmjs.com/package/@braine/quantum-query)
7
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
8
+
9
+ ## Why "Quantum"?
10
+ Existing libraries behave like "Buses". They stop at every station (component) to check if someone needs to get off (re-render).
11
+ **Quantum-Query** behaves like a teleporter. It updates *only* the specific component listening to a specific property, instantly.
12
+
13
+ * **O(1) Reactivity**: No selectors. No linear scans.
14
+ * **Zero Boilerplate**: No reduces, no thunks, no providers.
15
+ * **Enterprise Grade**: Built-in HTTP client with automatic deduplication, retries, and cancellation.
16
+
17
+ ---
18
+
19
+ ## Installation
20
+
21
+ ```bash
22
+ npm install @braine/quantum-query
23
+ ```
24
+
25
+ ---
26
+
27
+ ## The "Smart Model" Pattern
28
+
29
+ Stop splitting your logic between Redux (Client) and React Query (Server). Use **Smart Models**.
30
+
31
+ ### 1. Define It
32
+ `defineModel` wraps your state, computed properties, and actions into one reactive entity.
33
+
34
+ ```typescript
35
+ import { defineModel } from '@braine/quantum-query';
36
+
37
+ export const TodoModel = defineModel({
38
+ // 1. Unified State
39
+ state: {
40
+ items: [] as string[],
41
+ filter: 'all',
42
+ },
43
+
44
+ // 2. Computed Properties (Auto-Memoized)
45
+ computed: {
46
+ activeCount() {
47
+ return this.items.length;
48
+ }
49
+ },
50
+
51
+ // 3. Actions (Sync + Async + Optimistic)
52
+ actions: {
53
+ async add(text: string) {
54
+ // Optimistic Update (Instant UI)
55
+ this.items.push(text);
56
+
57
+ try {
58
+ await api.post('/todos', { text });
59
+ } catch (err) {
60
+ this.items.pop(); // Auto-Rollback
61
+ }
62
+ }
63
+ }
64
+ });
65
+ ```
66
+
67
+ ### 2. Use It
68
+ Just use it.
69
+
70
+ ```tsx
71
+ import { useStore } from '@braine/quantum-query';
72
+ import { TodoModel } from './models/TodoModel';
73
+
74
+ function TodoApp() {
75
+ const model = useStore(TodoModel); // Auto-subscribes!
76
+
77
+ return (
78
+ <button onClick={() => model.add("Ship it")}>
79
+ Active: {model.activeCount}
80
+ </button>
81
+ );
82
+ }
83
+ ```
84
+
85
+ ---
86
+
87
+ ## Enterprise HTTP Client
88
+
89
+ We built a fetch wrapper that matches **RTK Query** in power but keeps **Axios** simplicity.
90
+
91
+ ```typescript
92
+ import { createHttpClient } from '@braine/quantum-query';
93
+
94
+ export const api = createHttpClient({
95
+ baseURL: 'https://api.myapp.com',
96
+ timeout: 5000,
97
+ retry: { retries: 3 }, // Exponential backoff for 5xx/Network errors
98
+
99
+ // Auth Handling
100
+ auth: {
101
+ getToken: () => localStorage.getItem('token'),
102
+ onTokenExpired: async () => {
103
+ const newToken = await refreshToken();
104
+ localStorage.setItem('token', newToken);
105
+ return newToken; // Automatically retries original request
106
+ }
107
+ }
108
+ });
109
+
110
+ // Automatic Deduplication
111
+ // If 5 components call this at once, only 1 request is sent!
112
+ const users = await api.get('/users');
113
+ ```
114
+
115
+ ---
116
+
117
+ ## Comparison
118
+
119
+ | Feature | Redux Toolkit | TanStack Query | **Quantum-Query** |
120
+ | :--- | :--- | :--- | :--- |
121
+ | **Philosophy** | Reducers + Thunks | Server Cache Only | **Unified Smart Models** |
122
+ | **Boilerplate** | High | Medium | **Zero** |
123
+ | **Performance** | O(N) Selectors | Good | **O(1) Direct Access** |
124
+ | **Deduplication**| Yes | Yes | **Yes** |
125
+ | **Bundle Size** | Heavy | Medium | **Tiny (<5kb)** |
126
+
127
+ ## License
128
+ MIT