@scalar/object-utils
Advanced tools
Comparing version 1.1.6 to 1.1.7
# @scalar/object-utils | ||
## 1.1.7 | ||
### Patch Changes | ||
- 03e9bbb: Move to flatted for localstorage | ||
## 1.1.6 | ||
@@ -4,0 +10,0 @@ |
@@ -22,3 +22,4 @@ import { Mutation } from '../mutator-record/mutations.js'; | ||
redo: (uid: string) => void; | ||
loadLocalStorage: () => void; | ||
}; | ||
//# sourceMappingURL=handlers.d.ts.map |
import { Mutation } from './mutations.js'; | ||
import { useDebounceFn } from '@vueuse/core'; | ||
import { stringify, parse } from 'flatted'; | ||
import { LS_CONFIG } from './local-storage.js'; | ||
@@ -16,11 +17,27 @@ | ||
const onChange = localStorageKey | ||
? useDebounceFn(() => localStorage.setItem(localStorageKey, JSON.stringify(entityMap)), LS_CONFIG.DEBOUNCE_MS, { maxWait: LS_CONFIG.MAX_WAIT_MS }) | ||
? useDebounceFn(() => localStorage.setItem(localStorageKey, stringify(entityMap)), LS_CONFIG.DEBOUNCE_MS, { maxWait: LS_CONFIG.MAX_WAIT_MS }) | ||
: () => null; | ||
/** Adds a new item to the record of tracked items and creates a new mutation tracking instance */ | ||
const add = (item) => { | ||
entityMap[item.uid] = item; | ||
mutationMap[item.uid] = new Mutation(item, maxNumberRecords); | ||
onChange(); | ||
}; | ||
/** Load the previous entity map state from localStorage into the active state */ | ||
const loadLocalStorage = () => { | ||
if (!localStorageKey) | ||
return; | ||
const lsItem = localStorage.getItem(localStorageKey); | ||
const data = | ||
// Check for the new data structure to support the old ones | ||
lsItem?.[0] === '[' | ||
? parse(localStorage.getItem(localStorageKey) || '[{}]') | ||
: JSON.parse(localStorage.getItem(localStorageKey) || '{}'); | ||
const instances = Object.values(data); | ||
// TODO: Validation should be provided for each entity | ||
instances.forEach(add); | ||
}; | ||
return { | ||
/** Adds a new item to the record of tracked items and creates a new mutation tracking instance */ | ||
add: (item) => { | ||
entityMap[item.uid] = item; | ||
mutationMap[item.uid] = new Mutation(item, maxNumberRecords); | ||
onChange(); | ||
}, | ||
add, | ||
delete: (uid) => { | ||
@@ -61,2 +78,3 @@ delete entityMap[uid]; | ||
}, | ||
loadLocalStorage, | ||
}; | ||
@@ -63,0 +81,0 @@ } |
@@ -16,3 +16,3 @@ { | ||
], | ||
"version": "1.1.6", | ||
"version": "1.1.7", | ||
"engines": { | ||
@@ -60,2 +60,3 @@ "node": ">=18" | ||
"@vueuse/core": "^10.10.0", | ||
"flatted": "^3.3.1", | ||
"just-clone": "^6.2.0", | ||
@@ -62,0 +63,0 @@ "ts-deepmerge": "^7.0.1" |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
54127
919
4
+ Addedflatted@^3.3.1
+ Addedflatted@3.3.2(transitive)