Closed Bug 1476873 Opened 6 years ago Closed 5 years ago

Use Element.toggleAttribute instead of our custom handling for setAttribute vs. removeAttribute

Categories

(Firefox :: WebPayments UI, enhancement, P1)

enhancement

Tracking

()

RESOLVED FIXED
Firefox 66
Tracking Status
firefox66 --- fixed

People

(Reporter: MattN, Assigned: dpino)

References

()

Details

(Whiteboard: [webpayments-reserve])

Attachments

(1 file, 1 obsolete file)

Attachment #9029594 - Flags: review?(MattN+bmo)
Assignee: nobody → dpino
Status: NEW → ASSIGNED
Priority: P3 → P1
I run the tests. It doesn't seem to be regressions https://treeherder.mozilla.org/#/jobs?repo=try&revision=b3cf25219244e71423a4783c4d14dbcc5357a0b5
Comment on attachment 9029594 [details] [diff] [review]
Bug-1476873-Use-Element.toggleAttribute-instead-of-c.patch

Review of attachment 9029594 [details] [diff] [review]:
-----------------------------------------------------------------

Sorry, I think when I filed this I thought toggleAttribute allowed specifying the value to toggle too, not just the name. Let's only switch to toggleAttribute for boolean attributes like the ones in *-form.js and @changes-prevented then revert the rest.

I don't think the
```js
if (el.toggleAttribute(…)) {
  el.setAttribute(…);
}
```
pattern is common enough that I think it hinders readability.

::: browser/components/payments/res/containers/payment-dialog.js
@@ +415,5 @@
>      for (let page of this._mainContainer.querySelectorAll(":scope > .page")) {
>        page.hidden = state.page.id != page.id;
>      }
>  
> +    this.toggleAttribute("changes-prevented", state.changesPrevented);

This is a good replacement

::: browser/components/payments/res/mixins/ObservedPropertiesMixin.js
@@ +33,5 @@
>            get() {
>              return this.getAttribute(name);
>            },
>            set(value) {
> +            if (this.toggleAttribute(name, !!value)) {

This is a behaviour change for "" btw.
Attachment #9029594 - Flags: review?(MattN+bmo) → feedback+
I agree the "if toggle/set" pattern is less readable. Updated patch with suggested changes.
Attachment #9029594 - Attachment is obsolete: true
Attachment #9031672 - Flags: review?(MattN+bmo)
Comment on attachment 9031672 [details] [diff] [review]
Bug-1476873-Use-Element.toggleAttribute-instead-of-c.patch

Review of attachment 9031672 [details] [diff] [review]:
-----------------------------------------------------------------

Thanks!
Attachment #9031672 - Flags: review?(MattN+bmo) → review+
Keywords: checkin-needed
Pushed by nerli@mozilla.com:
https://hg.mozilla.org/integration/mozilla-inbound/rev/099c54d22608
Use Element.toggleAttribute instead of custom handling for setAttribute vs. removeAttribute. r=Mattn
Keywords: checkin-needed
https://hg.mozilla.org/mozilla-central/rev/099c54d22608
Status: ASSIGNED → RESOLVED
Closed: 5 years ago
Resolution: --- → FIXED
Target Milestone: --- → Firefox 66
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: