mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-08 01:10:08 +02:00
Re-factor how the compatibilityParams
, in the viewer, are handled
Previously we'd simply export this directly from `web/app_options.js`, which meant that it'd be technically possible to *accidentally* modify the `compatibilityParams` Object when accessing it. To avoid this we instead introduce a new `AppOptions`-method that is used to lookup data in `compatibilityParams`, which means that we no longer need to export this Object. Based on these changes, it's now possible to simplify some existing code in `AppOptions` by taking full advantage of the nullish coalescing (`??`) operator.
This commit is contained in:
parent
90b2664622
commit
38004b65b1
2 changed files with 18 additions and 24 deletions
|
@ -438,16 +438,17 @@ class AppOptions {
|
|||
throw new Error("Cannot initialize AppOptions.");
|
||||
}
|
||||
|
||||
static getCompat(name) {
|
||||
return compatibilityParams[name] ?? undefined;
|
||||
}
|
||||
|
||||
static get(name) {
|
||||
const userOption = userOptions[name];
|
||||
if (userOption !== undefined) {
|
||||
return userOption;
|
||||
}
|
||||
const defaultOption = defaultOptions[name];
|
||||
if (defaultOption !== undefined) {
|
||||
return compatibilityParams[name] ?? defaultOption.value;
|
||||
}
|
||||
return undefined;
|
||||
return (
|
||||
userOptions[name] ??
|
||||
compatibilityParams[name] ??
|
||||
defaultOptions[name]?.value ??
|
||||
undefined
|
||||
);
|
||||
}
|
||||
|
||||
static getAll(kind = null, defaultOnly = false) {
|
||||
|
@ -458,16 +459,9 @@ class AppOptions {
|
|||
if (kind && !(kind & defaultOption.kind)) {
|
||||
continue;
|
||||
}
|
||||
if (defaultOnly) {
|
||||
options[name] = defaultOption.value;
|
||||
continue;
|
||||
}
|
||||
const userOption = userOptions[name];
|
||||
|
||||
options[name] =
|
||||
userOption !== undefined
|
||||
? userOption
|
||||
: compatibilityParams[name] ?? defaultOption.value;
|
||||
options[name] = defaultOnly
|
||||
? defaultOption.value
|
||||
: userOptions[name] ?? compatibilityParams[name] ?? defaultOption.value;
|
||||
}
|
||||
return options;
|
||||
}
|
||||
|
@ -501,4 +495,4 @@ class AppOptions {
|
|||
}
|
||||
}
|
||||
|
||||
export { AppOptions, compatibilityParams, OptionKind };
|
||||
export { AppOptions, OptionKind };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue