mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 21:31:04 +00:00
Bug 1689240 - Move CategoriesBox event handling into handleEvent method and remove listener on disconnection. r=robwu
Differential Revision: https://phabricator.services.mozilla.com/D108510
This commit is contained in:
parent
6015ee0245
commit
328af90dda
@ -1771,6 +1771,38 @@ class CategoriesBox extends customElements.get("button-group") {
|
||||
});
|
||||
}
|
||||
|
||||
handleEvent(e) {
|
||||
if (e.target == document && e.type == "view-selected") {
|
||||
const { type, param } = e.detail;
|
||||
this.select(`addons://${type}/${param}`);
|
||||
return;
|
||||
}
|
||||
|
||||
if (e.target == this && e.type == "button-group:key-selected") {
|
||||
this.activeChild.load();
|
||||
return;
|
||||
}
|
||||
|
||||
if (e.type == "click") {
|
||||
const button = e.target.closest("[viewid]");
|
||||
if (button) {
|
||||
button.load();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Forward the unhandled events to the button-group custom element.
|
||||
super.handleEvent(e);
|
||||
}
|
||||
|
||||
disconnectedCallback() {
|
||||
document.removeEventListener("view-selected", this);
|
||||
this.removeEventListener("button-group:key-selected", this);
|
||||
this.removeEventListener("click", this);
|
||||
AddonManagerListenerHandler.removeListener(this);
|
||||
super.disconnectedCallback();
|
||||
}
|
||||
|
||||
async initialize() {
|
||||
let addonTypesObjects = AddonManager.addonTypes;
|
||||
let addonTypes = new Set();
|
||||
@ -1797,20 +1829,9 @@ class CategoriesBox extends customElements.get("button-group") {
|
||||
|
||||
this.updateAvailableCount();
|
||||
|
||||
document.addEventListener("view-selected", e => {
|
||||
const { type, param } = e.detail;
|
||||
this.select(`addons://${type}/${param}`);
|
||||
});
|
||||
this.addEventListener("click", e => {
|
||||
let button = e.target.closest("[viewid]");
|
||||
if (button) {
|
||||
button.load();
|
||||
}
|
||||
});
|
||||
this.addEventListener("button-group:key-selected", e => {
|
||||
this.activeChild.load();
|
||||
});
|
||||
|
||||
document.addEventListener("view-selected", this);
|
||||
this.addEventListener("button-group:key-selected", this);
|
||||
this.addEventListener("click", this);
|
||||
AddonManagerListenerHandler.addListener(this);
|
||||
|
||||
this._resolveRendered();
|
||||
|
Loading…
Reference in New Issue
Block a user