Skip to content

Commit

Permalink
Some code cleanups (bailout, catch, useSelect)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsnajdr committed Feb 6, 2023
1 parent a23e423 commit c2086ea
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions packages/editor/src/components/local-autosave-monitor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -73,7 +75,7 @@ function useAutosaveNotice() {

try {
localAutosave = JSON.parse( localAutosave );
} catch ( error ) {
} catch {
// Not usable if it can't be parsed.
return;
}
Expand Down Expand Up @@ -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,
[]
);

Expand Down

0 comments on commit c2086ea

Please sign in to comment.