Skip to content

Commit

Permalink
Clean-up getMainThreadWorkerMessageHandler for non-PRODUCTION mode
Browse files Browse the repository at this point in the history
*This is a final piece of clean-up of code that I recently wrote, after which I'm done :-)*

When the `getMainThreadWorkerMessageHandler` function was added, in PR 9385, it did so by basically introducing a `web/app.js` dependency in `src/display/api.js` through the `window.pdfjsNonProductionPdfWorker` property[1]. Even though this is limited to non-`PRODUCTION` mode, i.e. `gulp server`, it still seems unfortunate to have that sort of viewer dependency in the API code itself.

With the new, much nicer and shorter, names introduced in PR 9565 we can remove this non-`PRODUCTION` hack and just use `window.pdfjsWorker` in both the viewer and the API regardless of the build mode.

---

[1] It didn't seem correct to piggy-back on the `window.pdfjsDistBuildPdfWorker` property in non-`PRODUCTION` mode.
  • Loading branch information
Snuffleupagus committed Mar 29, 2018
1 parent a8e9f6c commit 8b09f7c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 9 deletions.
8 changes: 1 addition & 7 deletions src/display/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -1317,13 +1317,7 @@ var PDFWorker = (function PDFWorkerClosure() {
if (typeof window === 'undefined') {
return null;
}
if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('PRODUCTION')) {
return (window.pdfjsNonProductionPdfWorker &&
window.pdfjsNonProductionPdfWorker.WorkerMessageHandler);
}
// PRODUCTION
return (window.pdfjsWorker &&
window.pdfjsWorker.WorkerMessageHandler);
return (window.pdfjsWorker && window.pdfjsWorker.WorkerMessageHandler);
}

let fakeWorkerFilesLoadedCapability;
Expand Down
4 changes: 2 additions & 2 deletions web/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -1524,11 +1524,11 @@ function loadFakeWorker() {
if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('PRODUCTION')) {
if (typeof SystemJS === 'object') {
SystemJS.import('pdfjs/core/worker').then((worker) => {
window.pdfjsNonProductionPdfWorker = worker;
window.pdfjsWorker = worker;
resolve();
});
} else if (typeof require === 'function') {
window.pdfjsNonProductionPdfWorker = require('../src/core/worker.js');
window.pdfjsWorker = require('../src/core/worker.js');
resolve();
} else {
reject(new Error(
Expand Down

0 comments on commit 8b09f7c

Please sign in to comment.