aboutsummaryrefslogtreecommitdiff
path: root/ext/js/language/dictionary-importer.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-07-31 18:08:51 -0400
committerGitHub <noreply@github.com>2021-07-31 18:08:51 -0400
commit01c5c5c04bd9234c64d6f57ee0ea65b0f478a1b7 (patch)
treef262b7042bd56fc9b72efb7b42d97341efd50df9 /ext/js/language/dictionary-importer.js
parent1d6e437fb284a591fc1b7f4aec87bbc7cde5367f (diff)
Dictionary importer refactoring (#1867)
* Remove map of schemas * Don't reuse dictionary importer instances * Refactor * Update how progress callback is used
Diffstat (limited to 'ext/js/language/dictionary-importer.js')
-rw-r--r--ext/js/language/dictionary-importer.js21
1 files changed, 5 insertions, 16 deletions
diff --git a/ext/js/language/dictionary-importer.js b/ext/js/language/dictionary-importer.js
index 962758c3..f3e86654 100644
--- a/ext/js/language/dictionary-importer.js
+++ b/ext/js/language/dictionary-importer.js
@@ -22,12 +22,12 @@
*/
class DictionaryImporter {
- constructor(mediaLoader) {
+ constructor(mediaLoader, onProgress) {
this._mediaLoader = mediaLoader;
- this._schemas = new Map();
+ this._onProgress = onProgress;
}
- async importDictionary(dictionaryDatabase, archiveContent, details, onProgress) {
+ async importDictionary(dictionaryDatabase, archiveContent, details) {
if (!dictionaryDatabase) {
throw new Error('Invalid database');
}
@@ -35,7 +35,7 @@ class DictionaryImporter {
throw new Error('Database is not ready');
}
- const hasOnProgress = (typeof onProgress === 'function');
+ const hasOnProgress = (typeof this._onProgress === 'function');
// Read archive
const archive = await JSZip.loadAsync(archiveContent);
@@ -143,7 +143,7 @@ class DictionaryImporter {
loadedCount += count;
if (hasOnProgress) {
- onProgress(total, loadedCount);
+ this._onProgress(total, loadedCount);
}
}
};
@@ -178,17 +178,6 @@ class DictionaryImporter {
}
async _getSchema(fileName) {
- let schemaPromise = this._schemas.get(fileName);
- if (typeof schemaPromise !== 'undefined') {
- return schemaPromise;
- }
-
- schemaPromise = this._createSchema(fileName);
- this._schemas.set(fileName, schemaPromise);
- return schemaPromise;
- }
-
- async _createSchema(fileName) {
const schema = await this._fetchJsonAsset(fileName);
return new JsonSchema(schema);
}