Loading in all the json blobs

This commit is contained in:
Alex Yatskov 2016-03-20 12:26:10 -07:00
parent 6f256ec25a
commit 4f19856f44

View File

@ -17,21 +17,32 @@
*/ */
class Translator { class Translator {
constructor(paths) { constructor() {
this.paths = paths this.rules = {};
this.rules = {} this.edict = {};
this.enamdict = {};
this.kanjidic = {};
this.initialized = false; this.initialized = false;
} }
initialize(callback) { initialize(paths, callback) {
if (this.initialized) { if (this.initialized) {
return; return;
} }
$.when( const loaders = [];
$.getJSON(chrome.extension.getURL(this.paths['rules'])) for (const key of ['rules', 'edict', 'enamdict', 'kanjidic']) {
).done(rules => { loaders.push(
$.getJSON(chrome.extension.getURL(paths[key]))
);
}
$.when.apply($, loaders).done((rules, edict, enamdict, kanjidic) => {
this.rules = rules; this.rules = rules;
this.edict = edict;
this.enamdict = enamdict;
this.kanjidic = kanjidic;
this.initialized = true; this.initialized = true;
if (callback) { if (callback) {
@ -41,8 +52,13 @@ class Translator {
} }
} }
let trans = new Translator({ const trans = new Translator();
rules: 'jp/data/rules.json'
});
trans.initialize(); trans.initialize({
rules: 'jp/data/rules.json',
edict: 'jp/data/edict.json',
enamdict: 'jp/data/enamdict.json',
kanjidic: 'jp/data/kanjidic.json',
}, function() {
alert('Loaded');
});