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

Improve code structure of the annotation code #6699

Merged
merged 1 commit into from
Dec 1, 2015

Conversation

timvandermeij
Copy link
Contributor

This patch improves the code structure of the annotation code.

  • Create the annotation border style object in the setBorderStyle method instead of in the constructor. The behavior is the same as the setBorderStyle method is always called, thus a border style object is still always available.
  • Put all data object manipulation lines in one block in the constructor. This improves readability and maintainability as it is more visible which properties are exposed.
  • Simplify appendToOperatorList by removing the promise capability and removing an unused parameter.
  • Remove some unnecessary newlines/spaces.

I have tested this patch with a set of 21 PDF files with different types of annotations and the behavior is the same as before this patch.

@Snuffleupagus
Copy link
Collaborator

I'm wondering if we shouldn't instead bring back the getData() method on the (various) Annotation kinds, and let that return an object containing all the necessary properties?
That way, we'd avoid the current "double bookkeeping" we're having to do for this.<propertyName> vs data.<propertyName>. (Obviously that'd would require some re-factoring in a couple of the Annotations, to change data -> this, but it seems like the right thing to do in general.)

@timvandermeij
Copy link
Contributor Author

I agree that that appears to be the right approach to tackle the double bookkeeping problem. Is it okay if I do that in a follow-up PR and keep this PR as is for the minor changes in structure (as I think it helps to keep that larger refactoring separate from these minor code structure updates)?

@Snuffleupagus
Copy link
Collaborator

Is it okay if I do that in a follow-up PR and keep this PR just for the minor changes in structure

That is probably best, so that's fine by me!
Also, we should ensure that the follow-up addresses issue #6680, to avoid unneeded churn in the code.

}, reject);
}, function(reason) {
annotationsReadyCapability.reject(reason);
});
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would it be possible to simplify this even further, by removing the PromiseCapability all together? E.g. like this:

return Promise.all(annotationPromises).then(function(datas) {
  opList.addOp(OPS.beginAnnotations, []);
  for (var i = 0, n = datas.length; i < n; ++i) {
    var annotOpList = datas[i];
    opList.addOpList(annotOpList);
  }
  opList.addOp(OPS.endAnnotations, []);
});  

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice suggestion! I have done this in the new commit, also with more descriptive variable names (as datas was a bit undescriptive in my opinion).

@timvandermeij timvandermeij force-pushed the annotation-refactoring branch 4 times, most recently from 3559c6b to c89dd85 Compare November 28, 2015 23:01
@timvandermeij timvandermeij changed the title Minor refactoring for src/core/annotation.js Improve code structure of the annotation code Nov 28, 2015
This patch improves the code structure of the annotation code.

- Create the annotation border style object in the `setBorderStyle` method instead of in the constructor. The behavior is the same as the `setBorderStyle` method is always called, thus a border style object is still always available.
- Put all data object manipulation lines in one block in the constructor. This improves readability and maintainability as it is more visible which properties are exposed.
- Simplify `appendToOperatorList` by removing the promise capability and removing an unused parameter.
- Remove some unnecessary newlines/spaces.
@timvandermeij
Copy link
Contributor Author

/botio-linux preview

@pdfjsbot
Copy link

From: Bot.io (Linux)


Received

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

Live output at: http://107.21.233.14:8877/dc336f224820b08/output.txt

@timvandermeij
Copy link
Contributor Author

/botio test

@pdfjsbot
Copy link

From: Bot.io (Linux)


Received

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

Live output at: http://107.21.233.14:8877/25770b516db06ce/output.txt

@pdfjsbot
Copy link

From: Bot.io (Windows)


Received

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

Live output at: http://107.22.172.223:8877/6f31cb7a594675d/output.txt

@pdfjsbot
Copy link

From: Bot.io (Windows)


Success

Full output at http://107.22.172.223:8877/6f31cb7a594675d/output.txt

Total script time: 18.75 mins

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

@pdfjsbot
Copy link

From: Bot.io (Linux)


Success

Full output at http://107.21.233.14:8877/25770b516db06ce/output.txt

Total script time: 19.94 mins

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

Snuffleupagus added a commit that referenced this pull request Dec 1, 2015
Improve code structure of the annotation code
@Snuffleupagus Snuffleupagus merged commit 361fa83 into mozilla:master Dec 1, 2015
@Snuffleupagus
Copy link
Collaborator

Looks good, thank you for the patch.

@timvandermeij timvandermeij deleted the annotation-refactoring branch December 1, 2015 20:24
@timvandermeij
Copy link
Contributor Author

Thank you for the helpful review comments for this one!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants