Closed Bug 1303720 Opened 5 years ago Closed 5 years ago

Use addEventListener(..., {once: true}) in im and chat code

Categories

(Instantbird :: Other, enhancement)

enhancement
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED
Instantbird 52

People

(Reporter: aryx, Assigned: aryx)

References

Details

Attachments

(1 file)

Attached patch patch, v1Splinter Review
Similar to bug 1300339.

See https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener

Bug 1287706 added support for the 'once' option in addEventListener which works like an removeEventListener executed when the callback gets executed for the first time.

Advantage: add + remove in one statement, remove can't get lost
Attachment #8792476 - Flags: review?(aleth)
Comment on attachment 8792476 [details] [diff] [review]
patch, v1

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

Thanks for taking a look at this! r+ with nits fixed.

::: im/components/mintrayr/content/mintrayr.js
@@ +11,5 @@
>  
>    load: function() {
> +    window.addEventListener("unload",
> +      () => gMinTrayR._prefs.removeObserver("alwaysShowTrayIcon", gMinTrayR),
> +      {once: true});

I assume you've checked nothing else calls init()?

@@ +54,2 @@
>        }.bind(this);
> +      window.addEventListener("focus", this._onfocus, {once: true});

Looks like this._onfocus doesn't need to be stored any more now, so you can inline it using an arrow function.
Attachment #8792476 - Flags: review?(aleth) → review+
https://hg.mozilla.org/comm-central/rev/624e9f5b5295
Status: ASSIGNED → RESOLVED
Closed: 5 years ago
Resolution: --- → FIXED
Target Milestone: --- → Instantbird 52
Version: trunk → 52
Depends on: 1308772
You need to log in before you can comment on or make changes to this bug.