From c2086ea7992365f9d1536451b07de7ef34ace65d Mon Sep 17 00:00:00 2001 From: Jarda Snajdr Date: Mon, 6 Feb 2023 11:44:22 +0100 Subject: [PATCH] Some code cleanups (bailout, catch, useSelect) --- .../local-autosave-monitor/index.js | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/packages/editor/src/components/local-autosave-monitor/index.js b/packages/editor/src/components/local-autosave-monitor/index.js index d2fe87073f0fad..185497710f35f9 100644 --- a/packages/editor/src/components/local-autosave-monitor/index.js +++ b/packages/editor/src/components/local-autosave-monitor/index.js @@ -30,17 +30,19 @@ let hasStorageSupport; * reused in subsequent invocations. */ const hasSessionStorageSupport = () => { - if ( typeof hasStorageSupport === 'undefined' ) { - try { - // Private Browsing in Safari 10 and earlier will throw an error when - // attempting to set into sessionStorage. The test here is intentional in - // causing a thrown error as condition bailing from local autosave. - window.sessionStorage.setItem( '__wpEditorTestSessionStorage', '' ); - window.sessionStorage.removeItem( '__wpEditorTestSessionStorage' ); - hasStorageSupport = true; - } catch ( error ) { - hasStorageSupport = false; - } + if ( hasStorageSupport !== undefined ) { + return hasStorageSupport; + } + + try { + // Private Browsing in Safari 10 and earlier will throw an error when + // attempting to set into sessionStorage. The test here is intentional in + // causing a thrown error as condition bailing from local autosave. + window.sessionStorage.setItem( '__wpEditorTestSessionStorage', '' ); + window.sessionStorage.removeItem( '__wpEditorTestSessionStorage' ); + hasStorageSupport = true; + } catch { + hasStorageSupport = false; } return hasStorageSupport; @@ -73,7 +75,7 @@ function useAutosaveNotice() { try { localAutosave = JSON.parse( localAutosave ); - } catch ( error ) { + } catch { // Not usable if it can't be parsed. return; } @@ -176,11 +178,9 @@ function LocalAutosaveMonitor() { useAutosaveNotice(); useAutosavePurge(); - const { localAutosaveInterval } = useSelect( - ( select ) => ( { - localAutosaveInterval: - select( editorStore ).getEditorSettings().localAutosaveInterval, - } ), + const localAutosaveInterval = useSelect( + ( select ) => + select( editorStore ).getEditorSettings().localAutosaveInterval, [] );