add property to settings
This commit is contained in:
parent
fbdec04786
commit
e19f89f162
4 changed files with 61 additions and 9 deletions
6
src/shared/settings/property-types.js
Normal file
6
src/shared/settings/property-types.js
Normal file
|
@ -0,0 +1,6 @@
|
|||
export default {
|
||||
// TODO describe property types here
|
||||
// mystr: 'string',
|
||||
// mynum: 'number',
|
||||
// mybool: 'boolean',
|
||||
};
|
|
@ -1,6 +1,7 @@
|
|||
import operations from 'shared/operations';
|
||||
import propertyTypes from './property-types';
|
||||
|
||||
const VALID_TOP_KEYS = ['keymaps', 'search', 'blacklist'];
|
||||
const VALID_TOP_KEYS = ['keymaps', 'search', 'blacklist', 'properties'];
|
||||
const VALID_OPERATION_VALUES = Object.keys(operations).map((key) => {
|
||||
return operations[key];
|
||||
});
|
||||
|
@ -48,6 +49,17 @@ const validateSearch = (search) => {
|
|||
}
|
||||
};
|
||||
|
||||
const validateProperties = (properties) => {
|
||||
for (let name of Object.keys(properties)) {
|
||||
if (!propertyTypes[name]) {
|
||||
throw new Error(`Unknown property name: "${name}"`);
|
||||
}
|
||||
if (typeof properties[name] !== propertyTypes[name]) {
|
||||
throw new Error(`Invalid type for property: "${name}"`);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const validate = (settings) => {
|
||||
validateInvalidTopKeys(settings);
|
||||
if (settings.keymaps) {
|
||||
|
@ -56,6 +68,9 @@ const validate = (settings) => {
|
|||
if (settings.search) {
|
||||
validateSearch(settings.search);
|
||||
}
|
||||
if (settings.properties) {
|
||||
validateProperties(settings.properties);
|
||||
}
|
||||
};
|
||||
|
||||
export { validate };
|
||||
|
|
|
@ -44,9 +44,12 @@ const valueFromForm = (form) => {
|
|||
}
|
||||
}
|
||||
|
||||
let blacklist = form.blacklist;
|
||||
|
||||
return { keymaps, search, blacklist };
|
||||
return {
|
||||
keymaps,
|
||||
search,
|
||||
blacklist: form.blacklist,
|
||||
properties: form.properties
|
||||
};
|
||||
};
|
||||
|
||||
const jsonFromValue = (value) => {
|
||||
|
@ -78,9 +81,12 @@ const formFromValue = (value, allowedOps) => {
|
|||
}
|
||||
}
|
||||
|
||||
let blacklist = value.blacklist;
|
||||
|
||||
return { keymaps, search, blacklist };
|
||||
return {
|
||||
keymaps,
|
||||
search,
|
||||
blacklist: value.blacklist,
|
||||
properties: value.properties,
|
||||
};
|
||||
};
|
||||
|
||||
const jsonFromForm = (form) => {
|
||||
|
|
Reference in a new issue