This commit is contained in:
Alex Yatskov 2017-03-26 22:42:17 -07:00
parent 5de3005d0b
commit 3b0aa88de1
3 changed files with 31 additions and 30 deletions

View File

@ -189,37 +189,37 @@ window.yomichan = new class {
}
}
onMessage(request, sender, callback) {
const handlers = new class {
optionsGet({callback}) {
onMessage({action, params}, sender, callback) {
const handlers = {
optionsGet: ({callback}) => {
promiseCallback(optionsLoad(), callback);
}
},
kanjiFind({text, callback}) {
kanjiFind: ({text, callback}) => {
promiseCallback(this.kanjiFind(text), callback);
}
},
termsFind({text, callback}) {
termsFind: ({text, callback}) => {
promiseCallback(this.termsFind(text), callback);
}
},
templateRender({template, data, callback}) {
templateRender: ({template, data, callback}) => {
promiseCallback(this.templateRender(template, data), callback);
}
},
definitionAdd({definition, mode, callback}) {
definitionAdd: ({definition, mode, callback}) => {
promiseCallback(this.definitionAdd(definition, mode), callback);
}
},
definitionsAddable({definitions, modes, callback}) {
definitionsAddable: ({definitions, modes, callback}) => {
promiseCallback(this.definitionsAddable(definitions, modes), callback);
}
};
const {action, params} = request, method = handlers[action];
if (typeof(method) === 'function') {
const handler = handlers[action];
if (handler) {
params.callback = callback;
method.call(this, params);
handler(params);
}
return true;

View File

@ -57,23 +57,24 @@ window.displayFrame = new class extends Display {
}
onMessage(e) {
const handlers = new class {
showTermDefs({definitions, options, context}) {
const handlers = {
showTermDefs: ({definitions, options, context}) => {
this.showTermDefs(definitions, options, context);
}
},
showKanjiDefs({definitions, options, context}) {
showKanjiDefs: ({definitions, options, context}) => {
this.showKanjiDefs(definitions, options, context);
}
},
showOrphaned() {
showOrphaned: () => {
this.showOrphaned();
}
};
const {action, params} = e.originalEvent.data, method = handlers[action];
if (typeof(method) === 'function') {
method.call(this, params);
const {action, params} = e.originalEvent.data;
const handler = handlers[action];
if (handler) {
handler(params);
}
}
};

View File

@ -116,8 +116,8 @@ window.driver = new class {
}
onBgMessage({action, params}, sender, callback) {
const handlers = new class {
optionsSet(options) {
const handlers = {
optionsSet: options => {
this.options = options;
if (!this.options.enable) {
this.searchClear();
@ -125,9 +125,9 @@ window.driver = new class {
}
};
const method = handlers[action];
if (typeof(method) === 'function') {
method.call(this, params);
const handler = handlers[action];
if (handler) {
handler(params);
}
callback();