Move/refactor the code in the BaseViewer.update method to reduce duplication in the extending classes

Since most of the important rendering code is already (almost) identical between `PDFViewer.update` and `PDFSinglePageViewer.update`, it's possible to further reduce duplication by moving the code into `BaseViewer.update` instead.
This commit is contained in:
Jonas Jenwald 2019-01-18 12:42:32 +01:00
parent cdbc33ba06
commit 343f488daa
3 changed files with 26 additions and 40 deletions

View File

@ -824,8 +824,28 @@ class BaseViewer {
};
}
_updateHelper(visiblePages) {
throw new Error('Not implemented: _updateHelper');
}
update() {
throw new Error('Not implemented: update');
const visible = this._getVisiblePages();
const visiblePages = visible.views, numVisiblePages = visiblePages.length;
if (numVisiblePages === 0) {
return;
}
this._resizeBuffer(numVisiblePages, visiblePages);
this.renderingQueue.renderHighestPriority(visible);
this._updateHelper(visiblePages); // Run any class-specific update code.
this._updateLocation(visible.first);
this.eventBus.dispatch('updateviewarea', {
source: this,
location: this._location,
});
}
containsElement(element) {

View File

@ -111,23 +111,7 @@ class PDFSinglePageViewer extends BaseViewer {
return this._getCurrentVisiblePage();
}
update() {
let visible = this._getVisiblePages();
let visiblePages = visible.views, numVisiblePages = visiblePages.length;
if (numVisiblePages === 0) {
return;
}
this._resizeBuffer(numVisiblePages);
this.renderingQueue.renderHighestPriority(visible);
this._updateLocation(visible.first);
this.eventBus.dispatch('updateviewarea', {
source: this,
location: this._location,
});
}
_updateHelper(visiblePages) { }
get _isScrollModeHorizontal() {
// The Scroll/Spread modes are never used in `PDFSinglePageViewer`.

View File

@ -45,23 +45,14 @@ class PDFViewer extends BaseViewer {
return this._getCurrentVisiblePage();
}
update() {
let visible = this._getVisiblePages();
let visiblePages = visible.views, numVisiblePages = visiblePages.length;
if (numVisiblePages === 0) {
_updateHelper(visiblePages) {
if (this.isInPresentationMode) {
return;
}
this._resizeBuffer(numVisiblePages, visiblePages);
this.renderingQueue.renderHighestPriority(visible);
let currentId = this._currentPageNumber;
let stillFullyVisible = false;
for (let i = 0; i < numVisiblePages; ++i) {
let page = visiblePages[i];
for (const page of visiblePages) {
if (page.percent < 100) {
break;
}
@ -70,21 +61,12 @@ class PDFViewer extends BaseViewer {
break;
}
}
if (!stillFullyVisible) {
currentId = visiblePages[0].id;
}
if (!this.isInPresentationMode) {
this._setCurrentPageNumber(currentId);
}
this._updateLocation(visible.first);
this.eventBus.dispatch('updateviewarea', {
source: this,
location: this._location,
});
}
get _isScrollModeHorizontal() {
// Used to ensure that pre-rendering of the next/previous page works
// correctly, since Scroll/Spread modes are ignored in Presentation Mode.