Files
frontend-app-learning/src/data/sessionStorage.js
leangseu-edx bce25c462a chore: update sidebar logic (#1236)
* fix: make side bar notification behave correctly

---------

Co-authored-by: Awais Ansari <awais.ansari63@gmail.com>
2023-11-22 11:46:34 -05:00

32 lines
874 B
JavaScript

// This file holds some convenience methods for dealing with sessionStorage. Unlike localStorage that never expires,
// sessionStorage is cleared when the browser tab is closed since the page session ends
//
// NOTE: These storage keys are not namespaced. That means that it's shared for the current fully
// qualified domain. Namespacing could be added, but we'll cross that bridge when we need it.
function getSessionStorage(key) {
try {
if (global.sessionStorage) {
return global.sessionStorage.getItem(key);
}
} catch (e) {
// If this fails for some reason, just return null.
}
return null;
}
function setSessionStorage(key, value) {
try {
if (global.sessionStorage) {
global.sessionStorage.setItem(key, value);
}
} catch (e) {
// If this fails, just bail.
}
}
export {
getSessionStorage,
setSessionStorage,
};