mirror of
https://github.com/pmndrs/zustand.git
synced 2025-12-08 19:45:52 +00:00
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:
parent
69112dcfff
commit
23086be4ad
@ -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()),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user