-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Move the Preferences
initialization/fetching code to the top of PDFViewerApplication.initialize
, to enable using them when initializing e.g. the viewer components
#7886
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
Move the Preferences
initialization/fetching code to the top of PDFViewerApplication.initialize
, to enable using them when initializing e.g. the viewer components
#7886
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good with following changes:
- we still need to dispatch('localized') event even if we will not handle it (for backwards compatibility)
- we have lots of closures inside the
initialize
, can we refactor and move them in some private smaller methods, and just chain calls there.
Thank you for the review comments!
Sure, I'll undo the removal. A couple of questions first though:
Good point, I'll try to do that. |
Just GENERIC build is fine and it can done sometime during initialization (in addition to what you have now) |
I've now no restored the 'localized' event in /botio-linux preview |
Having just remembered issue #7797, should I simply move the various |
Besides re-factoring the viewer initialization into helper methods, the latest version of the also PR moves the /botio-windows preview |
From: Bot.io (Windows)ReceivedCommand cmd_preview from @Snuffleupagus received. Current queue size: 0 Live output at: http://107.22.172.223:8877/02730e8a742eeb1/output.txt |
From: Bot.io (Windows)SuccessFull output at http://107.22.172.223:8877/02730e8a742eeb1/output.txt Total script time: 3.35 mins Published |
@yurydelendik Since you reviewed, and approved, this PR a number of changes have been made: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thank you.
|
||
this.toolbar = new Toolbar(appConfig.toolbar, container, eventBus); | ||
return this._readPreferences().then(function () { | ||
return self._initializeViewerComponents().then(function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: to reduce indentation level return _initializeViewerComponents promise and move closure to the outer promise then:
return self._initializeViewerComponents();
}).then(function() {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call, fixed now!
… reads the Preferences and one that initializes the various viewer components
…FViewerApplication.initialize`, to enable using them when initializing e.g. the viewer components Note that in quick testing using `console.time/timeEnd`, both locally and with the Firefox addon, the total run time of the *entire* `PDFViewerApplication.initialize` function does not seem to change with this patch.
…alized, and move binding of `window` event listeners to a helper method, to prevent errors if an event manages to arrive too soon With `bindEvents()` now being called after the viewer has been initialized, we no longer need to have `PDFViewerApplication.initialized` checks in the event handler functions. Furthermore by moving the `window.addEventListener`s to a helper method, `PDFViewerApplication.initialized` checks are no longer necessary in the event handlers, hence we thus address part of issue 7797 here as well.
…ized' event to use the `localized` Promise instead, and only re-dispatch the 'localized' event on the `eventBus` for `GENERIC` builds Ideally we'd remove the 'localized' event from the `eventBus`, but for backwards compatibility we keep it in `GENERIC` builds. Note that while we want to ensure that the direction attribute of the HTML is updated as soon as the `localized` Promise is resolved, we purposely wait until the viewer has been initialized to ensure that the 'localized' event will always be dispatched.
Thanks for the review! /botio-linux preview |
From: Bot.io (Linux)ReceivedCommand cmd_preview from @Snuffleupagus received. Current queue size: 1 Live output at: http://107.21.233.14:8877/96340f6e4b36559/output.txt |
From: Bot.io (Linux)SuccessFull output at http://107.21.233.14:8877/96340f6e4b36559/output.txt Total script time: 2.15 mins Published |
Nice work! This makes the code much more readable. |
…alization Move the `Preferences` initialization/fetching code to the top of `PDFViewerApplication.initialize`, to enable using them when initializing e.g. the viewer components
This is a new attempt at implementing, the main feature of, PR #7586. With the changes made to the 'localized' event in PR #7789, and the first commits here, this should avoid the issues with the Firefox addon that caused the previous PR to be backed out; see #7586 (comment).
I'd suggest looking at one commit at a time, and using the
?w=1
flag should help reduce (or at least simplify) the larger diffs somewhat. Please also note that GitHub may list the commits in a sub-optimal order, according to date, but they should be reviewed as follows:Refactor
PDFViewerApplication.initialize
into two methods, one that reads the Preferences and one that initializes the various viewer componentsMove the
Preferences
initialization/fetching code to the top ofPDFViewerApplication.initialize
, to enable using them when initializing e.g. the viewer componentsDon't call
bindEvents()
untilPDFViewerApplication
has been initialized, and move binding ofwindow
event listeners to a helper method, to prevent errors if an event manages to arrive too soonConvert the only remaining consumer (in
hand_tool.js
) of the 'localized' event to use thelocalized
Promise instead, and only re-dispatch the 'localized' event on theeventBus
forGENERIC
buildsThis change is