mirror of
https://github.com/livebook-dev/livebook.git
synced 2024-11-15 04:15:18 +08:00
d191b7eb9d
* Set up confirmation modals * Add temporary fix for the global hook remount
34 lines
675 B
JavaScript
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}`);
|
|
}
|
|
}
|