aboutsummaryrefslogtreecommitdiff
path: root/ext/bg/js/dictionary.js
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2016-11-05 17:30:00 -0700
committerAlex Yatskov <alex@foosoft.net>2016-11-05 17:30:00 -0700
commite2f1560afa25274d3b0efd3ce8fc8a17740ab7cc (patch)
tree711a2817fc1b2e08e25560164aa151c0e47f4351 /ext/bg/js/dictionary.js
parente4fa25894f7827c3461d2a7adc249a6f1aebc48b (diff)
WIP
Diffstat (limited to 'ext/bg/js/dictionary.js')
-rw-r--r--ext/bg/js/dictionary.js41
1 files changed, 29 insertions, 12 deletions
diff --git a/ext/bg/js/dictionary.js b/ext/bg/js/dictionary.js
index 2c9636ab..a2a4047a 100644
--- a/ext/bg/js/dictionary.js
+++ b/ext/bg/js/dictionary.js
@@ -20,7 +20,7 @@
class Dictionary {
constructor() {
this.db = null;
- this.dbVer = 3;
+ this.dbVer = 4;
this.entities = null;
}
@@ -31,10 +31,10 @@ class Dictionary {
this.db = new Dexie('dict');
this.db.version(1).stores({
- terms: '++id,expression,reading',
- entities: '++,name',
- kanji: '++,character',
- meta: 'name,value',
+ terms: '++id, dictionary, expression, reading',
+ kanji: '++, dictionary, character',
+ entities: '++, dictionary, name',
+ meta: 'name, value',
});
}
@@ -135,21 +135,31 @@ class Dictionary {
return Promise.reject('database not initialized');
}
- const entitiesLoaded = entities => {
+ const indexLoaded = (dictionary, entities) => {
this.entities = entities || {};
const rows = [];
for (const name in entities || {}) {
- rows.push({name, value: entities[name]});
+ rows.push({
+ dictionary,
+ name,
+ value: entities[name]
+ });
}
return this.db.entities.bulkAdd(rows);
};
- const entriesLoaded = (entries, total, current) => {
+ const entriesLoaded = (dictionary, entries, total, current) => {
const rows = [];
for (const [expression, reading, tags, ...glossary] of entries) {
- rows.push({expression, reading, tags, glossary});
+ rows.push({
+ dictionary,
+ expression,
+ reading,
+ tags,
+ glossary
+ });
}
return this.db.terms.bulkAdd(rows).then(() => {
@@ -159,7 +169,7 @@ class Dictionary {
});
};
- return importJsonDb(indexUrl, entitiesLoaded, entriesLoaded);
+ return importJsonDb(indexUrl, indexLoaded, entriesLoaded);
}
importKanjiDict(indexUrl, callback) {
@@ -167,10 +177,17 @@ class Dictionary {
return Promise.reject('database not initialized');
}
- const entriesLoaded = (entries, total, current) => {
+ const entriesLoaded = (dictionary, entries, total, current) => {
const rows = [];
for (const [character, onyomi, kunyomi, tags, ...meanings] of entries) {
- rows.push({character, onyomi, kunyomi, tags, meanings});
+ rows.push({
+ dictionary,
+ character,
+ onyomi,
+ kunyomi,
+ tags,
+ meanings
+ });
}
return this.db.kanji.bulkAdd(rows).then(() => {