Skip to content

Commit

Permalink
Persist documentation for Map & Set add storage and retrieval of vers…
Browse files Browse the repository at this point in the history
…ion (#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
  • Loading branch information
melutovich authored Aug 20, 2024
1 parent 69112dc commit 23086be
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions docs/integrations/persisting-store-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand Down

0 comments on commit 23086be

Please sign in to comment.