From e15513208584764526e2348ca7796ea665925086 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Mon, 5 Jul 2021 23:24:06 -0400 Subject: OptionsUtil and tests updates (#1801) * Update OptionsUtil.update to support an optional targetVersion param * Update Anki template updates to have an explicit target version --- ext/js/data/options-util.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'ext/js') 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) { -- cgit v1.2.3