-
Notifications
You must be signed in to change notification settings - Fork 19
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
feat: receive each advisory info separatly #32
feat: receive each advisory info separatly #32
Conversation
const listener = async ({ type, detail }, port) => { | ||
if (type === REQUEST_PACKAGE_INFO_EVENT) { | ||
const promises = await advisories(detail); | ||
Object.entries(promises).forEach(([part, promise]) => { | ||
promise.then((info) => { | ||
port.postMessage({ | ||
type: RESPONSE_PACKAGE_INFO_EVENT, | ||
detail: { | ||
packageId: detail, | ||
part, | ||
info, | ||
}, | ||
}); | ||
}); | ||
}); | ||
} | ||
|
||
return true; | ||
}; | ||
|
||
export const listen = () => { | ||
chrome.runtime.onConnect.addListener((port) => { | ||
port.onMessage.addListener(listener); | ||
}); | ||
}; |
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.
The code became a deep indentation, and also I'm struggling with the objects that passed between the events, each one requires a particular property for its use case.
I'm open to suggestions.
2e91914
to
fe6518f
Compare
export default (packageID) => { | ||
const depsDev = handleAsyncError(fetchDepsDev, packageID); | ||
const info = depsDev.then((depsDevInfo) => { | ||
const { latestVersion, licenses, stars } = depsDevInfo.data; | ||
return { | ||
latest: latestVersion, | ||
licenses, | ||
stars, | ||
}; | ||
}); | ||
|
||
return { debricked, depsDev, openbase, snyk, socket }; | ||
return { | ||
debricked: handleAsyncError(fetchDebricked, packageID), | ||
depsDev, | ||
info, | ||
openbase: handleAsyncError(fetchOpenbase, packageID), | ||
snyk: handleAsyncError(fetchSnyk, packageID), | ||
socket: handleAsyncError(fetchSocket, packageID), | ||
}; | ||
}; |
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.
Here is the trick. Instead of returning a complete result, I returned a Promise for each key.
This allows me to add a .then
to each promise, for registering a port.sendMessage
at the end of each promise.
…esponse-to-async-responses-event-based # Conflicts: # src/content.stackoverflow.js
Fix #26
Depends on #30
First, I moved from
message
communication toport
communication, as described here.Then, I split the advisories fetching to send a message when each advisory info is fetched, instead of aggregating them all together.