From b0036b1a08dcc1d2a324c1cbfe97b7352b7505ac Mon Sep 17 00:00:00 2001 From: Mitchell Elutovich Date: Tue, 20 Aug 2024 12:59:05 +0300 Subject: [PATCH 1/2] Persist documentation for Map & Set add storage and retrieval of version --HG-- branch : discussion-2689-persist-doc-map-and-set-missing-version --- docs/integrations/persisting-store-data.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/integrations/persisting-store-data.md b/docs/integrations/persisting-store-data.md index 8d63cc5726..461d6dd2e5 100644 --- a/docs/integrations/persisting-store-data.md +++ b/docs/integrations/persisting-store-data.md @@ -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 } }, setItem: (name, newValue: StorageValue) => { // functions cannot be JSON encoded const str = JSON.stringify({ + ...newValue, state: { ...newValue.state, transactions: Array.from(newValue.state.transactions.entries()), From 0d6e3d2ae2140a1353869a10208cc6ca8041243f Mon Sep 17 00:00:00 2001 From: Mitchell Elutovich Date: Wed, 21 Aug 2024 00:20:17 +0300 Subject: [PATCH 2/2] 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 --- docs/integrations/persisting-store-data.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/integrations/persisting-store-data.md b/docs/integrations/persisting-store-data.md index 461d6dd2e5..715c36040f 100644 --- a/docs/integrations/persisting-store-data.md +++ b/docs/integrations/persisting-store-data.md @@ -783,13 +783,13 @@ interface BearState { getItem: (name) => { const str = localStorage.getItem(name); if (!str) return null; - const { state, version } = JSON.parse(str); + const existingValue = JSON.parse(str); return { + ...existingValue, state: { - ...state, - transactions: new Map(state.transactions), - }, - version + ...existingValue.state, + transactions: new Map(existingValue.state.transactions), + } } }, setItem: (name, newValue: StorageValue) => {