aboutsummaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2018-01-08 21:54:16 +0900
committerShin'ya Ueoka <ueokande@i-beam.org>2018-01-08 22:04:33 +0900
commit6083e70ea089fa2683741a1118be0e4e6b76f858 (patch)
treede282571884396e961a10cd447572c0fb1e370ea /src/shared
parentd23c190cad81ec2109f69b4afa957194d029caaf (diff)
separate setting actions and reducers
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/settings/storage.js31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/shared/settings/storage.js b/src/shared/settings/storage.js
new file mode 100644
index 0000000..1edb441
--- /dev/null
+++ b/src/shared/settings/storage.js
@@ -0,0 +1,31 @@
+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 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);
+ }
+ return value;
+ });
+};
+
+const save = (settings) => {
+ return browser.storage.local.set({
+ settings,
+ });
+};
+
+export { loadRaw, loadValue, save };