diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2020-08-15 17:23:09 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-15 17:23:09 -0400 |
commit | d582c7a0f856c1a352992e3d16be319a891e0202 (patch) | |
tree | cb99ef132ca06ba82b10dfc528e0291f29195de1 /ext/bg/js/backend.js | |
parent | d8649f40d59356361ce470cc220dca6c62a66388 (diff) |
JSON schema refactor (#731)
* Remove JsonSchema.clone
* Move createProxy function
* Group public properties first
* Create private version of getPropertySchema
* Mark functions as private
* Use non-static getValidValueOrDefault
* Mark private
* Make public validate function not take an info parameter
* Remove JsonSchema
* Add isValid function
* Use isValid for some tests
* Fix incorrect type
Diffstat (limited to 'ext/bg/js/backend.js')
-rw-r--r-- | ext/bg/js/backend.js | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/ext/bg/js/backend.js b/ext/bg/js/backend.js index ba87a560..65f4d6b3 100644 --- a/ext/bg/js/backend.js +++ b/ext/bg/js/backend.js @@ -24,7 +24,7 @@ * DictionaryDatabase * DictionaryImporter * Environment - * JsonSchema + * JsonSchemaValidator * Mecab * ObjectPropertyAccessor * OptionsUtil @@ -48,6 +48,7 @@ class Backend { this._clipboardMonitor = new ClipboardMonitor({getClipboard: this._onApiClipboardGet.bind(this)}); this._options = null; this._optionsSchema = null; + this._optionsSchemaValidator = new JsonSchemaValidator(); this._defaultAnkiFieldTemplates = null; this._requestBuilder = new RequestBuilder(); this._audioUriBuilder = new AudioUriBuilder({ @@ -204,7 +205,7 @@ class Backend { this._optionsSchema = await this._fetchAsset('/bg/data/options-schema.json', true); this._defaultAnkiFieldTemplates = (await this._fetchAsset('/bg/data/default-anki-field-templates.handlebars')).trim(); this._options = await OptionsUtil.load(); - this._options = JsonSchema.getValidValueOrDefault(this._optionsSchema, this._options); + this._options = this._optionsSchemaValidator.getValidValueOrDefault(this._optionsSchema, this._options); this._applyOptions('background'); @@ -235,7 +236,7 @@ class Backend { getFullOptions(useSchema=false) { const options = this._options; - return useSchema ? JsonSchema.createProxy(options, this._optionsSchema) : options; + return useSchema ? this._optionsSchemaValidator.createProxy(options, this._optionsSchema) : options; } getOptions(optionsContext, useSchema=false) { @@ -792,7 +793,7 @@ class Backend { } async _onApiSetAllSettings({value, source}) { - this._options = JsonSchema.getValidValueOrDefault(this._optionsSchema, value); + this._options = this._optionsSchemaValidator.getValidValueOrDefault(this._optionsSchema, value); await this._onApiOptionsSave({source}); } |