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) and var self = this statements with arrow functions in remaining src/core/ files #8357

Merged
merged 1 commit into from
May 2, 2017

Conversation

Snuffleupagus
Copy link
Collaborator

@Snuffleupagus Snuffleupagus commented May 2, 2017

Smaller diff with https://github.com/mozilla/pdf.js/pull/8357/files?w=1.


This change is Reviewable

@Snuffleupagus
Copy link
Collaborator Author

/botio test

Copy link
Contributor

@yurydelendik yurydelendik left a comment

Choose a reason for hiding this comment

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

Looks good. But I think (as in #8358) we shall start using params destructuring when array is arg, especially for Promise.all, e.g.

        var dataPromises = Promise.all([contentStreamPromise, resourcesPromise]); 
        dataPromises.then(([contentStream]) => {

(at least for the affected code above)

…h arrow functions in remaining `src/core/` files
@Snuffleupagus
Copy link
Collaborator Author

Thank you for the review!

Here's an interdiff of the changes, in case that's helpful (since Reviewable didn't want to create one).

diff --git a/src/core/document.js b/src/core/document.js
index a35a0a75..c338f704 100644
--- a/src/core/document.js
+++ b/src/core/document.js
@@ -256,8 +256,7 @@ var Page = (function PageClosure() {
                                                   this.evaluatorOptions);
 
       var dataPromises = Promise.all([contentStreamPromise, resourcesPromise]);
-      var pageListPromise = dataPromises.then((data) => {
-        var [contentStream] = data;
+      var pageListPromise = dataPromises.then(([contentStream]) => {
         var opList = new OperatorList(intent, handler, this.pageIndex);
 
         handler.send('StartRenderPage', {
@@ -274,9 +273,8 @@ var Page = (function PageClosure() {
       // Fetch the page's annotations and add their operator lists to the
       // page's operator list to render them.
       var annotationsPromise = pdfManager.ensure(this, 'annotations');
-      return Promise.all([pageListPromise, annotationsPromise]).then((data) => {
-        var [pageOpList, annotations] = data;
-
+      return Promise.all([pageListPromise, annotationsPromise]).then(
+          function ([pageOpList, annotations]) {
         if (annotations.length === 0) {
           pageOpList.flush(true);
           return pageOpList;
@@ -317,8 +315,7 @@ var Page = (function PageClosure() {
       ]);
 
       var dataPromises = Promise.all([contentStreamPromise, resourcesPromise]);
-      return dataPromises.then((data) => {
-        var [contentStream] = data;
+      return dataPromises.then(([contentStream]) => {
         var partialEvaluator = new PartialEvaluator(pdfManager, this.xref,
                                                     handler, this.pageIndex,
                                                     this.idFactory,
diff --git a/src/core/obj.js b/src/core/obj.js
index d58bffbe..18d017a6 100644
--- a/src/core/obj.js
+++ b/src/core/obj.js
@@ -441,8 +441,8 @@ var Catalog = (function CatalogClosure() {
 
     getPage: function Catalog_getPage(pageIndex) {
       if (!(pageIndex in this.pagePromises)) {
-        this.pagePromises[pageIndex] = this.getPageDict(pageIndex).then((a) => {
-          var [dict, ref] = a;
+        this.pagePromises[pageIndex] = this.getPageDict(pageIndex).then(
+            ([dict, ref]) => {
           return this.pageFactory.createPage(pageIndex, dict, ref,
                                              this.fontCache,
                                              this.builtInCMapCache);

@Snuffleupagus
Copy link
Collaborator Author

/botio test

@pdfjsbot
Copy link

pdfjsbot commented May 2, 2017

From: Bot.io (Linux)


Received

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

Live output at: http://107.21.233.14:8877/46562ba0a0aa730/output.txt

@pdfjsbot
Copy link

pdfjsbot commented May 2, 2017

From: Bot.io (Windows)


Received

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

Live output at: http://54.215.176.217:8877/3628c731e7fab3f/output.txt

@pdfjsbot
Copy link

pdfjsbot commented May 2, 2017

From: Bot.io (Windows)


Success

Full output at http://54.215.176.217:8877/3628c731e7fab3f/output.txt

Total script time: 21.17 mins

  • Font tests: Passed
  • Unit tests: Passed
  • Regression tests: Passed

@pdfjsbot
Copy link

pdfjsbot commented May 2, 2017

From: Bot.io (Linux)


Success

Full output at http://107.21.233.14:8877/46562ba0a0aa730/output.txt

Total script time: 32.78 mins

  • Font tests: Passed
  • Unit tests: Passed
  • Regression tests: Passed

@yurydelendik yurydelendik merged commit de7002d into mozilla:master May 2, 2017
@yurydelendik
Copy link
Contributor

Thank you for the patch.

@Snuffleupagus Snuffleupagus deleted the core-rm-bind branch May 2, 2017 15:20
@timvandermeij
Copy link
Contributor

Nice work! I didn't really have experience with parameter destructuring, but it looks much shorter and more readable.

movsb pushed a commit to movsb/pdf.js that referenced this pull request Jul 14, 2018
Replace unnecessary `bind(this)` and `var self = this` statements with arrow functions in remaining `src/core/` 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.

4 participants