diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2021-07-05 23:24:06 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-05 23:24:06 -0400 |
commit | e15513208584764526e2348ca7796ea665925086 (patch) | |
tree | da165d327ec0e932e61882deeddcb81cfebc09b6 /ext/js | |
parent | 54808d4a2dc077a9a35924951743de12ae464b1b (diff) |
OptionsUtil and tests updates (#1801)
* Update OptionsUtil.update to support an optional targetVersion param
* Update Anki template updates to have an explicit target version
Diffstat (limited to 'ext/js')
-rw-r--r-- | ext/js/data/options-util.js | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/ext/js/data/options-util.js b/ext/js/data/options-util.js index 42175d35..4bd5e7af 100644 --- a/ext/js/data/options-util.js +++ b/ext/js/data/options-util.js @@ -31,7 +31,7 @@ class OptionsUtil { this._optionsSchema = new JsonSchema(schema); } - async update(options) { + async update(options, targetVersion=null) { // Invalid options if (!isObject(options)) { options = {}; @@ -84,7 +84,7 @@ class OptionsUtil { } // Generic updates - options = await this._applyUpdates(options, this._getVersionUpdates()); + options = await this._applyUpdates(options, this._getVersionUpdates(targetVersion)); // Validation options = this._optionsSchema.getValidValueOrDefault(options); @@ -448,8 +448,8 @@ class OptionsUtil { return options; } - _getVersionUpdates() { - return [ + _getVersionUpdates(targetVersion) { + const result = [ {async: false, update: this._updateVersion1.bind(this)}, {async: false, update: this._updateVersion2.bind(this)}, {async: true, update: this._updateVersion3.bind(this)}, @@ -464,6 +464,10 @@ class OptionsUtil { {async: true, update: this._updateVersion12.bind(this)}, {async: true, update: this._updateVersion13.bind(this)} ]; + if (typeof targetVersion === 'number' && targetVersion < result.length) { + result.splice(targetVersion); + } + return result; } _updateVersion1(options) { |