Skip to content

Commit

Permalink
fix(test): Fix possible sanity test bug (#1117)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mingze authored and mergify[bot] committed Dec 13, 2019
1 parent 7472809 commit dc71bed
Showing 1 changed file with 12 additions and 1 deletion.
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

0 comments on commit dc71bed

Please sign in to comment.