@inglorious/react-store 7.0.1 → 8.0.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.
Files changed (3) hide show
  1. package/README.md +23 -14
  2. package/package.json +2 -2
  3. package/src/index.jsx +5 -1
package/README.md CHANGED
@@ -13,6 +13,7 @@ Connect your React app to Inglorious Store with a familiar API. Built on `react-
13
13
 
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
+ - **Convenience `useEntity` Hook**: Select a single entity by its ID with a simple, optimized hook.
16
17
  - **Flexible Update Modes**:
17
18
  - **Eager mode** - Updates process immediately (responsive UIs)
18
19
  - **Batched mode** - Updates process on a timer (performance optimization)
@@ -64,10 +65,11 @@ import { createReactStore } from "@inglorious/react-store"
64
65
  import { store } from "./store"
65
66
 
66
67
  // Eager mode (default) - updates process immediately
67
- export const { Provider, useSelector, useNotify } = createReactStore(store)
68
+ export const { Provider, useSelector, useNotify, useEntity } =
69
+ createReactStore(store)
68
70
 
69
71
  // Or batched mode - updates process at 20 FPS
70
- // export const { Provider, useSelector, useNotify } = createReactStore(store, {
72
+ // export const { Provider, useSelector, useNotify, useEntity } = createReactStore(store, {
71
73
  // mode: "batched",
72
74
  // fps: 20
73
75
  // })
@@ -92,11 +94,11 @@ function App() {
92
94
 
93
95
  ```jsx
94
96
  // Counter.jsx
95
- import { useNotify, useSelector } from "./react-store"
97
+ import { useNotify, useEntity } from "./react-store"
96
98
 
97
99
  function Counter() {
98
100
  const notify = useNotify()
99
- const value = useSelector((state) => state.myCounter.value)
101
+ const { value } = useEntity("myCounter")
100
102
 
101
103
  return (
102
104
  <div>
@@ -129,25 +131,32 @@ Creates React bindings for an Inglorious Store.
129
131
  - `Provider`: React context provider component (pre-configured with your store)
130
132
  - `useSelector`: Hook to select state slices
131
133
  - `useNotify`: Hook to dispatch events
134
+ - `useEntity`: Hook to select a single entity by ID
132
135
 
133
136
  **Examples:**
134
137
 
135
138
  ```javascript
136
139
  // Eager mode (immediate updates)
137
- const { Provider, useSelector, useNotify } = createReactStore(store)
140
+ const { Provider, useSelector, useNotify, useEntity } = createReactStore(store)
138
141
 
139
142
  // Batched mode for real-time apps
140
- const { Provider, useSelector, useNotify } = createReactStore(store, {
141
- mode: "batched",
142
- fps: 30,
143
- })
143
+ const { Provider, useSelector, useNotify, useEntity } = createReactStore(
144
+ store,
145
+ {
146
+ mode: "batched",
147
+ fps: 30,
148
+ },
149
+ )
144
150
 
145
151
  // Custom FPS for animations
146
- const { Provider, useSelector, useNotify } = createReactStore(store, {
147
- mode: "batched",
148
- fps: 60,
149
- skippedEvents: ["update", "mousemove"], // Don't log these in DevTools
150
- })
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
+ )
151
160
  ```
152
161
 
153
162
  ### `useNotify()`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inglorious/react-store",
3
- "version": "7.0.1",
3
+ "version": "8.0.0",
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,7 +42,7 @@
42
42
  },
43
43
  "peerDependencies": {
44
44
  "react": "^19.2.0",
45
- "@inglorious/store": "6.2.1"
45
+ "@inglorious/store": "7.0.0"
46
46
  },
47
47
  "devDependencies": {
48
48
  "prettier": "^3.6.2",
package/src/index.jsx CHANGED
@@ -5,9 +5,13 @@ export function createReactStore(store) {
5
5
  return <Provider store={store}>{children}</Provider>
6
6
  }
7
7
 
8
+ function useEntity(id) {
9
+ return useSelector((entities) => entities[id])
10
+ }
11
+
8
12
  function useNotify() {
9
13
  return store._api.notify
10
14
  }
11
15
 
12
- return { Provider: StoreProvider, useSelector, useNotify }
16
+ return { Provider: StoreProvider, useSelector, useEntity, useNotify }
13
17
  }