Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

avoid callback hell with chrome.sendMessage #29

Closed
kkuehlz opened this issue Sep 9, 2019 · 2 comments
Closed

avoid callback hell with chrome.sendMessage #29

kkuehlz opened this issue Sep 9, 2019 · 2 comments
Assignees
Labels

Comments

@kkuehlz
Copy link
Member

kkuehlz commented Sep 9, 2019

The Firefox sendMessage implementation is much more sane than Chrome's. Instead of using a callback when the listener returns, it instead returns a Promise. For chained messages (which we will need to do for context menu decryption), it keeps us from entering the depths of callback hell.

We can either pull in https://github.com/mozilla/webextension-polyfill that will polyfill the mozilla sendMessage for chrome, or we could write a wrapper around the chrome API.

@dkess
Copy link

dkess commented Sep 10, 2019

What part of the code is this needed in? I can look into it

@kkuehlz
Copy link
Member Author

kkuehlz commented Sep 10, 2019

@dkess We probably want to change it everywhere because it's a better design. I have a slight preference for just writing a wrapper method that returns a Promise (goes in utils/message.ts) and sticking with the Chrome API as opposed to using the polyfill library. Since we don't need anything else polyfilled, pulling in the dependency seems excessive.

Right now we haven't quite entered callback hell yet. I was having a lot of issues when implementing selection decryption. Context menu triggered in background -> tell content_script to spawn iframe (cb 1) -> send ciphertext to iframe (cb 2) -> enable buttons (cb 3). This design will also let us simplify message listeners, break them into smaller components, and encourage message chaining as opposed to mono-receivers.

@kkuehlz kkuehlz assigned kkuehlz and unassigned dkess Sep 14, 2019
kkuehlz added a commit that referenced this issue Sep 14, 2019
Similar to b5f8fbf, modify the sendMessageActiveTab to return a Promise.
Goodbye callback hell!

Resolves #29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants