[api-minor] Change {PDFPageView, PDFThumbnailView}.update to take a parameter object

The old `update`-signature started to annoy me back when I added optional content support to the viewer, since we're (often) forced to pass in a bunch of arguments that we don't care about whenever these methods are called.

This is tagged `api-minor` since `PDFPageView` is being used in the `pageviewer` component example, and it's thus possible that these changes could affect some users; the next commit adds fallback handling for the old format.
This commit is contained in:
Jonas Jenwald 2021-08-31 17:08:43 +02:00
parent 258cf1decc
commit 7c81a8dd40
4 changed files with 17 additions and 15 deletions

View File

@ -405,9 +405,9 @@ class BaseViewer {
const pageNumber = this._currentPageNumber; const pageNumber = this._currentPageNumber;
for (let i = 0, ii = this._pages.length; i < ii; i++) { const updateArgs = { rotation };
const pageView = this._pages[i]; for (const pageView of this._pages) {
pageView.update(pageView.scale, rotation); pageView.update(updateArgs);
} }
// Prevent errors in case the rotation changes *before* the scale has been // Prevent errors in case the rotation changes *before* the scale has been
// set to a non-default value. // set to a non-default value.
@ -717,8 +717,9 @@ class BaseViewer {
} }
this._doc.style.setProperty("--zoom-factor", newScale); this._doc.style.setProperty("--zoom-factor", newScale);
for (let i = 0, ii = this._pages.length; i < ii; i++) { const updateArgs = { scale: newScale };
this._pages[i].update(newScale); for (const pageView of this._pages) {
pageView.update(updateArgs);
} }
this._currentScale = newScale; this._currentScale = newScale;
@ -1435,8 +1436,9 @@ class BaseViewer {
} }
this._optionalContentConfigPromise = promise; this._optionalContentConfigPromise = promise;
const updateArgs = { optionalContentConfigPromise: promise };
for (const pageView of this._pages) { for (const pageView of this._pages) {
pageView.update(pageView.scale, pageView.rotation, promise); pageView.update(updateArgs);
} }
this.update(); this.update();

View File

@ -297,11 +297,10 @@ class PDFPageView {
div.appendChild(this.loadingIconDiv); div.appendChild(this.loadingIconDiv);
} }
update(scale, rotation, optionalContentConfigPromise = null) { update({ scale = 0, rotation = null, optionalContentConfigPromise = null }) {
this.scale = scale || this.scale; this.scale = scale || this.scale;
// The rotation may be zero. if (typeof rotation === "number") {
if (typeof rotation !== "undefined") { this.rotation = rotation; // The rotation may be zero.
this.rotation = rotation;
} }
if (optionalContentConfigPromise instanceof Promise) { if (optionalContentConfigPromise instanceof Promise) {
this._optionalContentConfigPromise = optionalContentConfigPromise; this._optionalContentConfigPromise = optionalContentConfigPromise;

View File

@ -195,9 +195,9 @@ class PDFThumbnailView {
} }
} }
update(rotation) { update({ rotation = null }) {
if (typeof rotation !== "undefined") { if (typeof rotation === "number") {
this.rotation = rotation; this.rotation = rotation; // The rotation may be zero.
} }
const totalRotation = (this.rotation + this.pdfPageRotate) % 360; const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
this.viewport = this.viewport.clone({ this.viewport = this.viewport.clone({

View File

@ -144,8 +144,9 @@ class PDFThumbnailViewer {
} }
this._pagesRotation = rotation; this._pagesRotation = rotation;
for (let i = 0, ii = this._thumbnails.length; i < ii; i++) { const updateArgs = { rotation };
this._thumbnails[i].update(rotation); for (const thumbnail of this._thumbnails) {
thumbnail.update(updateArgs);
} }
} }