Skip to content

Commit

Permalink
Simplify the PDFDocumentProperties.#updateUI method
Browse files Browse the repository at this point in the history
We can remove the `reset`-parameter, since it's redundant, given that it's only used after `PDFDocumentProperties.#reset` has been invoked which means that `this.#fieldData === null` which is equivalent to resetting.
Also, we don't need to have two separate loops in order to update the UI in this method.
  • Loading branch information
Snuffleupagus committed Aug 27, 2024
1 parent b58c24a commit 055afbc
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions web/pdf_document_properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ class PDFDocumentProperties {
setDocument(pdfDocument) {
if (this.pdfDocument) {
this.#reset();
this.#updateUI(true);
this.#updateUI();
}
if (!pdfDocument) {
return;
Expand All @@ -216,20 +216,15 @@ class PDFDocumentProperties {
* NOTE: If the contents of a particular field is neither a non-empty string,
* nor a number, it will fall back to `DEFAULT_FIELD_CONTENT`.
*/
#updateUI(reset = false) {
if (reset || !this.#fieldData) {
for (const id in this.fields) {
this.fields[id].textContent = DEFAULT_FIELD_CONTENT;
}
return;
}
if (this.overlayManager.active !== this.dialog) {
#updateUI() {
if (this.#fieldData && this.overlayManager.active !== this.dialog) {
// Don't bother updating the dialog if has already been closed,
// unless it's being reset (i.e. `this.#fieldData === null`),
// since it will be updated the next time `this.open` is called.
return;
}
for (const id in this.fields) {
const content = this.#fieldData[id];
const content = this.#fieldData?.[id];
this.fields[id].textContent =
content || content === 0 ? content : DEFAULT_FIELD_CONTENT;
}
Expand Down

0 comments on commit 055afbc

Please sign in to comment.