Cleanup
This commit is contained in:
parent
1483dd4f09
commit
9462bc397b
@ -28,21 +28,14 @@ class Dictionary {
|
|||||||
}
|
}
|
||||||
|
|
||||||
initDb() {
|
initDb() {
|
||||||
|
this.entities = null;
|
||||||
|
|
||||||
this.db = new Dexie('dict');
|
this.db = new Dexie('dict');
|
||||||
this.db.version(1).stores({
|
this.db.version(1).stores({
|
||||||
terms: '++id,expression,reading',
|
terms: '++id,expression,reading',
|
||||||
entities: '++,name',
|
entities: '++,name',
|
||||||
kanji: '++,character'
|
kanji: '++,character'
|
||||||
});
|
});
|
||||||
|
|
||||||
return this.db;
|
|
||||||
}
|
|
||||||
|
|
||||||
loadDb() {
|
|
||||||
this.db = null;
|
|
||||||
this.entities = null;
|
|
||||||
|
|
||||||
return this.initDb().open();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
findTerm(term) {
|
findTerm(term) {
|
||||||
|
@ -38,16 +38,16 @@ class Translator {
|
|||||||
this.tagMeta = tagMeta;
|
this.tagMeta = tagMeta;
|
||||||
return this.dictionary.existsDb();
|
return this.dictionary.existsDb();
|
||||||
}).then((exists) => {
|
}).then((exists) => {
|
||||||
if (exists) {
|
|
||||||
return this.dictionary.loadDb();
|
|
||||||
} else {
|
|
||||||
this.dictionary.initDb();
|
this.dictionary.initDb();
|
||||||
|
if (exists) {
|
||||||
|
return Promise.resolve();
|
||||||
|
}
|
||||||
|
|
||||||
return Promise.all([
|
return Promise.all([
|
||||||
this.dictionary.importKanjiDict('bg/data/kanjidic/index.json'),
|
this.dictionary.importKanjiDict('bg/data/kanjidic/index.json'),
|
||||||
this.dictionary.importTermDict('bg/data/edict/index.json'),
|
this.dictionary.importTermDict('bg/data/edict/index.json'),
|
||||||
this.dictionary.importTermDict('bg/data/enamdict/index.json')
|
this.dictionary.importTermDict('bg/data/enamdict/index.json')
|
||||||
]);
|
]);
|
||||||
}
|
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
this.dictionary.findTerm('猫').then((result) => {
|
this.dictionary.findTerm('猫').then((result) => {
|
||||||
console.log(result);
|
console.log(result);
|
||||||
|
Loading…
Reference in New Issue
Block a user