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 Preferences to an ES6 class #8303

Merged
merged 1 commit into from
Apr 23, 2017
Merged

Convert the Preferences to an ES6 class #8303

merged 1 commit into from
Apr 23, 2017

Conversation

Snuffleupagus
Copy link
Collaborator

@Snuffleupagus Snuffleupagus commented Apr 17, 2017

Please note that the new BasePreferences is an abstract class, and is explicitly not usable on its own, which is then sub-classed for the various build targets.

Slightly smaller diff with https://github.com/mozilla/pdf.js/pull/8303/files?w=1.

@Snuffleupagus
Copy link
Collaborator Author

/botio-linux preview

* Used for settings that should be applied to all opened documents,
* or every time the viewer is loaded.
*/
var Preferences = {
prefs: null,
isInitializedPromiseResolved: false,
Copy link
Collaborator Author

@Snuffleupagus Snuffleupagus Apr 18, 2017

Choose a reason for hiding this comment

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

This was simply removed, since there wasn't a single place in the code-base that actually used it for anything.

@timvandermeij
Copy link
Contributor

/botio-linux preview

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.

It looks like the preferences do not work anymore in the Chrome extension with this patch applied.

@@ -23,10 +24,29 @@ if (typeof PDFJSDev !== 'undefined' && !PDFJSDev.test('GENERIC')) {

var GenericCom = {};

class GenericPreferences extends BasePreferences {
_writeToStorage(prefObj) {
return new Promise((resolve) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

This does not need to be an arrow function because this is not used.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hmm, I'm not sure how I managed to mess that up, but it's fixed now. Thanks for spotting it!

}

_readFromStorage(prefObj) {
return new Promise((resolve) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

This does not need to be an arrow function because this is not used.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hmm, I'm not sure how I managed to mess that up, but it's fixed now. Thanks for spotting it!

web/chromecom.js Outdated
});
};

var getPreferences = (defaultPrefs) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't it a problem that this is defined after it is used? I think it's better to move this above the if.

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, it most certainly is, and it's also the reason that the Chrome extension wasn't working.
In hindsight, this is a really stupid mistake on my part, since I know that function expressions (in contrast with function declarations) aren't hoisted.

I did test this successfully in Chrome, but with a prior version of the patch that had the getPreferences code placed correctly. For reasons that I don't quite understand, I then figured that I'd try to reduced the size of the diff slightly, and moved it back without actually testing 😕

@Snuffleupagus
Copy link
Collaborator Author

Snuffleupagus commented Apr 23, 2017

It looks like the preferences do not work anymore in the Chrome extension with this patch applied.

A really stupid mistake on my part, please see #8303 (comment) for an explanation of the problem.
My apologies for wasting your time finding something that I should have caught myself, and thanks for reviewing this thoroughly enough to catch this!

@timvandermeij
Copy link
Contributor

/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/32a2a03f7a6df1e/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux)


Success

Full output at http://107.21.233.14:8877/32a2a03f7a6df1e/output.txt

Total script time: 3.08 mins

Published

@timvandermeij timvandermeij merged commit 5fe26bb into mozilla:master Apr 23, 2017
@timvandermeij
Copy link
Contributor

Thank you for working on this! Really nice solution with the abstract base class. No worries about the mistake; it happened to me as well and I'm glad the review process does its work to catch it.

@Snuffleupagus Snuffleupagus deleted the es6-preferences branch April 23, 2017 20:19
movsb pushed a commit to movsb/pdf.js that referenced this pull request Jul 14, 2018
Convert the `Preferences` to an ES6 class
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