@biglogic/rgs 3.5.2 → 3.5.3

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
@@ -1,323 +1,360 @@
1
- # Argis (RGS) - Reactive Global State
2
-
3
- > "The Magnetar" **Atomic Precision. Immutable Safety. Zen Simplicity.**
4
- > The most powerful state management engine for React. Built for those who demand industrial-grade reliability with a zero-boilerplate experience.
5
-
6
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
- [![version](https://img.shields.io/npm/v/@biglogic/rgs.svg)](https://npmjs.org/package/@biglogic/rgs)
8
- [![downloads](https://img.shields.io/npm/dm/@biglogic/rgs.svg)](https://npmjs.org/package/@biglogic/rgs)
9
-
10
- ![Javascript](https://img.shields.io/badge/Javascript-gray?logo=Javascript)
11
- ![React](https://img.shields.io/badge/React-gray?logo=React)
12
- ![TypeScript](https://img.shields.io/badge/TypeScript-gray?logo=typescript)
13
- ![Node.js](https://img.shields.io/badge/Node.js-gray?logo=node.js)
14
- ![Jest](https://img.shields.io/badge/Jest-gray?logo=jest)
15
- ![Playwright](https://img.shields.io/badge/Playwright-gray?logo=playwright)
16
- ![ESLint](https://img.shields.io/badge/Eslint-gray?logo=eslint)
17
- ![esbuild](https://img.shields.io/badge/esbuild-gray?logo=esbuild)
18
-
19
- ![Snik](https://img.shields.io/badge/Snyk-gray?logo=Snyk)
20
- ![Snik](https://img.shields.io/badge/Socket-gray?logo=socket)
21
-
22
- <!-- [![GitBook](https://img.shields.io/static/v1?message=Documented%20on%20GitBook&logo=gitbook&logoColor=ffffff&label=%20&labelColor=5c5c5c&color=3F89A1)](https://a51.gitbook.io/rgs) -->
23
-
24
- ---
25
-
26
- ## 🌟 Why Magnetar?
27
-
28
- We took the simplicity of **Reactive Global State (RGS)** and fused it with the architecture of a **High-Performance Kernel**. It's the only library that gives you:
29
-
30
- - **💎 Absolute Immutability**: Powered by **Immer**. No more manual spreads. State is frozen by default.
31
- - **🛡️ Industrial-Grade Safety**: Deep Proxy guards that throw `Forbidden Mutation` errors if you try to bypass the kernel.
32
- - **🔌 Enterprise Ecosystem**: A real plugin architecture with 10+ official modules (Sync, Storage, DevTools, etc.).
33
- - **⚛️ Power on Demand**: Advanced async and persistence tools isolated in the `advanced` export.
34
- - **🏗️ Stellar Architecture**: Zero circular dependencies. Modular, clean, and 100% type-safe.
35
-
36
- ---
37
-
38
- ## gState vs useState
39
-
40
- | Feature | useState | gState |
41
- |---------|----------|--------|
42
- | **Global state across components** | ❌ Need Context/props | ✅ Automatic sharing |
43
- | **Provider wrapper** | ❌ Required | ✅ Not needed |
44
- | **Persistence (localStorage)** | ❌ Manual | ✅ Built-in |
45
- | **Data encryption** | ❌ | ✅ AES-256-GCM |
46
- | **Multiple namespaces/stores** | | |
47
- | **Plugins (Immer, Undo/Redo)** | | |
48
- | **Audit logging** | | |
49
- | **RBAC/GDPR consent** | | |
50
- | **SSR/Hydration** | Manual | Automatic |
51
- | **Computed values** | | |
52
-
53
- ### When to use what?
54
-
55
- - **useState**: Local UI, single component, temporary state
56
- - **gState**:
57
- - Shared state across multiple components
58
- - Persistent data (preferences, cart, authentication)
59
- - Sensitive data (encryption)
60
- - Advanced features (undo/redo, snapshots)
61
- - Enterprise (audit, RBAC, GDPR)
62
-
63
- ---
64
-
65
- ## ⚔️ The Arena: RGS vs The World
66
-
67
- |Feature|**RGS (Argis)**|Zustand|Redux Toolkit|Recoil|
68
- |:---|:---|:---|:---|:---|
69
- | **Philosophy** | **Zen State** | Minimalist | Enterprise Flux | Atomic |
70
- | **API Surface** | **1 Function** | Simple | Complex | Complex |
71
- | **Mutations** | **Magic (Immer)** | Manual Spreads | Magic (Immer) | Manual |
72
- | **Selectors** | ✅ **Type-Safe** | ✅ Functional | ✅ Functional | ⚠️ Selectors |
73
- | **Security** | 🛡️ **AES-256 + RBAC** | ❌ None | ❌ Ecosystem | ❌ None |
74
- | **Persistence** | 💾 **First-class** | 🔌 Middleware | 🔌 Middleware | 🔌 Effects |
75
- | **Async** | ✅ **Atomic** | ✅ Async/Await | ✅ Thunks | ✅ Suspense |
76
- | **Bundle Size** | **~2kB** | ~1kB | >10kB | >20kB |
77
-
78
- > **RGS** is the only library on the market that treats **Security** and **Persistence** as first-class citizens.
79
-
80
- ---
81
-
82
- ### Installation
83
-
84
- ```shell
85
- npm install @biglogic/rgs
86
- ```
87
-
88
- ---
89
-
90
- ### Examples and guide
91
-
92
- **[github.com/BigLogic-ca/rgs](https://github.com/BigLogic-ca/rgs)**
93
-
94
- ---
95
-
96
- ## 🏗️ Architecture
97
-
98
- ```mermaid
99
- graph TB
100
- subgraph API
101
- A[gstate] --> D[IStore]
102
- B[useStore] --> D
103
- C[createStore] --> D
104
- end
105
-
106
- D --> E[Storage Adapter]
107
- D --> F[Immer Proxy]
108
- D --> G[Plugins]
109
- D --> H[Security]
110
- D --> I[Async Store]
111
-
112
- E --> J[local]
113
- E --> K[session]
114
- E --> L[memory]
115
-
116
- G --> M[UndoRedo]
117
- G --> N[Sync]
118
- G --> O[Schema]
119
- G --> P[Analytics]
120
- ```
121
-
122
- ### Core Components
123
-
124
- | Component | Description |
125
- |-----------|-------------|
126
- | **gstate()** | Creates store + hook in one line |
127
- | **useStore()** | React hook for subscribing to state |
128
- | **createStore()** | Classic store factory |
129
- | **IStore** | Core interface with get/set/subscribe |
130
- | **StorageAdapters** | local, session, memory persistence |
131
- | **Plugins** | Immer, Undo/Redo, Sync, Schema, etc. |
132
- | **Security** | Encryption, RBAC, GDPR consent |
133
-
134
- ---
135
-
136
- ## Requirements
137
-
138
- - **React 16.8+** (for hooks support)
139
- - **React DOM**
140
-
141
- ## ⚡ Zero-Boilerplate Quickstart
142
-
143
- ### Path A: The Zen Way (Modular)
144
-
145
- Best for modern applications. Clean imports, zero global pollution, **Type-Safe**.
146
-
147
- ```tsx
148
- import { gstate } from '@biglogic/rgs'
149
-
150
- // 1. Create a typed store hook
151
- const useCounter = gstate({ count: 0, user: { name: 'Alice' } })
152
-
153
- // 2. Use with Type-Safe Selectors (Preferred)
154
- const count = useCounter(state => state.count)
155
- const userName = useCounter(state => state.user.name)
156
-
157
- // OR use string keys (Legacy)
158
- const [count, setCount] = useCounter('count')
159
- ```
160
-
161
- ### Path B: The Classic Way (Global)
162
-
163
- Best for shared state across the entire application.
164
-
165
- ```tsx
166
- // 1. Initialize once
167
- import { initState, useStore } from '@biglogic/rgs'
168
- initState({ namespace: 'app' })
169
-
170
- // 2. Use anywhere
171
- const [user, setUser] = useStore('user')
172
- ```
173
-
174
- ---
175
-
176
- ## 📚 Quick Examples
177
-
178
- ```tsx
179
- const store = gstate({ theme: 'dark' }, "my-app")
180
- ```
181
-
182
- ### Encryption
183
-
184
- ```tsx
185
- const secureStore = gstate({ token: 'xxx' }, { encoded: true })
186
- ```
187
-
188
- ### Undo/Redo
189
-
190
- ```tsx
191
- const store = gstate({ count: 0 })
192
- store._addPlugin(undoRedoPlugin({ limit: 50 }))
193
-
194
- store.undo()
195
- store.redo()
196
- ```
197
-
198
- ### Cross-Tab Sync
199
-
200
- ```tsx
201
- const store = gstate({ theme: 'light' })
202
- store._addPlugin(syncPlugin({ channelName: 'my-app' }))
203
- ```
204
-
205
- ```tsx
206
- const store = gstate({ firstName: 'John', lastName: 'Doe' })
207
- store.compute('fullName', (get) => `${get('firstName')} ${get('lastName')}`)
208
-
209
- const [fullName] = store('fullName') // "John Doe"
210
- ```
211
-
212
- ### Error Handling with onError
213
-
214
- Handle errors gracefully with the `onError` callback - perfect for production apps:
215
-
216
- ```tsx
217
- const store = gstate({ data: null }, {
218
- onError: (error, context) => {
219
- console.error(`Error in ${context.operation}:`, error.message)
220
- // Send to error tracking service (Sentry, etc.)
221
- }
222
- })
223
- ```
224
-
225
- ### Size Limits (maxObjectSize & maxTotalSize)
226
-
227
- Protect your app from memory issues with automatic size warnings:
228
-
229
- ```tsx
230
- const store = gstate({ data: {} }, {
231
- // Warn if single value exceeds 5MB (Default is 0/Disabled for performance)
232
- maxObjectSize: 5 * 1024 * 1024,
233
- // Warn if total store exceeds 50MB (Default is 0/Disabled)
234
- maxTotalSize: 50 * 1024 * 1024
235
- })
236
- ```
237
-
238
- ---
239
-
240
- ## Multiple Stores
241
-
242
- You can create multiple independent stores using namespaces:
243
-
244
- ```tsx
245
- // Option 1: gstate with namespace
246
- const userStore = gstate({ name: 'John' }, { namespace: 'users' })
247
- const appStore = gstate({ theme: 'dark' }, { namespace: 'app' })
248
-
249
- // In components - same key, different stores
250
- const [name] = userStore('name') // 'John'
251
- const [theme] = appStore('theme') // 'dark'
252
-
253
- // Option 2: initState + useStore (global default store)
254
- initState({ namespace: 'global' })
255
- const [value, setValue] = useStore('key')
256
- ```
257
-
258
- **Tip**: Keys are unique per-namespace, so you can use the same key name in different stores.
259
-
260
- ## 🚀 Advanced Superpowers
261
-
262
- ### 🔌 Official Plugin Ecosystem
263
-
264
- Extend the core functionality dynamically with specialized modules.
265
-
266
- 1. **ImmerPlugin**: Adds `setWithProduce` for functional updates.
267
- 2. **UndoRedoPlugin**: Multi-level history management.
268
- 3. **PersistencePlugin**: Advanced storage with custom serialization.
269
- 4. **SyncPlugin**: Cross-tab state synchronization via BroadcastChannel.
270
- 5. **SchemaPlugin**: Runtime validation (perfect for Zod).
271
- 6. **DevToolsPlugin**: Redux DevTools integration.
272
- 7. **TTLPlugin**: Time-to-live management.
273
- 8. **AnalyticsPlugin**: Tracking bridge for metrics.
274
- 9. **SnapshotPlugin**: Manual state checkpointing.
275
- 10. **GuardPlugin**: Data transformation layer.
276
-
277
- ```typescript
278
- import { createStore, PersistencePlugin, undoRedoPlugin } from '@biglogic/rgs'
279
-
280
- const store = createStore()
281
- store._addPlugin(PersistencePlugin({ storage: 'localStorage' }))
282
- store._addPlugin(undoRedoPlugin({ limit: 50 }))
283
-
284
- // Undo like a pro
285
- store.undo()
286
- ```
287
-
288
- ### 🔬 Power Tools (Import from `rgs/advanced`)
289
-
290
- Need the heavy artillery? We've got you covered.
291
-
292
- - `createAsyncStore(fetcher)`: Atomic async state management.
293
- - `StorageAdapters`: High-level interfaces for any storage engine.
294
- - `Middleware / IPlugin`: Build your own extensions.
295
-
296
- ---
297
-
298
- ## 🛡️ Quality & Testing
299
-
300
- RGS is built with an obsession for reliability. Our test suite covers multiple layers to ensure zero-regressions:
301
-
302
- - **Unit Tests (Jest)**: 100+ tests covering core logic, stores, and hooks.
303
- - **E2E Tests (Playwright)**: Real-world browser testing for cross-tab synchronization and Web Crypto API.
304
- - **Concurrency Testing**: Verification of race conditions in multi-tab environments.
305
-
306
- ```bash
307
- # Run unit tests
308
- npm run test
309
-
310
- # Run E2E tests
311
- npm run test:e2e
312
- ```
313
-
314
- ---
315
-
316
- ## 📄 License
317
-
318
- MIT © [Dario Passariello](https://github.com/dpassariello)
319
-
320
- ---
321
-
322
- **Designed for those who build the future.**
323
- Made with ❤️ and a lot of caffe' espresso!
1
+ # Argis (RGS) - Reactive Global State
2
+
3
+ > "The Magnetar" **Atomic Precision. Immutable Safety. Zen Simplicity.**
4
+ > The most powerful state management engine for React. Built for those who demand industrial-grade reliability with a zero-boilerplate experience.
5
+
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
+ [![version](https://img.shields.io/npm/v/@biglogic/rgs.svg)](https://npmjs.org/package/@biglogic/rgs)
8
+ [![downloads](https://img.shields.io/npm/dm/@biglogic/rgs.svg)](https://npmjs.org/package/@biglogic/rgs)
9
+
10
+ ![Javascript](https://img.shields.io/badge/Javascript-gray?logo=Javascript)
11
+ ![React](https://img.shields.io/badge/React-gray?logo=React)
12
+ ![TypeScript](https://img.shields.io/badge/TypeScript-gray?logo=typescript)
13
+ ![Node.js](https://img.shields.io/badge/Node.js-gray?logo=node.js)
14
+ ![Jest](https://img.shields.io/badge/Jest-gray?logo=jest)
15
+ ![Playwright](https://img.shields.io/badge/Playwright-gray?logo=playwright)
16
+ ![ESLint](https://img.shields.io/badge/Eslint-gray?logo=eslint)
17
+ ![esbuild](https://img.shields.io/badge/esbuild-gray?logo=esbuild)
18
+
19
+ ![Snik](https://img.shields.io/badge/Snyk-gray?logo=Snyk)
20
+ ![Snik](https://img.shields.io/badge/Socket-gray?logo=socket)
21
+
22
+ <!-- [![GitBook](https://img.shields.io/static/v1?message=Documented%20on%20GitBook&logo=gitbook&logoColor=ffffff&label=%20&labelColor=5c5c5c&color=3F89A1)](https://a51.gitbook.io/rgs) -->
23
+
24
+ ---
25
+
26
+ ## 🌟 Why Magnetar?
27
+
28
+ We took the simplicity of **Reactive Global State (RGS)** and fused it with the architecture of a **High-Performance Kernel**. It's the only library that gives you:
29
+
30
+ - **💎 Absolute Immutability**: Powered by **Immer**. No more manual spreads. State is frozen by default.
31
+ - **🛡️ Industrial-Grade Safety**: Deep Proxy guards that throw `Forbidden Mutation` errors if you try to bypass the kernel.
32
+ - **🔌 Enterprise Ecosystem**: A real plugin architecture with 10+ official modules (Sync, Storage, DevTools, etc.).
33
+ - **⚛️ Power on Demand**: Advanced async and persistence tools isolated in the `advanced` export.
34
+ - **🏗️ Stellar Architecture**: Zero circular dependencies. Modular, clean, and 100% type-safe.
35
+
36
+ ---
37
+
38
+ ## gState vs useState
39
+
40
+ | Feature | RGS gState | React useState |
41
+ |---------|--------|----------|
42
+ | **Global state across components** | ✅ Automatic sharing | ❌ Need Context/props |
43
+ | **Provider wrapper** | ✅ Not needed | ❌ Required |
44
+ | **Persistence (localStorage)** | ✅ Built-in | ❌ Manual |
45
+ | **Data encryption** | ✅ AES-256-GCM | ❌ |
46
+ | **Multiple namespaces/stores** | | |
47
+ | **Plugins (Immer, Undo/Redo)** | | |
48
+ | **Audit logging** | | |
49
+ | **RBAC/GDPR consent** | | |
50
+ | **SSR/Hydration** | Automatic | Manual |
51
+ | **Computed values** | | |
52
+
53
+ ### When to use what?
54
+
55
+ - **useState**: Local UI, single component, temporary state
56
+ - **gState**:
57
+ - Shared state across multiple components
58
+ - Persistent data (preferences, cart, authentication)
59
+ - Sensitive data (encryption)
60
+ - Advanced features (undo/redo, snapshots)
61
+ - Enterprise (audit, RBAC, GDPR)
62
+
63
+ ---
64
+
65
+ ## ⚔️ The Arena: RGS vs The World
66
+
67
+ |Feature|**RGS (Argis)**|Zustand|Redux Toolkit|Recoil|
68
+ |:---|:---|:---|:---|:---|
69
+ | **Philosophy** | **Zen State** | Minimalist | Enterprise Flux | Atomic |
70
+ | **API Surface** | **1 Function** | Simple | Complex | Complex |
71
+ | **Mutations** | **Magic (Immer)** | Manual Spreads | Magic (Immer) | Manual |
72
+ | **Selectors** | ✅ **Type-Safe** | ✅ Functional | ✅ Functional | ⚠️ Selectors |
73
+ | **Security** | 🛡️ **AES-256 + RBAC** | ❌ None | ❌ Ecosystem | ❌ None |
74
+ | **Persistence** | 💾 **First-class** | 🔌 Middleware | 🔌 Middleware | 🔌 Effects |
75
+ | **Async** | ✅ **Atomic** | ✅ Async/Await | ✅ Thunks | ✅ Suspense |
76
+ | **Local-First Sync** | **Built-in** | None | None | None |
77
+ | **Bundle Size** | **~2kB** | ~1kB | >10kB | >20kB |
78
+
79
+ > **RGS** is the only library on the market that treats **Security** and **Persistence** as first-class citizens.
80
+
81
+ ---
82
+
83
+ ### Installation
84
+
85
+ ```shell
86
+ npm install @biglogic/rgs
87
+ ```
88
+
89
+ ---
90
+
91
+ ### Examples and guide
92
+
93
+ **[github.com/BigLogic-ca/rgs](https://github.com/BigLogic-ca/rgs)**
94
+
95
+ ---
96
+
97
+ ## 🏗️ Architecture
98
+
99
+ ```mermaid
100
+ graph TB
101
+ subgraph API
102
+ A[gstate] --> D[IStore]
103
+ B[useStore] --> D
104
+ C[createStore] --> D
105
+ end
106
+
107
+ D --> E[Storage Adapter]
108
+ D --> F[Immer Proxy]
109
+ D --> G[Plugins]
110
+ D --> H[Security]
111
+ D --> I[Async Store]
112
+
113
+ E --> J[local]
114
+ E --> K[session]
115
+ E --> L[memory]
116
+
117
+ G --> M[UndoRedo]
118
+ G --> N[Sync]
119
+ G --> O[Schema]
120
+ G --> P[Analytics]
121
+ ```
122
+
123
+ ### Core Components
124
+
125
+ | Component | Description |
126
+ |-----------|-------------|
127
+ | **gstate()** | Creates store + hook in one line |
128
+ | **useStore()** | React hook for subscribing to state |
129
+ | **createStore()** | Classic store factory |
130
+ | **IStore** | Core interface with get/set/subscribe |
131
+ | **StorageAdapters** | local, session, memory persistence |
132
+ | **Plugins** | Immer, Undo/Redo, Sync, Schema, etc. |
133
+ | **Security** | Encryption, RBAC, GDPR consent |
134
+
135
+ ---
136
+
137
+ ## Requirements
138
+
139
+ - **React 16.8+** (for hooks support)
140
+ - **React DOM**
141
+
142
+ ## ⚡ Zero-Boilerplate Quickstart
143
+
144
+ ### Path A: The Zen Way (Modular)
145
+
146
+ Best for modern applications. Clean imports, zero global pollution, **Type-Safe**.
147
+
148
+ ```tsx
149
+ import { gstate } from '@biglogic/rgs'
150
+
151
+ // 1. Create a typed store hook
152
+ const useCounter = gstate({ count: 0, user: { name: 'Alice' } })
153
+
154
+ // 2. Use with Type-Safe Selectors (Preferred)
155
+ const count = useCounter(state => state.count)
156
+ const userName = useCounter(state => state.user.name)
157
+
158
+ // OR use string keys (Legacy)
159
+ const [count, setCount] = useCounter('count')
160
+ ```
161
+
162
+ ### Path B: The Classic Way (Global)
163
+
164
+ Best for shared state across the entire application.
165
+
166
+ ```tsx
167
+ // 1. Initialize once
168
+ import { initState, useStore } from '@biglogic/rgs'
169
+ initState({ namespace: 'app' })
170
+
171
+ // 2. Use anywhere
172
+ const [user, setUser] = useStore('user')
173
+ ```
174
+
175
+ ---
176
+
177
+ ## 📚 Quick Examples
178
+
179
+ ```tsx
180
+ const store = gstate({ theme: 'dark' }, "my-app")
181
+ ```
182
+
183
+ ### Encryption
184
+
185
+ ```tsx
186
+ const secureStore = gstate({ token: 'xxx' }, { encoded: true })
187
+ ```
188
+
189
+ ### Undo/Redo
190
+
191
+ ```tsx
192
+ const store = gstate({ count: 0 })
193
+ store._addPlugin(undoRedoPlugin({ limit: 50 }))
194
+
195
+ store.undo()
196
+ store.redo()
197
+ ```
198
+
199
+ ### Cross-Tab Sync
200
+
201
+ ```tsx
202
+ const store = gstate({ theme: 'light' })
203
+ store._addPlugin(syncPlugin({ channelName: 'my-app' }))
204
+ ```
205
+
206
+ ```tsx
207
+ const store = gstate({ firstName: 'John', lastName: 'Doe' })
208
+ store.compute('fullName', (get) => `${get('firstName')} ${get('lastName')}`)
209
+
210
+ const [fullName] = store('fullName') // "John Doe"
211
+ ```
212
+
213
+ ### Error Handling with onError
214
+
215
+ Handle errors gracefully with the `onError` callback - perfect for production apps:
216
+
217
+ ```tsx
218
+ const store = gstate({ data: null }, {
219
+ onError: (error, context) => {
220
+ console.error(`Error in ${context.operation}:`, error.message)
221
+ // Send to error tracking service (Sentry, etc.)
222
+ }
223
+ })
224
+ ```
225
+
226
+ ### Size Limits (maxObjectSize & maxTotalSize)
227
+
228
+ Protect your app from memory issues with automatic size warnings:
229
+
230
+ ```tsx
231
+ const store = gstate({ data: {} }, {
232
+ // Warn if single value exceeds 5MB (Default is 0/Disabled for performance)
233
+ maxObjectSize: 5 * 1024 * 1024,
234
+ // Warn if total store exceeds 50MB (Default is 0/Disabled)
235
+ maxTotalSize: 50 * 1024 * 1024
236
+ })
237
+ ```
238
+
239
+ ### Local-First Sync (Offline-by-Default)
240
+
241
+ RGS now includes a powerful Local-First Sync Engine that makes your app work offline by default:
242
+
243
+ ```tsx
244
+ import { gstate, useSyncedState } from '@biglogic/rgs'
245
+
246
+ // Create store with built-in sync
247
+ const store = gstate({
248
+ todos: [],
249
+ user: null
250
+ }, {
251
+ namespace: 'myapp',
252
+ sync: {
253
+ endpoint: 'https://api.example.com/sync',
254
+ authToken: 'your-token',
255
+ autoSyncInterval: 30000, // Sync every 30s
256
+ syncOnReconnect: true, // Auto-sync when back online
257
+ strategy: 'last-write-wins' // Conflict resolution
258
+ }
259
+ })
260
+
261
+ // Use in React - automatically synced!
262
+ function TodoList() {
263
+ const [todos, setTodos] = useSyncedState('todos')
264
+
265
+ // Works offline automatically
266
+ const addTodo = (text) => {
267
+ setTodos([...todos, { id: Date.now(), text }])
268
+ }
269
+
270
+ return <div>{/* ... */}</div>
271
+ }
272
+ ```
273
+
274
+ ---
275
+
276
+ ## Multiple Stores
277
+
278
+ You can create multiple independent stores using namespaces:
279
+
280
+ ```tsx
281
+ // Option 1: gstate with namespace
282
+ const userStore = gstate({ name: 'John' }, { namespace: 'users' })
283
+ const appStore = gstate({ theme: 'dark' }, { namespace: 'app' })
284
+
285
+ // In components - same key, different stores
286
+ const [name] = userStore('name') // 'John'
287
+ const [theme] = appStore('theme') // 'dark'
288
+
289
+ // Option 2: initState + useStore (global default store)
290
+ initState({ namespace: 'global' })
291
+ const [value, setValue] = useStore('key')
292
+ ```
293
+
294
+ **Tip**: Keys are unique per-namespace, so you can use the same key name in different stores.
295
+
296
+ ## 🚀 Advanced Superpowers
297
+
298
+ ### 🔌 Official Plugin Ecosystem
299
+
300
+ Extend the core functionality dynamically with specialized modules.
301
+
302
+ 1. **ImmerPlugin**: Adds `setWithProduce` for functional updates.
303
+ 2. **UndoRedoPlugin**: Multi-level history management.
304
+ 3. **PersistencePlugin**: Advanced storage with custom serialization.
305
+ 4. **SyncPlugin**: Cross-tab state synchronization via BroadcastChannel.
306
+ 5. **SchemaPlugin**: Runtime validation (perfect for Zod).
307
+ 6. **DevToolsPlugin**: Redux DevTools integration.
308
+ 7. **TTLPlugin**: Time-to-live management.
309
+ 8. **AnalyticsPlugin**: Tracking bridge for metrics.
310
+ 9. **SnapshotPlugin**: Manual state checkpointing.
311
+ 10. **GuardPlugin**: Data transformation layer.
312
+ 11. **Local-First Sync**: Built-in offline-first with auto-sync (NEW!)
313
+
314
+ ```typescript
315
+ import { createStore, PersistencePlugin, undoRedoPlugin } from '@biglogic/rgs'
316
+
317
+ const store = createStore()
318
+ store._addPlugin(PersistencePlugin({ storage: 'localStorage' }))
319
+ store._addPlugin(undoRedoPlugin({ limit: 50 }))
320
+
321
+ // Undo like a pro
322
+ store.undo()
323
+ ```
324
+
325
+ ### 🔬 Power Tools (Import from `rgs/advanced`)
326
+
327
+ Need the heavy artillery? We've got you covered.
328
+
329
+ - `createAsyncStore(fetcher)`: Atomic async state management.
330
+ - `StorageAdapters`: High-level interfaces for any storage engine.
331
+ - `Middleware / IPlugin`: Build your own extensions.
332
+
333
+ ---
334
+
335
+ ## 🛡️ Quality & Testing
336
+
337
+ RGS is built with an obsession for reliability. Our test suite covers multiple layers to ensure zero-regressions:
338
+
339
+ - **Unit Tests (Jest)**: 100+ tests covering core logic, stores, and hooks.
340
+ - **E2E Tests (Playwright)**: Real-world browser testing for cross-tab synchronization and Web Crypto API.
341
+ - **Concurrency Testing**: Verification of race conditions in multi-tab environments.
342
+
343
+ ```bash
344
+ # Run unit tests
345
+ npm run test
346
+
347
+ # Run E2E tests
348
+ npm run test:e2e
349
+ ```
350
+
351
+ ---
352
+
353
+ ## 📄 License
354
+
355
+ MIT © [Dario Passariello](https://github.com/dpassariello)
356
+
357
+ ---
358
+
359
+ **Designed for those who build the future.**
360
+ Made with ❤️ and a lot of caffe' espresso!