1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-22 16:18:08 +02:00

Use more optional chaining in the code-base

This patch updates a bunch of older code, that makes conditional function calls, to use optional chaining rather than `if`-blocks.

These mostly mechanical changes reduce the size of the `gulp mozcentral` build by a little over 1 kB.
This commit is contained in:
Jonas Jenwald 2022-09-05 15:36:04 +02:00
parent 9578152ae4
commit 38ee28b1d3
15 changed files with 51 additions and 119 deletions

View file

@ -637,12 +637,9 @@ class BaseViewer {
this._cancelRendering();
this._resetView();
if (this.findController) {
this.findController.setDocument(null);
}
if (this._scriptingManager) {
this._scriptingManager.setDocument(null);
}
this.findController?.setDocument(null);
this._scriptingManager?.setDocument(null);
if (this.#annotationEditorUIManager) {
this.#annotationEditorUIManager.destroy();
this.#annotationEditorUIManager = null;
@ -807,12 +804,8 @@ class BaseViewer {
// starts to create the correct size canvas. Wait until one page is
// rendered so we don't tie up too many resources early on.
this.#onePageRenderedOrForceFetch().then(async () => {
if (this.findController) {
this.findController.setDocument(pdfDocument); // Enable searching.
}
if (this._scriptingManager) {
this._scriptingManager.setDocument(pdfDocument); // Enable scripting.
}
this.findController?.setDocument(pdfDocument); // Enable searching.
this._scriptingManager?.setDocument(pdfDocument); // Enable scripting.
if (this.#annotationEditorUIManager) {
// Ensure that the Editor buttons, in the toolbar, are updated.

View file

@ -45,9 +45,7 @@ const ChromeCom = {
};
if (!chrome.runtime) {
console.error("chrome.runtime is undefined.");
if (callback) {
callback();
}
callback?.();
} else if (callback) {
chrome.runtime.sendMessage(message, callback);
} else {

View file

@ -221,9 +221,7 @@ class PDFPageView {
destroy() {
this.reset();
if (this.pdfPage) {
this.pdfPage.cleanup();
}
this.pdfPage?.cleanup();
}
/**

View file

@ -231,10 +231,7 @@ class PDFThumbnailViewer {
// Set the first `pdfPage` immediately, since it's already loaded,
// rather than having to repeat the `PDFDocumentProxy.getPage` call in
// the `this.#ensurePdfPageLoaded` method before rendering can start.
const firstThumbnailView = this._thumbnails[0];
if (firstThumbnailView) {
firstThumbnailView.setPdfPage(firstPdfPage);
}
this._thumbnails[0]?.setPdfPage(firstPdfPage);
// Ensure that the current thumbnail is always highlighted on load.
const thumbnailView = this._thumbnails[this._currentPageNumber - 1];