-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve setItem helper to setStorageItem
- Loading branch information
1 parent
dbe58d1
commit 852d01d
Showing
6 changed files
with
32 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** | ||
* Set item to a specified storage | ||
* @param {Object} storage Storage instance to set item into | ||
* @param {string} key | ||
* @param {string} value | ||
* @param {boolean} shouldLog | ||
*/ | ||
export const setStorageItem = (storage, key, value, shouldLog) => { | ||
// eslint-disable-next-line no-console | ||
const log = console.log.bind(console); | ||
// setItem() may throw an exception if the storage is full. | ||
try { | ||
storage.setItem(key, value); | ||
} catch (e) { | ||
if (shouldLog) { | ||
log(`Unable to set sessionStorage item due to: ${e.message}`); | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters