From 31d9ea53b946c9b89668145af83a3926ff5f7e61 Mon Sep 17 00:00:00 2001 From: the-djmaze <3752035+the-djmaze@users.noreply.github.com> Date: Mon, 21 Sep 2020 22:28:12 +0200 Subject: [PATCH] Update Client.js This change made on mobile as test. --- dev/Storage/Client.js | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/dev/Storage/Client.js b/dev/Storage/Client.js index 8b37e9c6b..b5c564ed7 100644 --- a/dev/Storage/Client.js +++ b/dev/Storage/Client.js @@ -1,6 +1,14 @@ import { CLIENT_SIDE_STORAGE_INDEX_NAME } from 'Common/Consts'; -const storage = localStorage; +const storage = localStorage, +getStorage = () => { + try { + const value = storage.getItem(CLIENT_SIDE_STORAGE_INDEX_NAME) || null; + return null == value ? null : JSON.parse(value); + } catch (e) { + return null; + } +}; /** * @param {number} key @@ -8,20 +16,15 @@ const storage = localStorage; * @returns {boolean} */ export function set(key, data) { - let storageResult = null; - try { - const storageValue = storage.getItem(CLIENT_SIDE_STORAGE_INDEX_NAME) || null; - storageResult = null === storageValue ? null : JSON.parse(storageValue); - } catch (e) {} // eslint-disable-line no-empty - - (storageResult || (storageResult = {}))['p' + key] = data; + const storageResult = getStorage() || {}; + storageResult['p' + key] = data; try { storage.setItem(CLIENT_SIDE_STORAGE_INDEX_NAME, JSON.stringify(storageResult)); return true; - } catch (e) {} // eslint-disable-line no-empty - - return false; + } catch (e) { + return false; + } } /** @@ -31,11 +34,10 @@ export function set(key, data) { export function get(key) { try { key = 'p' + key; - const storageValue = storage.getItem(CLIENT_SIDE_STORAGE_INDEX_NAME) || null, - storageResult = null === storageValue ? null : JSON.parse(storageValue); + const storageResult = getStorage(); return storageResult && null != storageResult[key] ? storageResult[key] : null; - } catch (e) {} // eslint-disable-line no-empty - - return null; + } catch (e) { + return null; + } }