From a18f3be559b9a8298f93f04837d400a1fff0b2b9 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Mon, 7 Nov 2016 08:29:21 -0800 Subject: [PATCH] Renaming things --- ext/bg/background.html | 2 +- ext/bg/js/{dictionary.js => database.js} | 12 ++++++------ ext/bg/js/options-form.js | 4 ++-- ext/bg/js/translator.js | 18 +++++++++--------- 4 files changed, 18 insertions(+), 18 deletions(-) rename ext/bg/js/{dictionary.js => database.js} (98%) diff --git a/ext/bg/background.html b/ext/bg/background.html index 1bb36cf8..49fc6d0f 100644 --- a/ext/bg/background.html +++ b/ext/bg/background.html @@ -9,7 +9,7 @@ - + diff --git a/ext/bg/js/dictionary.js b/ext/bg/js/database.js similarity index 98% rename from ext/bg/js/dictionary.js rename to ext/bg/js/database.js index a7bca2f1..19e3228f 100644 --- a/ext/bg/js/dictionary.js +++ b/ext/bg/js/database.js @@ -17,14 +17,14 @@ */ -class Dictionary { +class Database { constructor() { this.db = null; this.dbVer = 6; this.entities = null; } - initDb() { + init() { if (this.db !== null) { return Promise.reject('database already initialized'); } @@ -39,8 +39,8 @@ class Dictionary { }); } - prepareDb() { - this.initDb(); + prepare() { + this.init(); return this.db.meta.get('version').then(row => { return row ? row.value : 0; @@ -56,13 +56,13 @@ class Dictionary { this.db = null; return db.delete().then(() => { - this.initDb(); + this.init(); return false; }); }); } - sealDb() { + seal() { if (this.db === null) { return Promise.reject('database not initialized'); } diff --git a/ext/bg/js/options-form.js b/ext/bg/js/options-form.js index 2f2fe6fd..14143d81 100644 --- a/ext/bg/js/options-form.js +++ b/ext/bg/js/options-form.js @@ -166,7 +166,7 @@ function populateDictionaries(opts) { const container = $('.dicts'); container.empty(); - yomichan().translator.dictionary.getDictionaries().then(rows => { + yomichan().translator.database.getDictionaries().then(rows => { rows.forEach(row => { const dictOpts = opts.dictionaries[row.title] || {enableTerms: true, enableKanji: false}; const html = Handlebars.templates['dictionary.html']({ @@ -184,7 +184,7 @@ function populateDictionaries(opts) { $('.dict-delete').click(e => { const dict = $(e.target).closest('.dict'); const title = dict.data('title'); - yomichan().translator.dictionary.deleteDictionary(title); + yomichan().translator.database.deleteDictionary(title); dict.slideUp(); }); diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js index 0a0a6109..e65acd60 100644 --- a/ext/bg/js/translator.js +++ b/ext/bg/js/translator.js @@ -21,7 +21,7 @@ class Translator { constructor() { this.loaded = false; this.tagMeta = null; - this.dictionary = new Dictionary(); + this.database = new Database(); this.deinflector = new Deinflector(); } @@ -35,7 +35,7 @@ class Translator { return loadJson('bg/data/tags.json'); }).then(tagMeta => { this.tagMeta = tagMeta; - return this.dictionary.prepareDb(); + return this.database.prepare(); }).then(exists => { if (exists) { return; @@ -62,11 +62,11 @@ class Translator { }; return Promise.all([ - this.dictionary.importDictionary('bg/data/edict/index.json', bankCallback), - this.dictionary.importDictionary('bg/data/enamdict/index.json', bankCallback), - this.dictionary.importDictionary('bg/data/kanjidic/index.json', bankCallback), + this.database.importDictionary('bg/data/edict/index.json', bankCallback), + this.database.importDictionary('bg/data/enamdict/index.json', bankCallback), + this.database.importDictionary('bg/data/kanjidic/index.json', bankCallback), ]).then(() => { - return this.dictionary.sealDb(); + return this.database.seal(); }).then(() => { if (callback) { callback({state: 'end', progress: 100.0}); @@ -84,7 +84,7 @@ class Translator { for (let i = text.length; i > 0; --i) { deinflectPromises.push( this.deinflector.deinflect(text.slice(0, i), term => { - return this.dictionary.findTerm(term).then(definitions => definitions.map(definition => definition.tags)); + return this.database.findTerm(term).then(definitions => definitions.map(definition => definition.tags)); }).then(deinflects => { const processPromises = []; for (const deinflect of deinflects) { @@ -143,7 +143,7 @@ class Translator { for (const c of text) { if (!processed[c]) { - promises.push(this.dictionary.findKanji(c).then((definitions) => definitions)); + promises.push(this.database.findKanji(c).then((definitions) => definitions)); processed[c] = true; } } @@ -152,7 +152,7 @@ class Translator { } processTerm(groups, source, tags, rules, root) { - return this.dictionary.findTerm(root).then(definitions => { + return this.database.findTerm(root).then(definitions => { for (const definition of definitions) { if (definition.id in groups) { continue;