From bc13932ac1cbc79f7c7b6fa24d4b1ac0979a96a2 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sun, 7 Mar 2021 16:12:29 +0100 Subject: [PATCH] Use more optional chaining in the `web/`-folder (PR 12961 follow-up) I overlooked these cases previously, but there's no reason why optional chaining (and nullish coalescing) cannot be used here as well. --- web/pdf_find_controller.js | 4 ++-- web/pdf_sidebar_resizer.js | 7 ++----- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/web/pdf_find_controller.js b/web/pdf_find_controller.js index 100dee201..bc99e1f61 100644 --- a/web/pdf_find_controller.js +++ b/web/pdf_find_controller.js @@ -771,7 +771,7 @@ class PDFFindController { total = this._matchesCountTotal; if (matchIdx !== -1) { for (let i = 0; i < pageIdx; i++) { - current += (this._pageMatches[i] && this._pageMatches[i].length) || 0; + current += this._pageMatches[i]?.length || 0; } current += matchIdx + 1; } @@ -797,7 +797,7 @@ class PDFFindController { state, previous, matchesCount: this._requestMatchesCount(), - rawQuery: this._state ? this._state.query : null, + rawQuery: this._state?.query ?? null, }); } } diff --git a/web/pdf_sidebar_resizer.js b/web/pdf_sidebar_resizer.js index 6a255ab78..b97a1be7f 100644 --- a/web/pdf_sidebar_resizer.js +++ b/web/pdf_sidebar_resizer.js @@ -53,10 +53,7 @@ class PDFSidebarResizer { * @type {number} */ get outerContainerWidth() { - if (!this._outerContainerWidth) { - this._outerContainerWidth = this.outerContainer.clientWidth; - } - return this._outerContainerWidth; + return (this._outerContainerWidth ||= this.outerContainer.clientWidth); } /** @@ -135,7 +132,7 @@ class PDFSidebarResizer { this.eventBus._on("resize", evt => { // When the *entire* viewer is resized, such that it becomes narrower, // ensure that the sidebar doesn't end up being too wide. - if (!evt || evt.source !== window) { + if (evt?.source !== window) { return; } // Always reset the cached width when the viewer is resized.