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

View File

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

View File

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