@inglorious/react-store 8.0.0 → 9.0.1

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.
Files changed (3) hide show
  1. package/README.md +18 -92
  2. package/package.json +3 -3
  3. package/src/index.jsx +20 -0
package/README.md CHANGED
@@ -14,10 +14,6 @@ Connect your React app to Inglorious Store with a familiar API. Built on `react-
14
14
  - **Drop-in Integration**: Works just like `react-redux` with enhanced features for Inglorious Store
15
15
  - **Custom `useNotify` Hook**: Dispatch events with a clean, ergonomic API
16
16
  - **Convenience `useEntity` Hook**: Select a single entity by its ID with a simple, optimized hook.
17
- - **Flexible Update Modes**:
18
- - **Eager mode** - Updates process immediately (responsive UIs)
19
- - **Batched mode** - Updates process on a timer (performance optimization)
20
- - **Redux DevTools Support**: Full integration with Redux DevTools for debugging
21
17
  - **Battle-tested**: Built on `react-redux` for proven performance and stability
22
18
  - **TypeScript Support**: Optional type safety for those who want it
23
19
 
@@ -64,15 +60,8 @@ export const store = createStore({ types, entities })
64
60
  import { createReactStore } from "@inglorious/react-store"
65
61
  import { store } from "./store"
66
62
 
67
- // Eager mode (default) - updates process immediately
68
63
  export const { Provider, useSelector, useNotify, useEntity } =
69
64
  createReactStore(store)
70
-
71
- // Or batched mode - updates process at 20 FPS
72
- // export const { Provider, useSelector, useNotify, useEntity } = createReactStore(store, {
73
- // mode: "batched",
74
- // fps: 20
75
- // })
76
65
  ```
77
66
 
78
67
  ### 3. Wrap Your App
@@ -114,17 +103,13 @@ function Counter() {
114
103
 
115
104
  ## API Reference
116
105
 
117
- ### `createReactStore(store, config?)`
106
+ ### `createReactStore(store)`
118
107
 
119
108
  Creates React bindings for an Inglorious Store.
120
109
 
121
110
  **Parameters:**
122
111
 
123
112
  - `store` (required): An Inglorious Store instance
124
- - `config` (optional): Configuration object
125
- - `mode`: `"eager"` (default) or `"batched"`
126
- - `fps`: Frame rate for batched mode (default: 20)
127
- - `skippedEvents`: Array of event types to exclude from DevTools logging
128
113
 
129
114
  **Returns:**
130
115
 
@@ -136,27 +121,7 @@ Creates React bindings for an Inglorious Store.
136
121
  **Examples:**
137
122
 
138
123
  ```javascript
139
- // Eager mode (immediate updates)
140
124
  const { Provider, useSelector, useNotify, useEntity } = createReactStore(store)
141
-
142
- // Batched mode for real-time apps
143
- const { Provider, useSelector, useNotify, useEntity } = createReactStore(
144
- store,
145
- {
146
- mode: "batched",
147
- fps: 30,
148
- },
149
- )
150
-
151
- // Custom FPS for animations
152
- const { Provider, useSelector, useNotify, useEntity } = createReactStore(
153
- store,
154
- {
155
- mode: "batched",
156
- fps: 60,
157
- skippedEvents: ["update", "mousemove"], // Don't log these in DevTools
158
- },
159
- )
160
125
  ```
161
126
 
162
127
  ### `useNotify()`
@@ -219,69 +184,34 @@ function TodoList() {
219
184
  }
220
185
  ```
221
186
 
222
- ---
223
-
224
- ## Update Modes
225
-
226
- ### Eager Mode (Default)
187
+ ### `useEntity(id)`
227
188
 
228
- Best for most apps. Updates process immediately when you call `notify()`.
189
+ A convenience hook to select a single entity by its ID. It is an optimized way to subscribe a component to updates for a specific entity.
229
190
 
230
- ```javascript
231
- const { Provider, useSelector, useNotify } = createReactStore(store)
232
- ```
233
-
234
- **When to use:**
191
+ **Parameters:**
235
192
 
236
- - Standard apps (forms, CRUD, dashboards)
237
- - ✅ You want instant feedback on user actions
238
- - ✅ You're not processing many events per second
193
+ - `id` (required): The ID of the entity to select.
239
194
 
240
- ### Batched Mode
195
+ **Usage:**
241
196
 
242
- Best for performance-critical apps. Updates process on a fixed timer (FPS).
197
+ ```jsx
198
+ function UserProfile() {
199
+ const user = useEntity("user-123")
200
+ if (!user) {
201
+ return "User not found."
202
+ }
243
203
 
244
- ```javascript
245
- const { Provider, useSelector, useNotify } = createReactStore(store, {
246
- mode: "batched",
247
- fps: 20, // Process events 20 times per second
248
- })
204
+ return user.name
205
+ }
249
206
  ```
250
207
 
251
- **When to use:**
252
-
253
- - ✅ Games or animations
254
- - ✅ High-frequency events (mouse tracking, real-time data)
255
- - ✅ You want to batch multiple events into one React render
256
- - ✅ Performance optimization is critical
257
-
258
- **FPS Guidelines:**
259
-
260
- - **60 FPS** - Smooth animations, games
261
- - **30 FPS** - Good balance for most real-time apps
262
- - **20 FPS (default)** - Input handling, live dashboards, lower CPU usage
263
- - **5-10 FPS** - Background updates, status polling
264
-
265
208
  ---
266
209
 
267
210
  ## Redux DevTools Integration
268
211
 
269
- Redux DevTools work automatically! Install the [browser extension](https://github.com/reduxjs/redux-devtools) to inspect:
270
-
271
- - State snapshots
272
- - Event history
273
- - Time-travel debugging
274
-
275
- **In batched mode**, events are automatically grouped by frame for cleaner DevTools logs.
212
+ Redux DevTools work automatically! Install the browser extension to inspect state snapshots, event history, and use time-travel debugging.
276
213
 
277
- ```javascript
278
- // Skip noisy events from DevTools
279
- const { Provider, useSelector, useNotify } = createReactStore(store, {
280
- mode: "batched",
281
- fps: 20,
282
- skippedEvents: ["mousemove", "update"], // Don't log these
283
- })
284
- ```
214
+ The underlying `@inglorious/store` allows for configuration, such as skipping certain events from being logged. See the store documentation for more details.
285
215
 
286
216
  ---
287
217
 
@@ -433,9 +363,6 @@ For complete TypeScript examples, see the [@inglorious/store TypeScript document
433
363
  **Q: Can I use this with existing react-redux code?**
434
364
  A: Yes! The `Provider` and `useSelector` are compatible. You can gradually migrate to `useNotify`.
435
365
 
436
- **Q: Should I use eager or batched mode?**
437
- A: Start with eager (default). Switch to batched if you notice performance issues or are building a game/real-time app.
438
-
439
366
  **Q: Does this work with React Native?**
440
367
  A: Yes! It works anywhere `react-redux` works.
441
368
 
@@ -457,9 +384,8 @@ A: Not at all! The library works great with plain JavaScript. TypeScript support
457
384
 
458
385
  **What's different:**
459
386
 
460
- - ✅ Custom `useNotify` hook instead of `useDispatch`
461
- - ✅ Batched mode option for performance
462
- - ✅ Automatic `store.update()` handling
387
+ - ✅ `useNotify` hook for dispatching events instead of `useDispatch`
388
+ - ✅ `useEntity` hook for easily selecting an entity by ID
463
389
  - ✅ Cleaner API for event-based state management
464
390
 
465
391
  ---
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inglorious/react-store",
3
- "version": "8.0.0",
3
+ "version": "9.0.1",
4
4
  "description": "Official React bindings for @inglorious/store. Provides hooks and a Provider to connect your React components to the store.",
5
5
  "author": "IceOnFire <antony.mistretta@gmail.com> (https://ingloriouscoderz.it)",
6
6
  "license": "MIT",
@@ -42,12 +42,12 @@
42
42
  },
43
43
  "peerDependencies": {
44
44
  "react": "^19.2.0",
45
- "@inglorious/store": "7.0.0"
45
+ "@inglorious/store": "7.1.1"
46
46
  },
47
47
  "devDependencies": {
48
48
  "prettier": "^3.6.2",
49
49
  "vite": "^7.1.3",
50
- "@inglorious/eslint-config": "1.0.1"
50
+ "@inglorious/eslint-config": "1.1.0"
51
51
  },
52
52
  "engines": {
53
53
  "node": ">= 22"
package/src/index.jsx CHANGED
@@ -1,14 +1,34 @@
1
1
  import { Provider, useSelector } from "react-redux"
2
2
 
3
+ /**
4
+ * Creates a set of React hooks and a Provider component tailored to an Inglorious Store instance.
5
+ * @param {import('@inglorious/store/types/store').Store} store The Inglorious Store instance.
6
+ * @returns {{Provider: ({children}: {children: any}) => JSX.Element, useSelector: import('react-redux').useSelector, useEntity: (id: string | number) => object | undefined, useNotify: () => import('@inglorious/store/types/store').Notify}}
7
+ */
3
8
  export function createReactStore(store) {
9
+ /**
10
+ * A React context Provider that makes the Inglorious Store available to any nested components.
11
+ * @param {{children: React.ReactNode}} props
12
+ */
4
13
  function StoreProvider({ children }) {
5
14
  return <Provider store={store}>{children}</Provider>
6
15
  }
7
16
 
17
+ /**
18
+ * A convenience hook to select a single entity by its ID from the store.
19
+ * It subscribes the component to updates for that specific entity.
20
+ * @param {string | number} id The ID of the entity to select.
21
+ * @returns {object | undefined} The entity object if found, otherwise undefined.
22
+ */
8
23
  function useEntity(id) {
9
24
  return useSelector((entities) => entities[id])
10
25
  }
11
26
 
27
+ /**
28
+ * A hook that returns the `notify` function from the Inglorious Store.
29
+ * This is the primary way to dispatch events to the store from your components.
30
+ * @returns {import('@inglorious/store/types/store').Notify} The `notify` function.
31
+ */
12
32
  function useNotify() {
13
33
  return store._api.notify
14
34
  }