@superutils/store 0.1.19 → 0.1.20
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 +5 -5
- package/dist/browser/index.min.js.map +1 -1
- package/dist/index.cjs +2 -1
- package/dist/index.d.cts +6 -6
- package/dist/index.d.ts +6 -6
- package/dist/index.js +2 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -129,7 +129,7 @@ createStore({
|
|
|
129
129
|
|
|
130
130
|
To ensure data integrity, you can provide a `validate` object containing hooks for various operations (`set`, `setAll`, `delete`, `clear`, `write`). These hooks are executed immediately before the store's internal state is updated. If a validator throws an error, the operation is aborted.
|
|
131
131
|
|
|
132
|
-
|
|
132
|
+
```javascript
|
|
133
133
|
import { createObjectStore } from '@superutils/store'
|
|
134
134
|
const settingsStore = createObjectStore({
|
|
135
135
|
name: 'app-settings',
|
|
@@ -139,7 +139,7 @@ const settingsStore = createObjectStore({
|
|
|
139
139
|
},
|
|
140
140
|
validate: {
|
|
141
141
|
set([key, value]) {
|
|
142
|
-
console.log(this.size) // "this" refers to the store instance
|
|
142
|
+
console.log('size:', this.size) // "this" refers to the store instance
|
|
143
143
|
if (key !== 'theme' || ['light', 'dark', 'system'].includes(value)) return
|
|
144
144
|
// throw error to abort operation
|
|
145
145
|
throw new Error(`Invalid theme: ${value}`)
|
|
@@ -151,7 +151,7 @@ const settingsStore = createObjectStore({
|
|
|
151
151
|
},
|
|
152
152
|
})
|
|
153
153
|
settingsStore.set('theme', 'system')
|
|
154
|
-
console.log(settingsStore.get('theme')) // 'system
|
|
154
|
+
console.log(settingsStore.get('theme')) // 'system'
|
|
155
155
|
try {
|
|
156
156
|
settingsStore.set('theme', 'invalid') // throws error
|
|
157
157
|
} catch (err) {
|
|
@@ -177,7 +177,7 @@ const sub = store.subject$.subscribe(data => {
|
|
|
177
177
|
})
|
|
178
178
|
|
|
179
179
|
store.set('key', 'value')
|
|
180
|
-
|
|
180
|
+
```
|
|
181
181
|
|
|
182
182
|
### Search and Filtering
|
|
183
183
|
|
|
@@ -197,6 +197,7 @@ const store = createStore({
|
|
|
197
197
|
|
|
198
198
|
// Search for items using a query object
|
|
199
199
|
const searchResult = store.search({
|
|
200
|
+
asMap: false,
|
|
200
201
|
query: { category: 'electronics' },
|
|
201
202
|
})
|
|
202
203
|
console.log(searchResult) // [{ id: 1, name: 'Laptop', ... }]
|
|
@@ -243,7 +244,6 @@ if (!authStore.isAuthenticated) {
|
|
|
243
244
|
|
|
244
245
|
```typescript
|
|
245
246
|
import { createObjectStore } from '@superutils/store'
|
|
246
|
-
import fetch from '@superutils/fetch'
|
|
247
247
|
|
|
248
248
|
type UserProfile = {
|
|
249
249
|
age: number
|