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/core.js | |
parent | e0e29dc1aa0965b3e0fb97de64a27c2b695e068b (diff) |
Simplify message handlers (#396)
Diffstat (limited to 'ext/js/core.js')
-rw-r--r-- | ext/js/core.js | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/ext/js/core.js b/ext/js/core.js index d2372352..9995ee5b 100644 --- a/ext/js/core.js +++ b/ext/js/core.js @@ -324,7 +324,7 @@ export function promiseAnimationFrame(timeout) { * Invokes a standard message handler. This function is used to react and respond * to communication messages within the extension. * @template {import('core').SafeAny} TParams - * @param {import('core').MessageHandlerDetails} details Details about how to handle messages. + * @param {import('core').MessageHandler} handler The message handler function. * @param {TParams} params Information which was passed with the original message. * @param {(response: import('core').Response) => void} callback A callback function which is invoked after the handler has completed. The value passed * to the function is in the format: @@ -333,13 +333,10 @@ export function promiseAnimationFrame(timeout) { * @param {...*} extraArgs Additional arguments which are passed to the `handler` function. * @returns {boolean} `true` if the function is invoked asynchronously, `false` otherwise. */ -export function invokeMessageHandler({handler, async}, params, callback, ...extraArgs) { +export function invokeMessageHandler(handler, params, callback, ...extraArgs) { try { - let promiseOrResult = handler(params, ...extraArgs); - if (async === 'dynamic') { - ({async, result: promiseOrResult} = promiseOrResult); - } - if (async) { + const promiseOrResult = handler(params, ...extraArgs); + if (promiseOrResult instanceof Promise) { /** @type {Promise<any>} */ (promiseOrResult).then( (result) => { callback({result}); }, (error) => { callback({error: ExtensionError.serialize(error)}); } |