summaryrefslogtreecommitdiff
path: root/ext/js/background/backend.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-03-07 15:53:43 -0500
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-03-07 15:53:43 -0500
commit8694e94f294997166b5874094ebc4f516d423e3b (patch)
tree10eda2ebc10736a05d615f8073babc316b0d2cbe /ext/js/background/backend.js
parentd25a54a60d3b43095c556d2d50817682aad73d4f (diff)
Split dictionary order and index sorting (#1491)
* Refactor expression comparison * Rename function * Add dictionary index sorting * Update test data # Conflicts: # ext/js/language/translator.js # test/data/test-translator-data.json
Diffstat (limited to 'ext/js/background/backend.js')
-rw-r--r--ext/js/background/backend.js26
1 files changed, 7 insertions, 19 deletions
diff --git a/ext/js/background/backend.js b/ext/js/background/backend.js
index 715b916b..9b35e9b1 100644
--- a/ext/js/background/backend.js
+++ b/ext/js/background/backend.js
@@ -1891,30 +1891,18 @@ class Backend {
}
_getTranslatorEnabledDictionaryMap(options) {
- const dictionaries = [];
- const {dictionaries: optionsDictionaries} = options;
- for (const title in optionsDictionaries) {
- if (!Object.prototype.hasOwnProperty.call(optionsDictionaries, title)) { continue; }
- const dictionary = optionsDictionaries[title];
+ const enabledDictionaryMap = new Map();
+ const {dictionaries} = options;
+ for (const title in dictionaries) {
+ if (!Object.prototype.hasOwnProperty.call(dictionaries, title)) { continue; }
+ const dictionary = dictionaries[title];
if (!dictionary.enabled) { continue; }
- dictionaries.push({
- title,
- index: dictionaries.length,
+ enabledDictionaryMap.set(title, {
+ index: enabledDictionaryMap.size,
priority: dictionary.priority,
allowSecondarySearches: dictionary.allowSecondarySearches
});
}
-
- dictionaries.sort((v1, v2) => {
- const i = v2.priority - v1.priority;
- return i !== 0 ? i : v1.index - v2.index;
- });
-
- const enabledDictionaryMap = new Map();
- for (let i = 0, ii = dictionaries.length; i < ii; ++i) {
- const {title, allowSecondarySearches} = dictionaries[i];
- enabledDictionaryMap.set(title, {order: i, allowSecondarySearches});
- }
return enabledDictionaryMap;
}