Slightly re-factor how the BaseViewer
/PDFThumbnailViewer
handle page labels internally, to make the null
default value clearer
Currently it's not *immediately* clear from the code itself, unless you look at the definition of `this._pageLabels`, that the default value is `null`.[1] We can improve this, and also reduce the amount of code, by using modern ECMAScript features such as optional chaining and nullish coalescing. --- [1] Keep in mind that an *empty* string is actually a valid page label, according to the PDF specification.
This commit is contained in:
parent
094e0b2239
commit
dc19965d78
@ -290,7 +290,7 @@ class BaseViewer {
|
||||
this.eventBus.dispatch("pagechanging", {
|
||||
source: this,
|
||||
pageNumber: val,
|
||||
pageLabel: this._pageLabels && this._pageLabels[val - 1],
|
||||
pageLabel: this._pageLabels?.[val - 1] ?? null,
|
||||
previous,
|
||||
});
|
||||
|
||||
@ -305,7 +305,7 @@ class BaseViewer {
|
||||
* labels exist.
|
||||
*/
|
||||
get currentPageLabel() {
|
||||
return this._pageLabels && this._pageLabels[this._currentPageNumber - 1];
|
||||
return this._pageLabels?.[this._currentPageNumber - 1] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -631,9 +631,7 @@ class BaseViewer {
|
||||
}
|
||||
// Update all the `PDFPageView` instances.
|
||||
for (let i = 0, ii = this._pages.length; i < ii; i++) {
|
||||
const pageView = this._pages[i];
|
||||
const label = this._pageLabels && this._pageLabels[i];
|
||||
pageView.setPageLabel(label);
|
||||
this._pages[i].setPageLabel(this._pageLabels?.[i] ?? null);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -268,8 +268,7 @@ class PDFThumbnailViewer {
|
||||
}
|
||||
// Update all the `PDFThumbnailView` instances.
|
||||
for (let i = 0, ii = this._thumbnails.length; i < ii; i++) {
|
||||
const label = this._pageLabels && this._pageLabels[i];
|
||||
this._thumbnails[i].setPageLabel(label);
|
||||
this._thumbnails[i].setPageLabel(this._pageLabels?.[i] ?? null);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user