-
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
Changes from all commits
8816c49
1f4299d
9d150cc
fe6518f
3e34c0f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
import { listen } from './background/bridge'; | ||
import { listen } from './background/background-events'; | ||
|
||
listen(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { REQUEST_PACKAGE_INFO_EVENT, RESPONSE_PACKAGE_INFO_EVENT } from '../events-shared'; | ||
import advisories from './advisory/index'; | ||
|
||
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); | ||
}); | ||
}; | ||
Comment on lines
+4
to
+28
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,21 @@ | ||
import { mountContentScript } from './content'; | ||
import { getPackageInfo } from './content/bridge'; | ||
import { sendPackageInfoToWebapp } from './content/content-events'; | ||
import { fetchPackageInfo } from './content/content-events'; | ||
import { findRanges } from './content/stackoverflow/finder'; | ||
import { addIndicator } from './content/stackoverflow/indicator'; | ||
|
||
mountContentScript(async () => { | ||
const findings = findRanges(document.body); | ||
console.debug({ findings }); | ||
|
||
findings.reduce((acc, current) => { | ||
const { type, name } = current; | ||
if (acc[type + '_' + name]) return acc; | ||
let processed = {}; | ||
findings.forEach(({ range, ...packageId }) => { | ||
addIndicator(range, packageId); | ||
let packageKey = `${packageId.type}/${packageId.name}`; | ||
if (processed[packageKey]) { | ||
return; | ||
} | ||
|
||
getPackageInfo(find).then(sendPackageInfoToWebapp); | ||
acc[type + '_' + name] = true; | ||
return acc; | ||
}, {}); | ||
|
||
findings.forEach(addIndicator); | ||
processed[packageKey] = true; | ||
fetchPackageInfo(packageId); | ||
}); | ||
}); |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,9 @@ | ||
export const addIndicator = async ({ range, ...packageID }) => { | ||
export const addIndicator = async (range, packageID) => { | ||
console.debug('Adding indicator for', packageID); | ||
|
||
const indicator = document.createElement('overlay-indicator'); | ||
indicator.setAttribute('overlay-indicator-package-type', packageID.type); | ||
indicator.setAttribute('overlay-indicator-package-name', packageID.name); | ||
indicator.appendChild(range.extractContents()); | ||
range.insertNode(indicator); | ||
|
||
// TODO: handle info for package, from inside the component or from store | ||
}; |
This file was deleted.
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 aport.sendMessage
at the end of each promise.