aboutsummaryrefslogtreecommitdiff
path: root/src/shared/Settings.ts
diff options
context:
space:
mode:
authorShin'ya UEOKA <ueokande@i-beam.org>2019-10-05 02:06:02 +0000
committerShin'ya UEOKA <ueokande@i-beam.org>2019-10-06 12:58:59 +0000
commit574692551a27ea56660bf2061daeaa0d34beaff4 (patch)
tree414a7f1de8dfb24af45d7e392b72549bc67ad48a /src/shared/Settings.ts
parent2116ac90a6dfdb0910d7ad2896f70a052aa635cc (diff)
Make Properties class
Diffstat (limited to 'src/shared/Settings.ts')
-rw-r--r--src/shared/Settings.ts37
1 files changed, 5 insertions, 32 deletions
diff --git a/src/shared/Settings.ts b/src/shared/Settings.ts
index e2bb3f4..6250aae 100644
--- a/src/shared/Settings.ts
+++ b/src/shared/Settings.ts
@@ -1,12 +1,6 @@
-import * as PropertyDefs from './property-defs';
import Keymaps from './settings/Keymaps';
import Search from './settings/Search';
-
-export interface Properties {
- hintchars: string;
- smoothscroll: boolean;
- complete: string;
-}
+import Properties from './settings/Properties';
export default interface Settings {
keymaps: Keymaps;
@@ -15,27 +9,6 @@ export default interface Settings {
blacklist: string[];
}
-export const propertiesValueOf = (o: any): Properties => {
- let defNames = new Set(PropertyDefs.defs.map(def => def.name));
- let unknownName = Object.keys(o).find(name => !defNames.has(name));
- if (unknownName) {
- throw new TypeError(`Unknown property name: "${unknownName}"`);
- }
-
- for (let def of PropertyDefs.defs) {
- if (!Object.prototype.hasOwnProperty.call(o, def.name)) {
- continue;
- }
- if (typeof o[def.name] !== def.type) {
- throw new TypeError(`property "${def.name}" is not ${def.type}`);
- }
- }
- return {
- ...PropertyDefs.defaultValues,
- ...o,
- };
-};
-
export const blacklistValueOf = (o: any): string[] => {
if (!Array.isArray(o)) {
throw new TypeError(`"blacklist" is not an array of string`);
@@ -59,7 +32,7 @@ export const valueOf = (o: any): Settings => {
settings.search = Search.fromJSON(o.search);
break;
case 'properties':
- settings.properties = propertiesValueOf(o.properties);
+ settings.properties = Properties.fromJSON(o.properties);
break;
case 'blacklist':
settings.blacklist = blacklistValueOf(o.blacklist);
@@ -75,7 +48,7 @@ export const toJSON = (settings: Settings): any => {
return {
keymaps: settings.keymaps.toJSON(),
search: settings.search.toJSON(),
- properties: settings.properties,
+ properties: settings.properties.toJSON(),
blacklist: settings.blacklist,
};
};
@@ -156,10 +129,10 @@ export const DefaultSetting: Settings = {
'wikipedia': 'https://en.wikipedia.org/w/index.php?search={}'
}
}),
- properties: {
+ properties: Properties.fromJSON({
hintchars: 'abcdefghijklmnopqrstuvwxyz',
smoothscroll: false,
complete: 'sbh'
- },
+ }),
blacklist: []
};