pocket-state 0.1.10 → 0.1.11
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 +25 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -14,6 +14,7 @@ Works seamlessly **inside React** with hooks or **outside React** with a simple
|
|
|
14
14
|
- 🔌 Framework-agnostic – Works in plain TS/JS and React.
|
|
15
15
|
- 🛠 Middleware – Logging, persistence, batching, devtools bridges, etc.
|
|
16
16
|
- 🔔 Event Emitter – Subscribe to store and custom events.
|
|
17
|
+
- ⚖️ EqualityFn – Custom comparator (shallow by default, can use deep/custom).
|
|
17
18
|
- ✅ TypeScript-first – Fully type-safe.
|
|
18
19
|
|
|
19
20
|
---
|
|
@@ -183,17 +184,33 @@ export function CounterComponent() {
|
|
|
183
184
|
|
|
184
185
|
---
|
|
185
186
|
|
|
186
|
-
##
|
|
187
|
+
## ⚖️ EqualityFn
|
|
187
188
|
|
|
188
|
-
|
|
189
|
+
By default, `createStore` uses a shallow equality function to detect changes.
|
|
190
|
+
You can override this by providing a custom comparator as the 3rd argument:
|
|
189
191
|
|
|
190
|
-
```
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
192
|
+
```ts
|
|
193
|
+
import {createStore} from 'pocket-state';
|
|
194
|
+
import deepEqual from 'fast-deep-equal';
|
|
195
|
+
|
|
196
|
+
interface State {
|
|
197
|
+
count: number;
|
|
198
|
+
nested: {a: number; b: number};
|
|
194
199
|
}
|
|
200
|
+
|
|
201
|
+
// shallow equality (default)
|
|
202
|
+
const store1 = createStore<State>({count: 0, nested: {a: 1, b: 2}});
|
|
203
|
+
|
|
204
|
+
// deep equality
|
|
205
|
+
const store2 = createStore<State>(
|
|
206
|
+
{count: 0, nested: {a: 1, b: 2}},
|
|
207
|
+
[],
|
|
208
|
+
deepEqual,
|
|
209
|
+
);
|
|
195
210
|
```
|
|
196
211
|
|
|
212
|
+
This is useful when working with nested state objects and you want to avoid unnecessary re-renders.
|
|
213
|
+
|
|
197
214
|
---
|
|
198
215
|
|
|
199
216
|
## 🧩 API Reference
|
|
@@ -224,6 +241,6 @@ Generates a custom hook for your store.
|
|
|
224
241
|
|
|
225
242
|
## 📜 License
|
|
226
243
|
|
|
227
|
-
MIT
|
|
244
|
+
MIT
|
|
228
245
|
|
|
229
|
-
keywords: pocket-state, state-management, react, react-native, typescript, hooks, store
|
|
246
|
+
keywords: pocket-state, state-management, react, react-native, typescript, hooks, store, equalityFn
|