aboutsummaryrefslogtreecommitdiff
path: root/ext/fg/js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-07-11 15:20:00 -0400
committerGitHub <noreply@github.com>2020-07-11 15:20:00 -0400
commitec42a7e4d61dc30c2839a7ff7be44bec131127a5 (patch)
tree73d0221a3aebab8bf786012d1a61f14483b59df8 /ext/fg/js
parent8389cd8ba27f328123fb73e72b24e69a4a6de2c1 (diff)
Message handler refactor (#660)
* Refactor searchQueryUpdate action * Use standard message handler style * Use name "promiseOrResult" for consistency * Use standard message handler convention for Yomichan message handlers * Use common message handler invoker
Diffstat (limited to 'ext/fg/js')
-rw-r--r--ext/fg/js/frontend.js20
1 files changed, 1 insertions, 19 deletions
diff --git a/ext/fg/js/frontend.js b/ext/fg/js/frontend.js
index 1618fa12..aa03d4b5 100644
--- a/ext/fg/js/frontend.js
+++ b/ext/fg/js/frontend.js
@@ -211,25 +211,7 @@ class Frontend {
_onRuntimeMessage({action, params}, sender, callback) {
const messageHandler = this._runtimeMessageHandlers.get(action);
if (typeof messageHandler === 'undefined') { return false; }
-
- const {handler, async} = messageHandler;
-
- try {
- const promiseOrResult = handler(params, sender);
- if (async) {
- promiseOrResult.then(
- (result) => callback({result}),
- (error) => callback({error: errorToJson(error)})
- );
- return true;
- } else {
- callback({result: promiseOrResult});
- return false;
- }
- } catch (error) {
- callback({error: errorToJson(error)});
- return false;
- }
+ return yomichan.invokeMessageHandler(messageHandler, params, callback, sender);
}
_onZoomChanged({newZoomFactor}) {