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 1 commit
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
4 changes: 3 additions & 1 deletion 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 { state, version } = JSON.parse(str);
return {
state: {
...state,
transactions: new Map(state.transactions),
},
version
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes version: undefined if version is undefined. We also need to use object spread here like setItem.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've pushed another commit switching this as you've suggested.

}
},
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