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() { _handleClickAddToAttentionSet() {
if (!this.change || !this.account._account_id) return; if (!this.change || !this.account._account_id) return;
this.dispatchEvent( this.dispatchEventThroughTarget('show-alert', {
new CustomEvent('show-alert', {
detail: { detail: {
message: 'Saving attention set update ...', message: 'Saving attention set update ...',
dismissOnNavigation: true, dismissOnNavigation: true,
}, },
composed: true, });
bubbles: true,
})
);
// We are deliberately updating the UI before making the API call. It is a // 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. // 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() { _handleClickRemoveFromAttentionSet() {
if (!this.change || !this.account._account_id) return; if (!this.change || !this.account._account_id) return;
this.dispatchEvent( this.dispatchEventThroughTarget('show-alert', {
new CustomEvent('show-alert', {
detail: { detail: {
message: 'Saving attention set update ...', message: 'Saving attention set update ...',
dismissOnNavigation: true, dismissOnNavigation: true,
}, },
composed: true, });
bubbles: true,
})
);
// We are deliberately updating the UI before making the API call. It is a // 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. // 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 showAlertListener = sinon.spy();
const hideAlertListener = sinon.spy(); const hideAlertListener = sinon.spy();
const updatedListener = 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('hide-alert', hideAlertListener);
element._target.addEventListener('attention-set-updated', updatedListener); element._target.addEventListener('attention-set-updated', updatedListener);
@@ -149,7 +149,7 @@ suite('gr-hovercard-account tests', () => {
const showAlertListener = sinon.spy(); const showAlertListener = sinon.spy();
const hideAlertListener = sinon.spy(); const hideAlertListener = sinon.spy();
const updatedListener = 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('hide-alert', hideAlertListener);
element._target.addEventListener('attention-set-updated', updatedListener); element._target.addEventListener('attention-set-updated', updatedListener);