-
Notifications
You must be signed in to change notification settings - Fork 15
Centralize message handling to allow for multiple async listeners. #170
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
R+WC. Very clean! Extraction doesn't work right now due to a super minor change needed. Be sure to make that change before merging.
*/ | ||
|
||
import {handleConfigMessage} from 'commerce/config/background'; | ||
import {handleExtractedProductData} from 'commerce/background/extraction'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extraction doesn't work right now for a very minor reason:
- The
handleExtractedProductData
method needs to be updated, since you are now sendingmessage
instead ofmessage.extractedProduct
as the first argument.
Currently:
export async function handleExtractedProductData(contentExtractedProduct, sender) {
// Fetch the favicon, which the content script cannot do itself.
const extractedProduct = {
...contentExtractedProduct,
vendorFaviconUrl: sender.tab.favIconUrl,
};
// ...
Change that makes it work:
export async function handleExtractedProductData(message, sender) {
// Fetch the favicon, which the content script cannot do itself.
const extractedProduct = {
...message.extractedProduct,
vendorFaviconUrl: sender.tab.favIconUrl,
};
// ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch, my bad.
return handlers.get(message.type)(message, sender); | ||
} | ||
|
||
return undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain a little more why we want to return undefined
here? I'm not sure I'm totally following.
Would we not want to console.warn
or something that the message.type
is not recognized?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ESLint doesn't like if we have a return statement in some branches but not others. Since the if
has a return, we need one outside too in case we don't return there. undefined
is the default return value for functions that don't return, so I'm just using that here as well.
95e235c
to
2c31515
Compare
Thank you! |
This is the messaging refactor extracted from #168.