Merge "Replace dispatchEvent with dispatchEventThroughTarget"

This commit is contained in:
Dhruv Srivastava
2020-10-12 17:13:36 +00:00
committed by Gerrit Code Review
2 changed files with 14 additions and 22 deletions

View File

@@ -145,16 +145,12 @@ export class GrHovercardAccount extends GestureEventListeners(
_handleClickAddToAttentionSet() {
if (!this.change || !this.account._account_id) return;
this.dispatchEvent(
new CustomEvent('show-alert', {
detail: {
message: 'Saving attention set update ...',
dismissOnNavigation: true,
},
composed: true,
bubbles: true,
})
);
this.dispatchEventThroughTarget('show-alert', {
detail: {
message: 'Saving attention set update ...',
dismissOnNavigation: true,
},
});
// We are deliberately updating the UI before making the API call. It is a
// risk that we are taking to achieve a better UX for 99.9% of the cases.
@@ -181,16 +177,12 @@ export class GrHovercardAccount extends GestureEventListeners(
_handleClickRemoveFromAttentionSet() {
if (!this.change || !this.account._account_id) return;
this.dispatchEvent(
new CustomEvent('show-alert', {
detail: {
message: 'Saving attention set update ...',
dismissOnNavigation: true,
},
composed: true,
bubbles: true,
})
);
this.dispatchEventThroughTarget('show-alert', {
detail: {
message: 'Saving attention set update ...',
dismissOnNavigation: true,
},
});
// We are deliberately updating the UI before making the API call. It is a
// risk that we are taking to achieve a better UX for 99.9% of the cases.

View File

@@ -115,7 +115,7 @@ suite('gr-hovercard-account tests', () => {
const showAlertListener = sinon.spy();
const hideAlertListener = sinon.spy();
const updatedListener = sinon.spy();
element.addEventListener('show-alert', showAlertListener);
element._target.addEventListener('show-alert', showAlertListener);
element._target.addEventListener('hide-alert', hideAlertListener);
element._target.addEventListener('attention-set-updated', updatedListener);
@@ -149,7 +149,7 @@ suite('gr-hovercard-account tests', () => {
const showAlertListener = sinon.spy();
const hideAlertListener = sinon.spy();
const updatedListener = sinon.spy();
element.addEventListener('show-alert', showAlertListener);
element._target.addEventListener('show-alert', showAlertListener);
element._target.addEventListener('hide-alert', hideAlertListener);
element._target.addEventListener('attention-set-updated', updatedListener);