fix: apply default config

This commit is contained in:
EnixCoda 2019-02-21 10:35:44 +08:00
parent 3b08c474f0
commit d857537f64
No known key found for this signature in database
GPG key ID: 6825847C88AA329A

View file

@ -25,11 +25,13 @@ const defaultConfigs = {
copySnippetButton: true,
}
const configKeyArray = Object.values(configKeys)
function applyDefaultConfigs(configs: Config) {
return Object.keys(configs).reduce(
return configKeyArray.reduce(
(applied, configKey) => {
const key = configKey as keyof Config
if (configs[key] === undefined) {
if (!(key in configs)) {
applied[key] = defaultConfigs[key]
} else {
applied[key] = configs[key]
@ -40,8 +42,6 @@ function applyDefaultConfigs(configs: Config) {
)
}
const configKeyArray = Object.values(configKeys)
async function getAll(): Promise<Config> {
return applyDefaultConfigs(await storageHelper.get(configKeyArray))
}