Closed Bug 1448143 Opened 7 years ago Closed 7 years ago

Factor out a size getter from DownloadsViewUI.jsm so other consumers can access it

Categories

(Firefox :: New Tab Page, enhancement, P1)

57 Branch
enhancement

Tracking

()

RESOLVED FIXED
Firefox 61
Iteration:
61.1 - Mar 26
Tracking Status
firefox61 --- fixed

People

(Reporter: ursula, Assigned: ursula)

References

Details

Attachments

(1 file)

This will make it easier for Activity stream's downloaded items in highlights to get the "description" of the download. Or else I'd have to re-implement this function to get the size
Severity: normal → enhancement
Iteration: --- → 61.1 - Mar 26
Priority: -- → P1
Comment on attachment 8961528 [details] Bug 1448143 - Factor out a size getter from DownloadsViewUI.jsm so other consumers can access it https://reviewboard.mozilla.org/r/230318/#review235898 ::: browser/components/downloads/DownloadsViewUI.jsm:272 (Diff revision 1) > stateLabel = s.fileMovedOrMissing; > hoverStatus = stateLabel; > } else if (this.download.succeeded) { > - // For completed downloads, show the file size (e.g. "1.5 MB"). > - if (this.download.target.size !== undefined) { > - let [size, unit] = > + // For completed downloads, show the file size > + stateLabel = this.size.stateLabel; > + status = this.size.status; This is going to cause the `size` getter to run twice. You could avoid it with: ({stateLabel, status} = this.size); Or if you want to avoid the ()s, have .size return a pair/array similar to how `convertByteUnits` returns an array, then `[stateLabel, status] = this.size`;
Or just save it locally first let size = this.size; Although looking closer, perhaps the getter should be named sizeStrings? Or something else? Odd that there's status for a "size"
Yeah `sizeStrings` is a better name. Changed the name, and saved it to a variables locally first.
Comment on attachment 8961528 [details] Bug 1448143 - Factor out a size getter from DownloadsViewUI.jsm so other consumers can access it https://reviewboard.mozilla.org/r/230318/#review236190 ::: browser/components/downloads/DownloadsViewUI.jsm:122 (Diff revision 2) > + */ > + get sizeStrings() { > + let s = DownloadsCommon.strings; > + let sizeStrings = {}; > + > + if (this.download.target.size) { I believe the !== undefined is to guard against a 0 size, which is a valid size
Attachment #8961528 - Flags: review?(edilee) → review+
Pushed by usarracini@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/15b7991887bc Factor out a size getter from DownloadsViewUI.jsm so other consumers can access it r=Mardak
Status: NEW → RESOLVED
Closed: 7 years ago
Resolution: --- → FIXED
Target Milestone: --- → Firefox 61
Component: Activity Streams: Newtab → New Tab Page
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: