diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2023-12-20 00:18:55 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-20 05:18:55 +0000 |
commit | 3c226215419ca815712e9568f7d871a96f5ff1cf (patch) | |
tree | 8bfe561a0d36589860b64c1758c2e29e92e7e3f4 /ext/js/display | |
parent | e0e29dc1aa0965b3e0fb97de64a27c2b695e068b (diff) |
Simplify message handlers (#396)
Diffstat (limited to 'ext/js/display')
-rw-r--r-- | ext/js/display/display-audio.js | 2 | ||||
-rw-r--r-- | ext/js/display/display.js | 33 | ||||
-rw-r--r-- | ext/js/display/search-display-controller.js | 8 |
3 files changed, 19 insertions, 24 deletions
diff --git a/ext/js/display/display-audio.js b/ext/js/display/display-audio.js index 8cd1ccc3..30cf2b92 100644 --- a/ext/js/display/display-audio.js +++ b/ext/js/display/display-audio.js @@ -89,7 +89,7 @@ export class DisplayAudio { ['playAudioFromSource', this._onHotkeyActionPlayAudioFromSource.bind(this)] ]); this._display.registerDirectMessageHandlers([ - ['Display.clearAutoPlayTimer', {async: false, handler: this._onMessageClearAutoPlayTimer.bind(this)}] + ['Display.clearAutoPlayTimer', this._onMessageClearAutoPlayTimer.bind(this)] ]); /* eslint-enable no-multi-spaces */ this._display.on('optionsUpdated', this._onOptionsUpdated.bind(this)); diff --git a/ext/js/display/display.js b/ext/js/display/display.js index d7b8f898..79cf79a8 100644 --- a/ext/js/display/display.js +++ b/ext/js/display/display.js @@ -207,15 +207,15 @@ export class Display extends EventDispatcher { ['previousEntryDifferentDictionary', () => { this._focusEntryWithDifferentDictionary(-1, true); }] ]); this.registerDirectMessageHandlers([ - ['Display.setOptionsContext', {async: true, handler: this._onMessageSetOptionsContext.bind(this)}], - ['Display.setContent', {async: false, handler: this._onMessageSetContent.bind(this)}], - ['Display.setCustomCss', {async: false, handler: this._onMessageSetCustomCss.bind(this)}], - ['Display.setContentScale', {async: false, handler: this._onMessageSetContentScale.bind(this)}], - ['Display.configure', {async: true, handler: this._onMessageConfigure.bind(this)}], - ['Display.visibilityChanged', {async: false, handler: this._onMessageVisibilityChanged.bind(this)}] + ['Display.setOptionsContext', this._onMessageSetOptionsContext.bind(this)], + ['Display.setContent', this._onMessageSetContent.bind(this)], + ['Display.setCustomCss', this._onMessageSetCustomCss.bind(this)], + ['Display.setContentScale', this._onMessageSetContentScale.bind(this)], + ['Display.configure', this._onMessageConfigure.bind(this)], + ['Display.visibilityChanged', this._onMessageVisibilityChanged.bind(this)] ]); this.registerWindowMessageHandlers([ - ['Display.extensionUnloaded', {async: false, handler: this._onMessageExtensionUnloaded.bind(this)}] + ['Display.extensionUnloaded', this._onMessageExtensionUnloaded.bind(this)] ]); /* eslint-enable no-multi-spaces */ } @@ -328,7 +328,7 @@ export class Display extends EventDispatcher { this._progressIndicatorVisible.on('change', this._onProgressIndicatorVisibleChanged.bind(this)); yomitan.on('extensionUnloaded', this._onExtensionUnloaded.bind(this)); yomitan.crossFrame.registerHandlers([ - ['popupMessage', {async: 'dynamic', handler: this._onDirectMessage.bind(this)}] + ['popupMessage', this._onDirectMessage.bind(this)] ]); window.addEventListener('message', this._onWindowMessage.bind(this), false); @@ -506,7 +506,7 @@ export class Display extends EventDispatcher { } /** - * @param {import('core').MessageHandlerArray} handlers + * @param {import('core').MessageHandlerMapInit} handlers */ registerDirectMessageHandlers(handlers) { for (const [name, handlerInfo] of handlers) { @@ -515,7 +515,7 @@ export class Display extends EventDispatcher { } /** - * @param {import('core').MessageHandlerArray} handlers + * @param {import('core').MessageHandlerMapInit} handlers */ registerWindowMessageHandlers(handlers) { for (const [name, handlerInfo] of handlers) { @@ -638,22 +638,17 @@ export class Display extends EventDispatcher { /** * @param {import('frame-client').Message<import('display').MessageDetails>} data - * @returns {import('core').MessageHandlerAsyncResult} + * @returns {import('core').MessageHandlerResult} * @throws {Error} */ _onDirectMessage(data) { const {action, params} = this._authenticateMessageData(data); - const handlerInfo = this._directMessageHandlers.get(action); - if (typeof handlerInfo === 'undefined') { + const handler = this._directMessageHandlers.get(action); + if (typeof handler === 'undefined') { throw new Error(`Invalid action: ${action}`); } - const {async, handler} = handlerInfo; - const result = handler(params); - return { - async: typeof async === 'boolean' && async, - result - }; + return handler(params); } /** diff --git a/ext/js/display/search-display-controller.js b/ext/js/display/search-display-controller.js index 44850cbb..4dd41736 100644 --- a/ext/js/display/search-display-controller.js +++ b/ext/js/display/search-display-controller.js @@ -96,9 +96,9 @@ export class SearchDisplayController { ]); /* eslint-disable no-multi-spaces */ this._registerMessageHandlers([ - ['SearchDisplayController.getMode', {async: false, handler: this._onMessageGetMode.bind(this)}], - ['SearchDisplayController.setMode', {async: false, handler: this._onMessageSetMode.bind(this)}], - ['SearchDisplayController.updateSearchQuery', {async: false, handler: this._onExternalSearchUpdate.bind(this)}] + ['SearchDisplayController.getMode', this._onMessageGetMode.bind(this)], + ['SearchDisplayController.setMode', this._onMessageSetMode.bind(this)], + ['SearchDisplayController.updateSearchQuery', this._onExternalSearchUpdate.bind(this)] ]); /* eslint-enable no-multi-spaces */ @@ -549,7 +549,7 @@ export class SearchDisplayController { } /** - * @param {import('core').MessageHandlerArray} handlers + * @param {import('core').MessageHandlerMapInit} handlers */ _registerMessageHandlers(handlers) { for (const [name, handlerInfo] of handlers) { |