aboutsummaryrefslogtreecommitdiff
path: root/ext/js/language/dictionary-importer-threaded.js
diff options
context:
space:
mode:
Diffstat (limited to 'ext/js/language/dictionary-importer-threaded.js')
-rw-r--r--ext/js/language/dictionary-importer-threaded.js34
1 files changed, 19 insertions, 15 deletions
diff --git a/ext/js/language/dictionary-importer-threaded.js b/ext/js/language/dictionary-importer-threaded.js
index a251906b..c9b6fb24 100644
--- a/ext/js/language/dictionary-importer-threaded.js
+++ b/ext/js/language/dictionary-importer-threaded.js
@@ -20,7 +20,11 @@
*/
class DictionaryImporterThreaded {
- importDictionary(archiveContent, details, onProgress) {
+ constructor(onProgress) {
+ this._onProgress = onProgress;
+ }
+
+ importDictionary(archiveContent, details) {
return new Promise((resolve, reject) => {
const dictionaryImporterMediaLoader = new DictionaryImporterMediaLoader();
const worker = new Worker('/js/language/dictionary-importer-worker-main.js', {});
@@ -30,13 +34,13 @@ class DictionaryImporterThreaded {
case 'complete':
worker.removeEventListener('message', onMessage);
worker.terminate();
- this._onComplete(params, resolve, reject);
+ this._onMessageComplete(params, resolve, reject);
break;
case 'progress':
- this._onProgress(params, onProgress);
+ this._onMessageProgress(params);
break;
case 'getImageResolution':
- this._onGetImageResolution(params, worker, dictionaryImporterMediaLoader);
+ this._onMessageGetImageResolution(params, worker, dictionaryImporterMediaLoader);
break;
}
};
@@ -50,7 +54,7 @@ class DictionaryImporterThreaded {
// Private
- _onComplete(params, resolve, reject) {
+ _onMessageComplete(params, resolve, reject) {
const {error} = params;
if (typeof error !== 'undefined') {
reject(deserializeError(error));
@@ -59,19 +63,13 @@ class DictionaryImporterThreaded {
}
}
- _formatResult(data) {
- const {result, errors} = data;
- const errors2 = errors.map((error) => deserializeError(error));
- return {result, errors: errors2};
- }
-
- _onProgress(params, onProgress) {
- if (typeof onProgress !== 'function') { return; }
+ _onMessageProgress(params) {
+ if (typeof this._onProgress !== 'function') { return; }
const {args} = params;
- onProgress(...args);
+ this._onProgress(...args);
}
- async _onGetImageResolution(params, worker, dictionaryImporterMediaLoader) {
+ async _onMessageGetImageResolution(params, worker, dictionaryImporterMediaLoader) {
const {id, mediaType, content} = params;
let response;
try {
@@ -82,4 +80,10 @@ class DictionaryImporterThreaded {
}
worker.postMessage({action: 'getImageResolution.response', params: response});
}
+
+ _formatResult(data) {
+ const {result, errors} = data;
+ const errors2 = errors.map((error) => deserializeError(error));
+ return {result, errors: errors2};
+ }
}