default property values

jh-changes
Shin'ya Ueoka 7 years ago
parent f4499b840c
commit fe48dce1c9
  1. 4
      src/settings/components/index.jsx
  2. 15
      src/shared/settings/properties.js
  3. 6
      src/shared/settings/property-types.js
  4. 5
      src/shared/settings/validator.js
  5. 6
      src/shared/settings/values.js

@ -5,7 +5,7 @@ import SearchForm from './form/search-form';
import KeymapsForm from './form/keymaps-form'; import KeymapsForm from './form/keymaps-form';
import BlacklistForm from './form/blacklist-form'; import BlacklistForm from './form/blacklist-form';
import PropertiesForm from './form/properties-form'; import PropertiesForm from './form/properties-form';
import PropertyTypes from 'shared/settings/property-types'; import * as properties from 'shared/settings/properties';
import * as settingActions from 'settings/actions/setting'; import * as settingActions from 'settings/actions/setting';
import * as validator from 'shared/settings/validator'; import * as validator from 'shared/settings/validator';
import * as settingsValues from 'shared/settings/values'; import * as settingsValues from 'shared/settings/values';
@ -70,7 +70,7 @@ class SettingsComponent extends Component {
<fieldset> <fieldset>
<legend>Properties</legend> <legend>Properties</legend>
<PropertiesForm <PropertiesForm
types={PropertyTypes} types={properties.types}
value={this.state.settings.form.properties} value={this.state.settings.form.properties}
onChange={value => this.bindForm('properties', value)} onChange={value => this.bindForm('properties', value)}
/> />

@ -0,0 +1,15 @@
const types = {
// TODO describe property types here
// mystr: 'string',
// mynum: 'number',
// mybool: 'boolean',
};
const defaults = {
// TODO describe property defaults values
// mystr: 'hello',
// mynum: 123,
// mybool: true,
};
export { types, defaults };

@ -1,6 +0,0 @@
export default {
// TODO describe property types here
// mystr: 'string',
// mynum: 'number',
// mybool: 'boolean',
};

@ -1,5 +1,4 @@
import operations from 'shared/operations'; import operations from 'shared/operations';
import propertyTypes from './property-types';
const VALID_TOP_KEYS = ['keymaps', 'search', 'blacklist', 'properties']; const VALID_TOP_KEYS = ['keymaps', 'search', 'blacklist', 'properties'];
const VALID_OPERATION_VALUES = Object.keys(operations).map((key) => { const VALID_OPERATION_VALUES = Object.keys(operations).map((key) => {
@ -51,10 +50,10 @@ const validateSearch = (search) => {
const validateProperties = (properties) => { const validateProperties = (properties) => {
for (let name of Object.keys(properties)) { for (let name of Object.keys(properties)) {
if (!propertyTypes[name]) { if (!properties.types[name]) {
throw new Error(`Unknown property name: "${name}"`); throw new Error(`Unknown property name: "${name}"`);
} }
if (typeof properties[name] !== propertyTypes[name]) { if (typeof properties[name] !== properties.types[name]) {
throw new Error(`Invalid type for property: "${name}"`); throw new Error(`Invalid type for property: "${name}"`);
} }
} }

@ -1,3 +1,5 @@
import * as properties from './properties';
const operationFromFormName = (name) => { const operationFromFormName = (name) => {
let [type, argStr] = name.split('?'); let [type, argStr] = name.split('?');
let args = {}; let args = {};
@ -81,11 +83,13 @@ const formFromValue = (value, allowedOps) => {
} }
} }
let formProperties = Object.assign({}, properties.defaults, value.properties);
return { return {
keymaps, keymaps,
search, search,
blacklist: value.blacklist, blacklist: value.blacklist,
properties: value.properties, properties: formProperties,
}; };
}; };