Skip to content

Commit

Permalink
fix: improve storage API
Browse files Browse the repository at this point in the history
  • Loading branch information
arielsvg committed Dec 28, 2020
1 parent f7012c5 commit f34d64c
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions app/assets/javascripts/services/localStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@ export enum StorageKey {
DisableErrorReporting = 'DisableErrorReporting',
}

export type StorageValue = {
[StorageKey.DisableErrorReporting]: boolean;
}

export const storage = {
get(key: StorageKey) {
get<K extends StorageKey>(key: K): StorageValue[K] | null {
const value = localStorage.getItem(key);
return value ? JSON.parse(value) : null;
},
set(key: StorageKey, value: unknown) {
set<K extends StorageKey>(key: K, value: StorageValue[K]) {
localStorage.setItem(key, JSON.stringify(value));
},
remove(key: StorageKey) {
Expand Down

0 comments on commit f34d64c

Please sign in to comment.