Types src/settings
This commit is contained in:
parent
c059bf8be3
commit
e69497fab4
12 changed files with 194 additions and 117 deletions
|
@ -1,7 +1,32 @@
|
|||
export default {
|
||||
// Settings
|
||||
SETTING_SET_SETTINGS: 'setting.set.settings',
|
||||
SETTING_SHOW_ERROR: 'setting.show.error',
|
||||
SETTING_SWITCH_TO_FORM: 'setting.switch.to.form',
|
||||
SETTING_SWITCH_TO_JSON: 'setting.switch.to.json',
|
||||
};
|
||||
// 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';
|
||||
|
||||
interface SettingSetSettingsAcion {
|
||||
type: typeof SETTING_SET_SETTINGS;
|
||||
source: string;
|
||||
json: string;
|
||||
form: any;
|
||||
}
|
||||
|
||||
interface SettingShowErrorAction {
|
||||
type: typeof SETTING_SHOW_ERROR;
|
||||
error: string;
|
||||
json: string;
|
||||
}
|
||||
|
||||
interface SettingSwitchToFormAction {
|
||||
type: typeof SETTING_SWITCH_TO_FORM;
|
||||
form: any;
|
||||
}
|
||||
|
||||
interface SettingSwitchToJsonAction {
|
||||
type: typeof SETTING_SWITCH_TO_JSON;
|
||||
json: string;
|
||||
}
|
||||
|
||||
export type SettingAction =
|
||||
SettingSetSettingsAcion | SettingShowErrorAction |
|
||||
SettingSwitchToFormAction | SettingSwitchToJsonAction;
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
import actions from 'settings/actions';
|
||||
import * as validator from 'shared/settings/validator';
|
||||
import * as settingsValues from 'shared/settings/values';
|
||||
import * as settingsStorage from 'shared/settings/storage';
|
||||
import * as actions from './index';
|
||||
import * as validator from '../../shared/settings/validator';
|
||||
import * as settingsValues from '../../shared/settings/values';
|
||||
import * as settingsStorage from '../../shared/settings/storage';
|
||||
import keymaps from '../keymaps';
|
||||
|
||||
const load = async() => {
|
||||
const load = async(): Promise<actions.SettingAction> => {
|
||||
let settings = await settingsStorage.loadRaw();
|
||||
return set(settings);
|
||||
};
|
||||
|
||||
const save = async(settings) => {
|
||||
const save = async(settings: any): Promise<actions.SettingAction> => {
|
||||
try {
|
||||
if (settings.source === 'json') {
|
||||
let value = JSON.parse(settings.json);
|
||||
|
@ -26,7 +26,7 @@ const save = async(settings) => {
|
|||
return set(settings);
|
||||
};
|
||||
|
||||
const switchToForm = (json) => {
|
||||
const switchToForm = (json: string): actions.SettingAction => {
|
||||
try {
|
||||
validator.validate(JSON.parse(json));
|
||||
let form = settingsValues.formFromJson(json, keymaps.allowedOps);
|
||||
|
@ -43,7 +43,7 @@ const switchToForm = (json) => {
|
|||
}
|
||||
};
|
||||
|
||||
const switchToJson = (form) => {
|
||||
const switchToJson = (form: any): actions.SettingAction => {
|
||||
let json = settingsValues.jsonFromForm(form);
|
||||
return {
|
||||
type: actions.SETTING_SWITCH_TO_JSON,
|
||||
|
@ -51,7 +51,7 @@ const switchToJson = (form) => {
|
|||
};
|
||||
};
|
||||
|
||||
const set = (settings) => {
|
||||
const set = (settings: any): actions.SettingAction => {
|
||||
return {
|
||||
type: actions.SETTING_SET_SETTINGS,
|
||||
source: settings.source,
|
||||
|
|
Reference in a new issue