default property values
This commit is contained in:
parent
f4499b840c
commit
fe48dce1c9
5 changed files with 24 additions and 12 deletions
15
src/shared/settings/properties.js
Normal file
15
src/shared/settings/properties.js
Normal file
|
@ -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 propertyTypes from './property-types';
|
||||
|
||||
const VALID_TOP_KEYS = ['keymaps', 'search', 'blacklist', 'properties'];
|
||||
const VALID_OPERATION_VALUES = Object.keys(operations).map((key) => {
|
||||
|
@ -51,10 +50,10 @@ const validateSearch = (search) => {
|
|||
|
||||
const validateProperties = (properties) => {
|
||||
for (let name of Object.keys(properties)) {
|
||||
if (!propertyTypes[name]) {
|
||||
if (!properties.types[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}"`);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import * as properties from './properties';
|
||||
|
||||
const operationFromFormName = (name) => {
|
||||
let [type, argStr] = name.split('?');
|
||||
let args = {};
|
||||
|
@ -81,11 +83,13 @@ const formFromValue = (value, allowedOps) => {
|
|||
}
|
||||
}
|
||||
|
||||
let formProperties = Object.assign({}, properties.defaults, value.properties);
|
||||
|
||||
return {
|
||||
keymaps,
|
||||
search,
|
||||
blacklist: value.blacklist,
|
||||
properties: value.properties,
|
||||
properties: formProperties,
|
||||
};
|
||||
};
|
||||
|
||||
|
|
Reference in a new issue