From b74acf6f6aef4e4241ba62c72ed8ddb21adc751d Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Sun, 17 Jun 2018 22:02:32 +0900 Subject: Use await/async on shared directory --- src/shared/settings/storage.js | 42 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 22 deletions(-) (limited to 'src/shared/settings/storage.js') diff --git a/src/shared/settings/storage.js b/src/shared/settings/storage.js index 9b8045d..87843ed 100644 --- a/src/shared/settings/storage.js +++ b/src/shared/settings/storage.js @@ -1,30 +1,28 @@ import DefaultSettings from './default'; import * as settingsValues from './values'; -const loadRaw = () => { - return browser.storage.local.get('settings').then(({ settings }) => { - if (!settings) { - return DefaultSettings; - } - return Object.assign({}, DefaultSettings, settings); - }); +const loadRaw = async() => { + let { settings } = await browser.storage.local.get('settings'); + if (!settings) { + return DefaultSettings; + } + return Object.assign({}, DefaultSettings, settings); }; -const loadValue = () => { - return loadRaw().then((settings) => { - let value = JSON.parse(DefaultSettings.json); - if (settings.source === 'json') { - value = settingsValues.valueFromJson(settings.json); - } else if (settings.source === 'form') { - value = settingsValues.valueFromForm(settings.form); - } - if (!value.properties) { - value.properties = {}; - } - return Object.assign({}, - settingsValues.valueFromJson(DefaultSettings.json), - value); - }); +const loadValue = async() => { + let settings = await loadRaw(); + let value = JSON.parse(DefaultSettings.json); + if (settings.source === 'json') { + value = settingsValues.valueFromJson(settings.json); + } else if (settings.source === 'form') { + value = settingsValues.valueFromForm(settings.form); + } + if (!value.properties) { + value.properties = {}; + } + return Object.assign({}, + settingsValues.valueFromJson(DefaultSettings.json), + value); }; const save = (settings) => { -- cgit v1.2.3