Skip to content

Commit 7889cfd

Browse files
Merge pull request #13973 from Snuffleupagus/viewer-components-refactor-update
[api-minor] Change `{PDFPageView, PDFThumbnailView}.update` to take a parameter object
2 parents 680f33c + 8466204 commit 7889cfd

File tree

4 files changed

+34
-15
lines changed

4 files changed

+34
-15
lines changed

web/base_viewer.js

+8-6
Original file line numberDiff line numberDiff line change
@@ -405,9 +405,9 @@ class BaseViewer {
405405

406406
const pageNumber = this._currentPageNumber;
407407

408-
for (let i = 0, ii = this._pages.length; i < ii; i++) {
409-
const pageView = this._pages[i];
410-
pageView.update(pageView.scale, rotation);
408+
const updateArgs = { rotation };
409+
for (const pageView of this._pages) {
410+
pageView.update(updateArgs);
411411
}
412412
// Prevent errors in case the rotation changes *before* the scale has been
413413
// set to a non-default value.
@@ -717,8 +717,9 @@ class BaseViewer {
717717
}
718718
this._doc.style.setProperty("--zoom-factor", newScale);
719719

720-
for (let i = 0, ii = this._pages.length; i < ii; i++) {
721-
this._pages[i].update(newScale);
720+
const updateArgs = { scale: newScale };
721+
for (const pageView of this._pages) {
722+
pageView.update(updateArgs);
722723
}
723724
this._currentScale = newScale;
724725

@@ -1435,8 +1436,9 @@ class BaseViewer {
14351436
}
14361437
this._optionalContentConfigPromise = promise;
14371438

1439+
const updateArgs = { optionalContentConfigPromise: promise };
14381440
for (const pageView of this._pages) {
1439-
pageView.update(pageView.scale, pageView.rotation, promise);
1441+
pageView.update(updateArgs);
14401442
}
14411443
this.update();
14421444

web/pdf_page_view.js

+20-4
Original file line numberDiff line numberDiff line change
@@ -297,11 +297,27 @@ class PDFPageView {
297297
div.appendChild(this.loadingIconDiv);
298298
}
299299

300-
update(scale, rotation, optionalContentConfigPromise = null) {
300+
update({ scale = 0, rotation = null, optionalContentConfigPromise = null }) {
301+
if (
302+
typeof PDFJSDev !== "undefined" &&
303+
PDFJSDev.test("GENERIC") &&
304+
typeof arguments[0] !== "object"
305+
) {
306+
console.error(
307+
"PDFPageView.update called with separate parameters, please use an object instead."
308+
);
309+
310+
this.update({
311+
scale: arguments[0],
312+
rotation: arguments[1],
313+
optionalContentConfigPromise: arguments[2],
314+
});
315+
return;
316+
}
317+
301318
this.scale = scale || this.scale;
302-
// The rotation may be zero.
303-
if (typeof rotation !== "undefined") {
304-
this.rotation = rotation;
319+
if (typeof rotation === "number") {
320+
this.rotation = rotation; // The rotation may be zero.
305321
}
306322
if (optionalContentConfigPromise instanceof Promise) {
307323
this._optionalContentConfigPromise = optionalContentConfigPromise;

web/pdf_thumbnail_view.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,9 @@ class PDFThumbnailView {
195195
}
196196
}
197197

198-
update(rotation) {
199-
if (typeof rotation !== "undefined") {
200-
this.rotation = rotation;
198+
update({ rotation = null }) {
199+
if (typeof rotation === "number") {
200+
this.rotation = rotation; // The rotation may be zero.
201201
}
202202
const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
203203
this.viewport = this.viewport.clone({

web/pdf_thumbnail_viewer.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,9 @@ class PDFThumbnailViewer {
144144
}
145145
this._pagesRotation = rotation;
146146

147-
for (let i = 0, ii = this._thumbnails.length; i < ii; i++) {
148-
this._thumbnails[i].update(rotation);
147+
const updateArgs = { rotation };
148+
for (const thumbnail of this._thumbnails) {
149+
thumbnail.update(updateArgs);
149150
}
150151
}
151152

0 commit comments

Comments
 (0)