aboutsummaryrefslogtreecommitdiff
path: root/src/settings/actions
diff options
context:
space:
mode:
Diffstat (limited to 'src/settings/actions')
-rw-r--r--src/settings/actions/index.ts24
-rw-r--r--src/settings/actions/setting.ts39
2 files changed, 34 insertions, 29 deletions
diff --git a/src/settings/actions/index.ts b/src/settings/actions/index.ts
index dfa41c4..6b06ef8 100644
--- a/src/settings/actions/index.ts
+++ b/src/settings/actions/index.ts
@@ -1,12 +1,14 @@
import {
- JSONTextSettings, FormSettings, SettingSource,
-} from '../../shared/SettingData';
+ JSONTextSettings,
+ FormSettings,
+ SettingSource,
+} from "../../shared/SettingData";
// Settings
-export const SETTING_SET_SETTINGS = 'setting.set.settings';
-export const SETTING_SHOW_ERROR = 'setting.show.error';
-export const SETTING_SWITCH_TO_FORM = 'setting.switch.to.form';
-export const SETTING_SWITCH_TO_JSON = 'setting.switch.to.json';
+export const SETTING_SET_SETTINGS = "setting.set.settings";
+export const SETTING_SHOW_ERROR = "setting.show.error";
+export const SETTING_SWITCH_TO_FORM = "setting.switch.to.form";
+export const SETTING_SWITCH_TO_JSON = "setting.switch.to.json";
interface SettingSetSettingsAcion {
type: typeof SETTING_SET_SETTINGS;
@@ -23,14 +25,16 @@ interface SettingShowErrorAction {
interface SettingSwitchToFormAction {
type: typeof SETTING_SWITCH_TO_FORM;
- form: FormSettings,
+ form: FormSettings;
}
interface SettingSwitchToJsonAction {
type: typeof SETTING_SWITCH_TO_JSON;
- json: JSONTextSettings,
+ json: JSONTextSettings;
}
export type SettingAction =
- SettingSetSettingsAcion | SettingShowErrorAction |
- SettingSwitchToFormAction | SettingSwitchToJsonAction;
+ | SettingSetSettingsAcion
+ | SettingShowErrorAction
+ | SettingSwitchToFormAction
+ | SettingSwitchToJsonAction;
diff --git a/src/settings/actions/setting.ts b/src/settings/actions/setting.ts
index 93ca5f8..e880ae4 100644
--- a/src/settings/actions/setting.ts
+++ b/src/settings/actions/setting.ts
@@ -1,15 +1,17 @@
-import * as actions from './index';
-import * as storages from '../storage';
+import * as actions from "./index";
+import * as storages from "../storage";
import SettingData, {
- JSONTextSettings, FormSettings, SettingSource,
-} from '../../shared/SettingData';
+ JSONTextSettings,
+ FormSettings,
+ SettingSource,
+} from "../../shared/SettingData";
-const load = async(): Promise<actions.SettingAction> => {
+const load = async (): Promise<actions.SettingAction> => {
const data = await storages.load();
return set(data);
};
-const save = async(data: SettingData): Promise<actions.SettingAction> => {
+const save = async (data: SettingData): Promise<actions.SettingAction> => {
try {
if (data.getSource() === SettingSource.JSON) {
// toSettings exercise validation
@@ -26,7 +28,6 @@ const save = async(data: SettingData): Promise<actions.SettingAction> => {
return set(data);
};
-
const switchToForm = (json: JSONTextSettings): actions.SettingAction => {
try {
// toSettings exercise validation
@@ -55,18 +56,18 @@ const switchToJson = (form: FormSettings): actions.SettingAction => {
const set = (data: SettingData): actions.SettingAction => {
const source = data.getSource();
switch (source) {
- case SettingSource.JSON:
- return {
- type: actions.SETTING_SET_SETTINGS,
- source: source,
- json: data.getJSON(),
- };
- case SettingSource.Form:
- return {
- type: actions.SETTING_SET_SETTINGS,
- source: source,
- form: data.getForm(),
- };
+ case SettingSource.JSON:
+ return {
+ type: actions.SETTING_SET_SETTINGS,
+ source: source,
+ json: data.getJSON(),
+ };
+ case SettingSource.Form:
+ return {
+ type: actions.SETTING_SET_SETTINGS,
+ source: source,
+ form: data.getForm(),
+ };
}
throw new Error(`unknown source: ${source}`);
};