diff options
Diffstat (limited to 'ext')
-rw-r--r-- | ext/bg/js/yomichan.js | 32 | ||||
-rw-r--r-- | ext/fg/js/display-frame.js | 19 | ||||
-rw-r--r-- | ext/fg/js/driver.js | 10 |
3 files changed, 31 insertions, 30 deletions
diff --git a/ext/bg/js/yomichan.js b/ext/bg/js/yomichan.js index cbbcae63..7a26d6c7 100644 --- a/ext/bg/js/yomichan.js +++ b/ext/bg/js/yomichan.js @@ -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; diff --git a/ext/fg/js/display-frame.js b/ext/fg/js/display-frame.js index 41c2fb53..59032d0c 100644 --- a/ext/fg/js/display-frame.js +++ b/ext/fg/js/display-frame.js @@ -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); } } }; diff --git a/ext/fg/js/driver.js b/ext/fg/js/driver.js index 036dc2d8..2324e6b2 100644 --- a/ext/fg/js/driver.js +++ b/ext/fg/js/driver.js @@ -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(); |