@inglorious/react-store 7.0.1 → 7.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 +23 -14
- package/package.json +1 -1
- 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 } =
|
|
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,
|
|
97
|
+
import { useNotify, useEntity } from "./react-store"
|
|
96
98
|
|
|
97
99
|
function Counter() {
|
|
98
100
|
const notify = useNotify()
|
|
99
|
-
const 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(
|
|
141
|
-
|
|
142
|
-
|
|
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(
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
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
|
|
3
|
+
"version": "7.1.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",
|
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
|
}
|