summaryrefslogtreecommitdiff
path: root/ext/bg/js
diff options
context:
space:
mode:
Diffstat (limited to 'ext/bg/js')
-rw-r--r--ext/bg/js/dictionary.js38
-rw-r--r--ext/bg/js/util.js4
2 files changed, 25 insertions, 17 deletions
diff --git a/ext/bg/js/dictionary.js b/ext/bg/js/dictionary.js
index a2a4047a..936f3dd8 100644
--- a/ext/bg/js/dictionary.js
+++ b/ext/bg/js/dictionary.js
@@ -33,7 +33,9 @@ class Dictionary {
this.db.version(1).stores({
terms: '++id, dictionary, expression, reading',
kanji: '++, dictionary, character',
- entities: '++, dictionary, name',
+ entities: '++, dictionary',
+ termDicts: '++, dictionary',
+ kanjiDicts: '++, dictionary, version',
meta: 'name, value',
});
}
@@ -135,22 +137,24 @@ class Dictionary {
return Promise.reject('database not initialized');
}
- const indexLoaded = (dictionary, entities) => {
- this.entities = entities || {};
-
- const rows = [];
- for (const name in entities || {}) {
- rows.push({
- dictionary,
- name,
- value: entities[name]
- });
- }
+ const indexLoaded = (dictionary, version, entities) => {
+ return this.db.termDicts.add({dictionary, version}).then(() => {
+ this.entities = entities || {};
+
+ const rows = [];
+ for (const name in entities || {}) {
+ rows.push({
+ dictionary,
+ name,
+ value: entities[name]
+ });
+ }
- return this.db.entities.bulkAdd(rows);
+ return this.db.entities.bulkAdd(rows);
+ });
};
- const entriesLoaded = (dictionary, entries, total, current) => {
+ const entriesLoaded = (dictionary, version, entries, total, current) => {
const rows = [];
for (const [expression, reading, tags, ...glossary] of entries) {
rows.push({
@@ -177,7 +181,11 @@ class Dictionary {
return Promise.reject('database not initialized');
}
- const entriesLoaded = (dictionary, entries, total, current) => {
+ const indexLoaded = (dictionary, version) => {
+ return this.db.kanjiDicts.add({dictionary, version});
+ };
+
+ const entriesLoaded = (dictionary, version, entries, total, current) => {
const rows = [];
for (const [character, onyomi, kunyomi, tags, ...meanings] of entries) {
rows.push({
diff --git a/ext/bg/js/util.js b/ext/bg/js/util.js
index 9b17f43c..ac365135 100644
--- a/ext/bg/js/util.js
+++ b/ext/bg/js/util.js
@@ -121,7 +121,7 @@ function importJsonDb(indexUrl, indexLoaded, entriesLoaded) {
const indexDir = indexUrl.slice(0, indexUrl.lastIndexOf('/'));
return loadJson(indexUrl).then(index => {
if (indexLoaded !== null) {
- return indexLoaded(index.title, index.entities, index.banks).then(() => index);
+ return indexLoaded(index.title, index.version, index.entities, index.banks).then(() => index);
}
return index;
@@ -129,7 +129,7 @@ function importJsonDb(indexUrl, indexLoaded, entriesLoaded) {
const loaders = [];
for (let i = 1; i <= index.banks; ++i) {
const bankUrl = `${indexDir}/bank_${i}.json`;
- loaders.push(() => loadJson(bankUrl).then(entries => entriesLoaded(index.title, entries, index.banks, i)));
+ loaders.push(() => loadJson(bankUrl).then(entries => entriesLoaded(index.title, index.version, entries, index.banks, i)));
}
let chain = Promise.resolve();