Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 1 addition & 10 deletions src/lib/ClassPreferences.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
const VERSION = 1; // In case we ever need to invalidate these
const cache = {};
export function updatePreferences(prefs, appId, className) {
try {
localStorage.setItem(path(appId, className), JSON.stringify(prefs));
} catch {
// Fails in Safari private browsing
}
cache[appId] = cache[appId] || {};
cache[appId][className] = prefs;
}

export function getPreferences(appId, className) {
if (cache[appId] && cache[appId][className]) {
return cache[appId][className];
}
let entry;
try {
entry =
Expand All @@ -29,10 +23,7 @@ export function getPreferences(appId, className) {
return null;
}
try {
const prefs = JSON.parse(entry);
cache[appId] = cache[appId] || {};
cache[appId][className] = prefs;
return prefs;
return JSON.parse(entry);
} catch {
return null;
}
Expand Down
Loading