Replace repetitive element getters with something cleaner.

NEW
Unassigned

Status

()

6 years ago
6 years ago

People

(Reporter: mconley, Unassigned)

Tracking

Trunk
x86
All
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

6 years ago
In the front-end code for the downloads panel, we have some repetitive getters that retrieve / memoize DOM elements.

Example:

  /**
   * Sets whether or not the Downloads Summary should be displayed in the
   * footer. If not, the "Show All Downloads" button is shown instead.
   */
  set showingSummary(aValue)
  {
    if (this._footerNode) {
      if (aValue) {
        this._footerNode.setAttribute("showingsummary", "true");
      } else {
        this._footerNode.removeAttribute("showingsummary");
      }
    }
    return aValue;
  },

  /**
   * Element corresponding to the footer of the downloads panel.
   */
  get _footerNode()
  {
    let node = document.getElementById("downloadsFooter");
    if (!node) {
      return null;
    }
    delete this._footerNode;
    return this._footerNode = node;
  }


We can probably do something a bit cleaner with a centralized _element function and a WeakMap.
You need to log in before you can comment on or make changes to this bug.