diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2021-04-03 13:02:49 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-03 13:02:49 -0400 |
commit | a9fe2d03b22a0dd5760019f1325a7a86ebb07b85 (patch) | |
tree | aa2fe04c741c82c0456f44a39139c52988b6c22d /ext/js/background | |
parent | 0d2d342cd373798e3daf42799a9f35d974db92f5 (diff) |
Update dictionary settings structure (#1587)
* Update dictionary settings structure to use an array instead of an object
* Update ensureDictionarySettings implementation
* Remove some usage of ObjectPropertyAccessor
Diffstat (limited to 'ext/js/background')
-rw-r--r-- | ext/js/background/backend.js | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/ext/js/background/backend.js b/ext/js/background/backend.js index 0fd083bf..cf8137e5 100644 --- a/ext/js/background/backend.js +++ b/ext/js/background/backend.js @@ -1271,6 +1271,17 @@ class Backend { if (!Array.isArray(array)) { throw new Error('Invalid target type'); } return array.splice(start, deleteCount, ...items); } + case 'push': + { + const {path, items} = target; + if (typeof path !== 'string') { throw new Error('Invalid path'); } + if (!Array.isArray(items)) { throw new Error('Invalid items'); } + const array = accessor.get(ObjectPropertyAccessor.getPathArray(path)); + if (!Array.isArray(array)) { throw new Error('Invalid target type'); } + const start = array.length; + array.push(...items); + return start; + } default: throw new Error(`Unknown action: ${action}`); } @@ -1358,7 +1369,7 @@ class Backend { } _isAnyDictionaryEnabled(options) { - for (const {enabled} of Object.values(options.dictionaries)) { + for (const {enabled} of options.dictionaries) { if (enabled) { return true; } @@ -1900,12 +1911,9 @@ class Backend { _getTranslatorEnabledDictionaryMap(options) { const enabledDictionaryMap = new Map(); - const {dictionaries} = options; - for (const title in dictionaries) { - if (!Object.prototype.hasOwnProperty.call(dictionaries, title)) { continue; } - const dictionary = dictionaries[title]; + for (const dictionary of options.dictionaries) { if (!dictionary.enabled) { continue; } - enabledDictionaryMap.set(title, { + enabledDictionaryMap.set(dictionary.name, { index: enabledDictionaryMap.size, priority: dictionary.priority, allowSecondarySearches: dictionary.allowSecondarySearches |