livebook/assets/js/lib/storage.js
Jonatan Kłosko d191b7eb9d
Set up confirmation modals (#1033)
* Set up confirmation modals

* Add temporary fix for the global hook remount
2022-03-02 00:26:40 +01:00

34 lines
675 B
JavaScript

const PREFIX = "livebook:";
/**
* Loads value from local storage.
*/
export function load(key) {
try {
const json = localStorage.getItem(PREFIX + key);
if (json) {
return JSON.parse(json);
}
} catch (error) {
console.error(
`Failed to load from local storage, reason: ${error.message}`
);
}
return undefined;
}
/**
* Stores value in local storage.
*
* The value is serialized as JSON.
*/
export function store(key, value) {
try {
const json = JSON.stringify(value);
localStorage.setItem(PREFIX + key, json);
} catch (error) {
console.error(`Failed to write to local storage, reason: ${error.message}`);
}
}