Skip to content

Commit

Permalink
Use early return style instead of deeply nested conditional operator
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Jul 26, 2024
1 parent 9b9ac82 commit ab2cb9a
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions webextensions/background/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,23 @@ browser.runtime.onMessage.addListener((message, sender) => {
mInitialSignatureForTabWithoutSubject.set(sender.tab.id, signatureWithoutSubject);
const types = new Set(await getContainerFolderTypesFromSignature(signature));
log('message types: ', types);
const detectedType = (types.has('drafts') && !hasRecentlySavedDraftWithSignature(signature)) ?
TYPE_DRAFT :
types.has('templates') ?
TYPE_TEMPLATE :
(types.size > 0) ?
TYPE_EXISTING_MESSAGE :
(signature == blankSignature ||
details.type == 'new') ?
TYPE_NEWLY_COMPOSED :
TYPE_REPLY;
const detectedType = (() => {
if (types.has('drafts') &&
!hasRecentlySavedDraftWithSignature(signature))
return TYPE_DRAFT;

if (types.has('templates'))
return TYPE_TEMPLATE;

if (types.size > 0)
return TYPE_EXISTING_MESSAGE;

if (signature == blankSignature ||
details.type == 'new')
return TYPE_NEWLY_COMPOSED;

return TYPE_REPLY;
})();
log('detected type: ', detectedType)
mDetectedMessageTypeForTab.set(sender.tab.id , detectedType);
mLastContextMessagesForTab.delete(sender.tab.id);
Expand Down

0 comments on commit ab2cb9a

Please sign in to comment.