-
Notifications
You must be signed in to change notification settings - Fork 397
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
Add events to disco pane #543
Changes from all commits
6087532
4d5c0de
399a139
32918b2
fc07ce9
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,4 +1,10 @@ | ||
import { installEventList } from 'disco/constants'; | ||
import log from 'core/logger'; | ||
|
||
import { | ||
globalEvents, | ||
globalEventStatusMap, | ||
installEventList, | ||
} from 'disco/constants'; | ||
|
||
|
||
export function getAddon(guid, {_mozAddonManager = window.navigator.mozAddonManager} = {}) { | ||
|
@@ -36,3 +42,23 @@ export function uninstall(guid, {_mozAddonManager = window.navigator.mozAddonMan | |
return; | ||
}); | ||
} | ||
|
||
export function addChangeListeners(callback, mozAddonManager) { | ||
function handleChangeEvent(e) { | ||
const { id, type, needsRestart } = e; | ||
log.info('Event received', {type, id, needsRestart}); | ||
if (globalEventStatusMap.hasOwnProperty(type)) { | ||
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. I feel this should be a 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. Yeah, I don't feel too strongly it must be a map, since it's just a lookup. |
||
return callback({guid: id, status: globalEventStatusMap[type], needsRestart}); | ||
} | ||
throw new Error(`Unknown global event: ${type}`); | ||
} | ||
|
||
if (mozAddonManager && mozAddonManager.addEventListener) { | ||
for (const event of globalEvents) { | ||
mozAddonManager.addEventListener(event, handleChangeEvent); | ||
} | ||
} else { | ||
log.info('mozAddonManager.addEventListener not available'); | ||
} | ||
return handleChangeEvent; | ||
} |
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.
I don't think this should be plural. I could probably be convinced but from the caller's perspective this just registers a single callback that will be notified of the new status.
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.
I felt this was more accurate since it says what it does more closely. For example if this was addChangeListener you might expect it to only register one event where this doesn't it, registers listeners for multiple events.