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

Replace unnecessary bind(this) statements with arrow functions in web/ files #8377

Merged
merged 1 commit into from
May 4, 2017
Merged

Replace unnecessary bind(this) statements with arrow functions in web/ files #8377

merged 1 commit into from
May 4, 2017

Conversation

Snuffleupagus
Copy link
Collaborator

By using let, which is block-scoped, instead of var in a couple of places we're able to get rid of additional bind calls.

…web/` files

By using `let`, which is block-scoped, instead of `var` in a couple of places we're able to get rid of additional `bind` calls.
@yurydelendik
Copy link
Contributor

/botio-windows preview

@pdfjsbot
Copy link

pdfjsbot commented May 4, 2017

From: Bot.io (Windows)


Received

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

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

@pdfjsbot
Copy link

pdfjsbot commented May 4, 2017

From: Bot.io (Windows)


Success

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

Total script time: 19.74 mins

Published

@@ -383,8 +383,8 @@ var PDFViewer = (function pdfViewer() {
return;
}
var getPagesLeft = pagesCount;
for (var pageNum = 1; pageNum <= pagesCount; ++pageNum) {
pdfDocument.getPage(pageNum).then(function(pageNum, pdfPage) {
for (let pageNum = 1; pageNum <= pagesCount; ++pageNum) {
Copy link
Contributor

Choose a reason for hiding this comment

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

this was just converted into "var" for translated code, do we need to move let inside for-block?

Copy link
Contributor

@yurydelendik yurydelendik May 4, 2017

Choose a reason for hiding this comment

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

let make it for(var i = 1; i <= pagesCount; i++) { let pageNum = i;

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Unless I'm missing something, this shouldn't be a problem. Note that Babel converts a loop with let into a loop over a function, thus creating the necessary closure; see e.g. this simple example.

The complete code, taken from the preview above, thus becomes:

onePageRenderedCapability.promise.then(function () {
  if (_pdfjs.PDFJS.disableAutoFetch) {
    pagesCapability.resolve();
    return;
  }
  var getPagesLeft = pagesCount;

  var _loop = function _loop(_pageNum) {
    pdfDocument.getPage(_pageNum).then(function (pdfPage) {
      var pageView = _this._pages[_pageNum - 1];
      if (!pageView.pdfPage) {
        pageView.setPdfPage(pdfPage);
      }
      _this.linkService.cachePageRef(_pageNum, pdfPage.ref);
      if (--getPagesLeft === 0) {
        pagesCapability.resolve();
      }
    });
  };

  for (var _pageNum = 1; _pageNum <= pagesCount; ++_pageNum) {
    _loop(_pageNum);
  }
});

Copy link
Contributor

Choose a reason for hiding this comment

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

okay, nvm, I looked at wrong place

@yurydelendik yurydelendik merged commit b0a796c into mozilla:master May 4, 2017
@yurydelendik
Copy link
Contributor

Thank you for the patch.

@Snuffleupagus Snuffleupagus deleted the web-rm-bind branch May 4, 2017 17:55
movsb pushed a commit to movsb/pdf.js that referenced this pull request Jul 14, 2018
Replace unnecessary `bind(this)` statements with arrow functions in `web/` files
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