Skip to content

Commit

Permalink
Re-factor how the "compatibility" values are specified in AppOptions
Browse files Browse the repository at this point in the history
The intention with this change is to, more clearly, highlight when the default values may possibly be overridden by "compatibility" values.
  • Loading branch information
Snuffleupagus committed Feb 2, 2019
1 parent 9d83420 commit ef634b5
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions web/app_options.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ const defaultOptions = {
*/
maxCanvasPixels: {
/** @type {number} */
value: viewerCompatibilityParams.maxCanvasPixels || 16777216,
value: 16777216,
compatibility: viewerCompatibilityParams.maxCanvasPixels,
kind: OptionKind.VIEWER,
},
pdfBugEnabled: {
Expand Down Expand Up @@ -163,7 +164,8 @@ const defaultOptions = {
},
disableCreateObjectURL: {
/** @type {boolean} */
value: apiCompatibilityParams.disableCreateObjectURL || false,
value: false,
compatibility: apiCompatibilityParams.disableCreateObjectURL,
kind: OptionKind.API,
},
disableFontFace: {
Expand Down Expand Up @@ -241,22 +243,27 @@ class AppOptions {
}

static get(name) {
let defaultOption = defaultOptions[name], userOption = userOptions[name];
const userOption = userOptions[name];
if (userOption !== undefined) {
return userOption;
}
return (defaultOption !== undefined ? defaultOption.value : undefined);
const defaultOption = defaultOptions[name];
if (defaultOption !== undefined) {
return (defaultOption.compatibility || defaultOption.value);
}
return undefined;
}

static getAll(kind = null) {
let options = Object.create(null);
for (let name in defaultOptions) {
let defaultOption = defaultOptions[name], userOption = userOptions[name];
if (kind && defaultOption.kind !== kind) {
const options = Object.create(null);
for (const name in defaultOptions) {
const defaultOption = defaultOptions[name];
if (kind && kind !== defaultOption.kind) {
continue;
}
options[name] = (userOption !== undefined ?
userOption : defaultOption.value);
const userOption = userOptions[name];
options[name] = (userOption !== undefined ? userOption :
(defaultOption.compatibility || defaultOption.value));
}
return options;
}
Expand Down

0 comments on commit ef634b5

Please sign in to comment.