refactor: memo editor components (#1625)

This commit is contained in:
boojack
2023-05-03 19:13:37 +08:00
committed by GitHub
parent 8911ea1619
commit e3496ac1a2
12 changed files with 217 additions and 191 deletions

View File

@ -18,44 +18,43 @@ interface StorageData {
type StorageKey = keyof StorageData;
/**
* storage helper
*/
export function get(keys: StorageKey[]): Partial<StorageData> {
const data: Partial<StorageData> = {};
const storage = {
get: (keys: StorageKey[]): Partial<StorageData> => {
const data: Partial<StorageData> = {};
for (const key of keys) {
try {
const stringifyValue = localStorage.getItem(key);
if (stringifyValue !== null) {
const val = JSON.parse(stringifyValue);
data[key] = val;
for (const key of keys) {
try {
const stringifyValue = localStorage.getItem(key);
if (stringifyValue !== null) {
const val = JSON.parse(stringifyValue);
data[key] = val;
}
} catch (error: any) {
console.error("Get storage failed in ", key, error);
}
} catch (error: any) {
console.error("Get storage failed in ", key, error);
}
}
return data;
}
export function set(data: Partial<StorageData>) {
for (const key in data) {
try {
const stringifyValue = JSON.stringify(data[key as StorageKey]);
localStorage.setItem(key, stringifyValue);
} catch (error: any) {
console.error("Save storage failed in ", key, error);
return data;
},
set: (data: Partial<StorageData>) => {
for (const key in data) {
try {
const stringifyValue = JSON.stringify(data[key as StorageKey]);
localStorage.setItem(key, stringifyValue);
} catch (error: any) {
console.error("Save storage failed in ", key, error);
}
}
}
}
export function remove(keys: StorageKey[]) {
for (const key of keys) {
try {
localStorage.removeItem(key);
} catch (error: any) {
console.error("Remove storage failed in ", key, error);
},
remove: (keys: StorageKey[]) => {
for (const key of keys) {
try {
localStorage.removeItem(key);
} catch (error: any) {
console.error("Remove storage failed in ", key, error);
}
}
}
}
},
};
export default storage;