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

Refactor the getTempCanvas function in pdf_thumbnail_view.js to a factory, in preparation for ES6 conversion of the thumbnail related code #8458

Merged
merged 1 commit into from
May 30, 2017

Conversation

Snuffleupagus
Copy link
Collaborator

@Snuffleupagus Snuffleupagus commented May 30, 2017

This patch intends to simplify future ES6 refactoring of the thumbnail code, since the current code isn't going to work well together with proper Classes.

Edit: Somewhat simpler reviewing with https://github.com/mozilla/pdf.js/pull/8458/files?w=1.

… factory, in preparation for ES6 conversion of the thumbnail related code

This patch intends to simplify future ES6 refactoring of the thumbnail code, since the current code isn't going to work well together with proper `Class`es.
Copy link
Contributor

@timvandermeij timvandermeij left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have some questions about this, but I like the idea in general. Coincidentally I had been fiddling with this last weekend, but I couldn't figure out why it had to be so complex, so I left it in favor of the overlay manager PR. I'm hoping you can provide the answer for that concern :-)

@@ -32,35 +32,52 @@ var THUMBNAIL_CANVAS_BORDER_WIDTH = 1; // px
* but increases the overall memory usage. The default value is false.
*/

const TempImageFactory = (function TempImageFactoryClosure() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a particular reason to not make this a class like the other factories?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I wanted to keep the actual canvas private, and that cannot be done using classes (at least not as they are specified in ES6, but hopefully that changes in a future EcmaScript version).

Also, please keep in mind that currently all PDFThumbnailViews share just one temporary canvas, so a class would be overkill here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough. Let's keep it this way then.

@@ -405,11 +423,13 @@ var PDFThumbnailView = (function PDFThumbnailViewClosure() {
},
};

PDFThumbnailView.cleanup = function() {
Copy link
Contributor

@timvandermeij timvandermeij May 30, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not really understand why we need this construction (and why we even have it at the moment). How I see it is that PDFThumbnailViewer manages all PDFThumbnailView instances. Wouldn't it be much easier and more logical to move this cleanup logic to PDFThumbnailViewer instead? PDFThumbnailViewer.cleanup would then:

  • go over all PDFThumbnailView instances and destroy them;
  • call the factory's destroyCanvas method to delete the shared canvas.

Unless I'm missing something in my analysis, that should get rid of this construction altogether and have the PDFThumbnailViewer and PDFThumbnailView functionality completely split.

Copy link
Collaborator Author

@Snuffleupagus Snuffleupagus May 30, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the temporary canvas is only used by PDFThumbnailView, the PDFThumbnailViewer really shouldn't know anything about it (the current code isn't correct in my opinion).

What you're commenting on is a static method, i.e. one that is shared between all PDFThumbnailView instances, so there's nothing to iterate over here!

Edit: Note that the {PDFViewer, PDFThumbnailViewer}.cleanup methods are called from PDFViewerApplication.cleanup (see https://github.com/mozilla/pdf.js/blob/master/web/app.js#L1122). This is related to PDFRenderingQueue cleanup, and not destroying of documents on close (or similar).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. Maybe I'm worried for nothing; it looks a bit strange, but it's because the one canvas is shared among PDFThumbnailView instances. If there would be one per instance, it would be a lot simpler, but we don't want that for memory reasons. I'm fine with this then. Sorry for the noise!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries; I suppose that I can see why this looks a bit strange on first sight!

With ES6 classes, this particular code becomes slightly less verbose, since static methods are placed among "regular" ones; using the static cleanup() { ... } notation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good, I think having that method explicitly defined as static among the other ones would resolve the concern I had here in terms of code readability.

@timvandermeij
Copy link
Contributor

/botio-linux preview

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Received

Command cmd_preview from @timvandermeij received. Current queue size: 1

Live output at: http://54.67.70.0:8877/134460a85d92163/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Success

Full output at http://54.67.70.0:8877/134460a85d92163/output.txt

Total script time: 2.02 mins

Published

@timvandermeij
Copy link
Contributor

/botio lint

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Received

Command cmd_lint from @timvandermeij received. Current queue size: 0

Live output at: http://54.67.70.0:8877/ca5638ffb8a2387/output.txt

@pdfjsbot
Copy link

From: Bot.io (Windows)


Received

Command cmd_lint from @timvandermeij received. Current queue size: 1

Live output at: http://54.215.176.217:8877/2afa9728310e6f8/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Success

Full output at http://54.67.70.0:8877/ca5638ffb8a2387/output.txt

Total script time: 0.99 mins

  • Lint: Passed

@timvandermeij timvandermeij merged commit 9637783 into mozilla:master May 30, 2017
@timvandermeij
Copy link
Contributor

Thank you for refactoring this!

@pdfjsbot
Copy link

From: Bot.io (Windows)


Success

Full output at http://54.215.176.217:8877/2afa9728310e6f8/output.txt

Total script time: 3.35 mins

  • Lint: Passed

@Snuffleupagus Snuffleupagus deleted the thumbnails-TempImageFactory branch May 31, 2017 08:35
movsb pushed a commit to movsb/pdf.js that referenced this pull request Jul 14, 2018
…geFactory

Refactor the `getTempCanvas` function in `pdf_thumbnail_view.js` to a factory, in preparation for ES6 conversion of the thumbnail related code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants