aboutsummaryrefslogtreecommitdiff
path: root/src/settings/actions/setting.js
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2017-11-26 17:04:59 +0900
committerGitHub <noreply@github.com>2017-11-26 17:04:59 +0900
commit0b37c2250e21e8c40c2c5e9abfe51903458cc94d (patch)
tree64555dd19f414d27308ec3cd43ed6bdfef7d077b /src/settings/actions/setting.js
parent2ae2d1582d6b9f8059b1a3f947d442869a14fbdc (diff)
parentc23333110d846b4bf4a76422853820875b74e93a (diff)
Merge pull request #248 from ueokande/gui-settings
GUI Settings
Diffstat (limited to 'src/settings/actions/setting.js')
-rw-r--r--src/settings/actions/setting.js19
1 files changed, 14 insertions, 5 deletions
diff --git a/src/settings/actions/setting.js b/src/settings/actions/setting.js
index c1b27c8..1d01fda 100644
--- a/src/settings/actions/setting.js
+++ b/src/settings/actions/setting.js
@@ -1,13 +1,14 @@
import actions from 'settings/actions';
import messages from 'shared/messages';
-import DefaultSettings from 'shared/default-settings';
+import DefaultSettings from 'shared/settings/default';
+import * as settingsValues from 'shared/settings/values';
const load = () => {
return browser.storage.local.get('settings').then(({ settings }) => {
- if (settings) {
- return set(settings);
+ if (!settings) {
+ return set(DefaultSettings);
}
- return set(DefaultSettings);
+ return set(Object.assign({}, DefaultSettings, settings));
}, console.error);
};
@@ -24,11 +25,19 @@ const save = (settings) => {
};
const set = (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);
+ }
+
return {
type: actions.SETTING_SET_SETTINGS,
source: settings.source,
json: settings.json,
- value: JSON.parse(settings.json),
+ form: settings.form,
+ value,
};
};