mirror of
https://github.com/EnixCoda/Gitako.git
synced 2026-03-11 08:54:44 +00:00
refactor: config and storage
This commit is contained in:
parent
baa41b3084
commit
e15bab98fc
2 changed files with 6 additions and 7 deletions
|
|
@ -1,4 +1,3 @@
|
|||
import { pick } from 'utils/general'
|
||||
import storageHelper from 'utils/storageHelper'
|
||||
|
||||
export type Config = {
|
||||
|
|
@ -48,16 +47,16 @@ async function getAll(): Promise<Config> {
|
|||
return applyDefaultConfigs(await storageHelper.get(configKeyArray))
|
||||
}
|
||||
|
||||
async function getOne(key: keyof Config) {
|
||||
async function getOne(key: configKeys) {
|
||||
return (await getAll())[key]
|
||||
}
|
||||
|
||||
async function set(partialConfig: Partial<Config>) {
|
||||
return await storageHelper.set(pick(partialConfig, configKeyArray))
|
||||
async function setAll(partialConfig: Partial<Config>) {
|
||||
return await storageHelper.set(partialConfig)
|
||||
}
|
||||
|
||||
async function setOne(key: configKeys, value: any) {
|
||||
return await set({
|
||||
return await setAll({
|
||||
[key]: value,
|
||||
})
|
||||
}
|
||||
|
|
@ -65,6 +64,6 @@ async function setOne(key: configKeys, value: any) {
|
|||
export default {
|
||||
getAll,
|
||||
getOne,
|
||||
set,
|
||||
setAll,
|
||||
setOne,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
const localStorage = chrome.storage.local
|
||||
|
||||
function get(mapping: string | string[] | object): Promise<any> {
|
||||
function get(mapping: string[] | null): Promise<any> {
|
||||
return new Promise(resolve => localStorage.get(mapping, resolve))
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue