Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Aug 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
melutovich marked this conversation as resolved.
Show resolved Hide resolved
state: {
...newValue.state,
transactions: Array.from(newValue.state.transactions.entries()),
Expand Down