Move database creation into Backend
This commit is contained in:
parent
8095d9138c
commit
c193a703cc
@ -24,6 +24,7 @@
|
||||
* AudioUriBuilder
|
||||
* BackendApiForwarder
|
||||
* ClipboardMonitor
|
||||
* Database
|
||||
* JsonSchema
|
||||
* Mecab
|
||||
* Translator
|
||||
@ -43,7 +44,8 @@
|
||||
|
||||
class Backend {
|
||||
constructor() {
|
||||
this.translator = new Translator();
|
||||
this.database = new Database();
|
||||
this.translator = new Translator(this.database);
|
||||
this.anki = new AnkiNull();
|
||||
this.mecab = new Mecab();
|
||||
this.clipboardMonitor = new ClipboardMonitor({getClipboard: this._onApiClipboardGet.bind(this)});
|
||||
@ -107,6 +109,7 @@ class Backend {
|
||||
}
|
||||
|
||||
async prepare() {
|
||||
await this.database.prepare();
|
||||
await this.translator.prepare();
|
||||
|
||||
this.optionsSchema = await requestJson(chrome.runtime.getURL('/bg/data/options-schema.json'), 'GET');
|
||||
|
@ -17,7 +17,6 @@
|
||||
*/
|
||||
|
||||
/* global
|
||||
* Database
|
||||
* Deinflector
|
||||
* dictEnabledSet
|
||||
* dictTagBuildSource
|
||||
@ -34,24 +33,17 @@
|
||||
*/
|
||||
|
||||
class Translator {
|
||||
constructor() {
|
||||
this.database = null;
|
||||
constructor(database) {
|
||||
this.database = database;
|
||||
this.deinflector = null;
|
||||
this.tagCache = new Map();
|
||||
}
|
||||
|
||||
async prepare() {
|
||||
if (!this.database) {
|
||||
this.database = new Database();
|
||||
await this.database.prepare();
|
||||
}
|
||||
|
||||
if (!this.deinflector) {
|
||||
const url = chrome.runtime.getURL('/bg/lang/deinflect.json');
|
||||
const reasons = await requestJson(url, 'GET');
|
||||
this.deinflector = new Deinflector(reasons);
|
||||
}
|
||||
}
|
||||
|
||||
async purgeDatabase() {
|
||||
this.tagCache.clear();
|
||||
|
Loading…
Reference in New Issue
Block a user