Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(test): Fix possible sanity test bug #1117

Merged
merged 1 commit into from
Dec 13, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/lib/ThumbnailsSidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,17 @@ class ThumbnailsSidebar {
/** @property {Object} - Cache for the thumbnail image elements */
thumbnailImageCache;

/** @property {Array<number>} - The ID values returned by the call to window.requestAnimationFrame() */
animationFrameRequestIds;

/**
* [constructor]
*
* @param {HTMLElement} element - the HTMLElement that will anchor the thumbnail sidebar
* @param {PDFViewer} pdfViewer - the PDFJS viewer
*/
constructor(element, pdfViewer) {
this.animationFrameRequestIds = [];
this.anchorEl = element;
this.currentThumbnails = [];
this.pdfViewer = pdfViewer;
Expand Down Expand Up @@ -132,6 +136,10 @@ class ThumbnailsSidebar {
* @return {void}
*/
destroy() {
if (this.animationFrameRequestIds.length > 0) {
this.animationFrameRequestIds.forEach(id => cancelAnimationFrame(id));
}

if (this.virtualScroller) {
this.virtualScroller.destroy();
this.virtualScroller = null;
Expand Down Expand Up @@ -289,7 +297,8 @@ class ThumbnailsSidebar {
* @return {void}
*/
requestThumbnailImage(itemIndex, thumbnailEl) {
requestAnimationFrame(() => {
const requestId = requestAnimationFrame(() => {
this.animationFrameRequestIds = this.animationFrameRequestIds.filter(id => id !== requestId);
this.createThumbnailImage(itemIndex).then(imageEl => {
// Promise will resolve with null if create image request was already in progress
if (imageEl) {
Expand All @@ -302,6 +311,8 @@ class ThumbnailsSidebar {
this.renderNextThumbnailImage();
});
});

this.animationFrameRequestIds.push(requestId);
}

/**
Expand Down