From 8f24415a46fc56c4307ef79d8f256f5b2ebc7723 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sat, 16 May 2020 16:00:19 +0200 Subject: [PATCH] Remove the SystemJS dependency from the `web/preferences.js` file Originally the `default_preferences.json` file was checked into the repository, and we thus needed to load it in non-PRODUCTION mode (which was originally done asynchronously using `XMLHttpRequest`). Over the years a lot has changed and the `default_preferences.json` file is now built, by the `gulp default_preferences` task, from the `web/app_options.js` file. Hence it's no longer necessary, in non-PRODUCTION mode, to use SystemJS here since we can simply use a standard `import` statement instead. Note how e.g. `web/app.js` already imports from `web/app_options.js` in the same exact way that `web/preferences.js` now does, hence this patch will *not* result in any significant changes in the built/bundled viewer file. This is another (small) part in trying to reduce usage of SystemJS, with the goal of hopefully getting rid of it completely. (I've started working on this, and doing so has identified a number of problem areas; this patch addresses one of them.) --- web/preferences.js | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/web/preferences.js b/web/preferences.js index f917cdfce..d21e02f74 100644 --- a/web/preferences.js +++ b/web/preferences.js @@ -13,23 +13,19 @@ * limitations under the License. */ +import { AppOptions, OptionKind } from "./app_options.js"; + let defaultPreferences = null; function getDefaultPreferences() { if (!defaultPreferences) { - if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("PRODUCTION")) { + if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("PRODUCTION")) { + defaultPreferences = Promise.resolve( + AppOptions.getAll(OptionKind.PREFERENCE) + ); + } else { defaultPreferences = Promise.resolve( PDFJSDev.json("$ROOT/build/default_preferences.json") ); - } else { - defaultPreferences = new Promise(function (resolve, reject) { - if (typeof SystemJS === "object") { - SystemJS.import("./app_options.js").then(resolve, reject); - } else { - reject(new Error("SystemJS must be used to load AppOptions.")); - } - }).then(function ({ AppOptions, OptionKind }) { - return AppOptions.getAll(OptionKind.PREFERENCE); - }); } } return defaultPreferences;