Persist documentation for Map & Set add storage and retrieval of version (#2692)

* Persist documentation for Map & Set add storage and retrieval of version

--HG--
branch : discussion-2689-persist-doc-map-and-set-missing-version

* Persist documentation for Map & set improve getItem to include version only when present by way of spread operator on existingValue

--HG--
branch : discussion-2689-persist-doc-map-and-set-missing-version
This commit is contained in:
melutovich 2024-08-21 02:52:45 +03:00 committed by GitHub
parent 69112dcfff
commit 23086be4ad
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -783,17 +783,19 @@ interface BearState {
getItem: (name) => {
const str = localStorage.getItem(name);
if (!str) return null;
const { state } = JSON.parse(str);
const existingValue = JSON.parse(str);
return {
...existingValue,
state: {
...state,
transactions: new Map(state.transactions),
},
...existingValue.state,
transactions: new Map(existingValue.state.transactions),
}
}
},
setItem: (name, newValue: StorageValue<BearState>) => {
// functions cannot be JSON encoded
const str = JSON.stringify({
...newValue,
state: {
...newValue.state,
transactions: Array.from(newValue.state.transactions.entries()),