From 1699203f02cf2837706ac1fc8818120858816594 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fe=CC=81lix=20Pe=CC=81ault?= Date: Wed, 14 Sep 2022 22:15:44 +0200 Subject: [PATCH] Shorten Shop local storage store code --- src/utils/stores/shop.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/utils/stores/shop.ts b/src/utils/stores/shop.ts index 7f61f8b..7b7d636 100644 --- a/src/utils/stores/shop.ts +++ b/src/utils/stores/shop.ts @@ -18,11 +18,9 @@ export const cartId: Writable = writable(null) // Write to localStorage when changing cartId if (typeof localStorage !== 'undefined') { - const cartId = localStorage.getItem('cartId') - if (cartId) { - cartId.set(cartId) - // console.log('existing cart:', cartId) - } + const id = localStorage.getItem('cartId') + id && cartId.set(id ? id : null) + cartId.subscribe(value => localStorage.setItem('cartId', value)) }