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

Convert the files in the /web folder to ES6 modules #8203

Merged
merged 3 commits into from
Apr 13, 2017
Merged

Convert the files in the /web folder to ES6 modules #8203

merged 3 commits into from
Apr 13, 2017

Conversation

Snuffleupagus
Copy link
Collaborator

@Snuffleupagus Snuffleupagus commented Mar 28, 2017

Please refer to the individual commit messages; careful testing will be necessary here.

As discussed on IRC, this makes the viewer slightly slower to load only in gulp server mode, however the difference seem slight enough that I think it will be fine.

Please Note: When looking at the second commit, ignoring whitespace by appending the ?w=1 flag to the URL is probably necessary in order to be able to actually read the diff.


This change is Reviewable

web/app.js Outdated
@@ -41,6 +41,12 @@ import { SecondaryToolbar } from 'pdfjs-web/secondary_toolbar';
import { Toolbar } from 'pdfjs-web/toolbar';
import { ViewHistory } from 'pdfjs-web/view_history';

var {
Copy link
Contributor

Choose a reason for hiding this comment

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

In contrast to the commit message, this does not actually remove import * as pdfjsLib from 'pdfjs-web/pdfjs';. Why not, i.e., why is this particular instance being done this way instead of altering the * import like the other occurrences in this diff?

Copy link
Collaborator Author

@Snuffleupagus Snuffleupagus Mar 28, 2017

Choose a reason for hiding this comment

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

Please note that https://github.com/mozilla/pdf.js/blob/master/web/debugger.js is currently being initialized with the entire pdfjsLib object, and I just didn't fancy re-factoring that code too in this already quite large PR.

Edit: But I suppose that I can attempt to do that if you insist :-)

Copy link
Contributor

Choose a reason for hiding this comment

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

Good call. I didn't notice that, so I wondered why this was different. Looks good to me in that case.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I looked through debugger.js quickly, and it seems that it only uses two of the pdfjsLib properties. Hence I've changed the initialization to only pass in those when calling PDFBug.init instead, and subsequently this point is now fixed :-)

var scrollIntoView = uiUtils.scrollIntoView;
var PDFThumbnailView = pdfThumbnailView.PDFThumbnailView;
import { getVisibleElements, scrollIntoView, watchScroll
} from 'pdfjs-web/ui_utils';
Copy link
Contributor

@timvandermeij timvandermeij Mar 28, 2017

Choose a reason for hiding this comment

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

I think this could be improved in terms of how we write multiline imports. Personally I would find the following easier to read:

import {
  getVisibleElements, scrollIntoView, watchScroll
} from 'pdfjs-web/ui_utils';

I don't know if there are actual conventions for this, but otherwise we should choose something that is the most readable and use it consistently. I think I just find the line starting with the indented curly bracket a bit strange.

This is a nit, but I figured I'd comment it now so we can make a decision (either this suggestion or your current version or something else) and stick with it for future PRs.

Copy link
Collaborator Author

@Snuffleupagus Snuffleupagus Mar 28, 2017

Choose a reason for hiding this comment

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

I went back and forth a bit on the matter of formatting multi-line imports when writing the code.
In a way, I think it's more important that the exports are clear and readable, since ESLint will complain if you e.g. forget an import or import something that is unused.

However, if you think that readability is too much of an issue with the current import style, I can certainly change it as suggested.

Copy link
Contributor

@timvandermeij timvandermeij Mar 28, 2017

Choose a reason for hiding this comment

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

I would vote for the suggested notation because it makes the imports more readable in my opinion (somewhat similar to the object notation).

@yurydelendik Do you have a preference for a particular notation?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, but it might be complicated rule: if entire import including { and } can fit into single line then it's good as is, otherwise several lines first is import { and last is } from 'mod';

import { single } from 'first';
import {
  one, two, THREE, four as fourOfSecond, etc
} from 'second';

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The style of the multi-line imports has been changed as requested, thank you both for the feedback!

@Snuffleupagus
Copy link
Collaborator Author

Snuffleupagus commented Apr 2, 2017

The logical follow-up to this PR would be to convert the files in the /src folder as well, but as discussed that more or less breaks both gulp server and unit/browser testing since everything becomes super slow. However, once built everything runs just fine!

For reference, in case it's useful with regards to asking for configuration advice and/or reporting bugs to SystemJS/Babel, here's a branch that converts everything in the /src folder to ES6 modules: https://github.com/mozilla/pdf.js/compare/master...Snuffleupagus:es6-modules-src?w=1.

@timvandermeij
Copy link
Contributor

timvandermeij commented Apr 2, 2017

Good point. While that should not block this PR, it should be investigated what is making things slow. Did you try to run it without Babel (since that performs transformations on the JavaScript)?

Should we first release a new version before reviewing/merging this?

@Snuffleupagus
Copy link
Collaborator Author

Should we first release a new version before reviewing/merging this?

That was suggested by Yury on IRC, and I completely concur that it's a good idea!

…uilds, to avoid issues when converting the code to ES6 modules
Note that as discussed on IRC, this makes the viewer slightly slower to load *only* in `gulp server` mode, however the difference seem slight enough that I think it will be fine.
…ses to only specify the necessary imports

Rather than always importing everything from the `web/pdfjs.js`, similar to all other imports we can just choose what we actually need.
@Snuffleupagus
Copy link
Collaborator Author

/botio unittest

@pdfjsbot
Copy link

pdfjsbot commented Apr 9, 2017

From: Bot.io (Linux)


Received

Command cmd_unittest from @Snuffleupagus received. Current queue size: 0

Live output at: http://107.21.233.14:8877/2713d751f9a85e3/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Apr 9, 2017

From: Bot.io (Windows)


Received

Command cmd_unittest from @Snuffleupagus received. Current queue size: 0

Live output at: http://54.215.176.217:8877/da3240890777411/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Apr 9, 2017

From: Bot.io (Linux)


Success

Full output at http://107.21.233.14:8877/2713d751f9a85e3/output.txt

Total script time: 2.59 mins

  • Unit Tests: Passed

@pdfjsbot
Copy link

pdfjsbot commented Apr 9, 2017

From: Bot.io (Windows)


Success

Full output at http://54.215.176.217:8877/da3240890777411/output.txt

Total script time: 6.70 mins

  • Unit Tests: Passed

@pdfjsbot
Copy link

pdfjsbot commented Apr 9, 2017

From: Bot.io (Linux)


Received

Command cmd_preview from @Snuffleupagus received. Current queue size: 0

Live output at: http://107.21.233.14:8877/44dbb32d89ae21b/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Apr 9, 2017

From: Bot.io (Linux)


Success

Full output at http://107.21.233.14:8877/44dbb32d89ae21b/output.txt

Total script time: 2.75 mins

Published

@yurydelendik
Copy link
Contributor

Okay, let's try this. Thank you for the patch.

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.

4 participants