mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-09 09:45:42 +02:00
Use more optional chaining in the code-base
This patch updates a bunch of older code, that makes conditional function calls, to use optional chaining rather than `if`-blocks. These mostly mechanical changes reduce the size of the `gulp mozcentral` build by a little over 1 kB.
This commit is contained in:
parent
9578152ae4
commit
38ee28b1d3
15 changed files with 51 additions and 119 deletions
|
@ -100,16 +100,12 @@ class App extends PDFObject {
|
|||
const timeout = Object.create(null);
|
||||
const id = { callbackId, interval };
|
||||
this._timeoutIds.set(timeout, id);
|
||||
if (this._timeoutIdsRegistry) {
|
||||
this._timeoutIdsRegistry.register(timeout, id);
|
||||
}
|
||||
this._timeoutIdsRegistry?.register(timeout, id);
|
||||
return timeout;
|
||||
}
|
||||
|
||||
_unregisterTimeout(timeout) {
|
||||
if (this._timeoutIdsRegistry) {
|
||||
this._timeoutIdsRegistry.unregister(timeout);
|
||||
}
|
||||
this._timeoutIdsRegistry?.unregister(timeout);
|
||||
|
||||
const data = this._timeoutIds.get(timeout);
|
||||
if (!data) {
|
||||
|
|
|
@ -950,10 +950,9 @@ class Doc extends PDFObject {
|
|||
}
|
||||
|
||||
getPrintParams() {
|
||||
if (!this._printParams) {
|
||||
this._printParams = new PrintParams({ lastPage: this._numPages - 1 });
|
||||
}
|
||||
return this._printParams;
|
||||
return (this._printParams ||= new PrintParams({
|
||||
lastPage: this._numPages - 1,
|
||||
}));
|
||||
}
|
||||
|
||||
getSound() {
|
||||
|
|
|
@ -91,9 +91,7 @@ class EventDispatcher {
|
|||
} else if (id === "app" && baseEvent.name === "ResetForm") {
|
||||
for (const fieldId of baseEvent.ids) {
|
||||
const obj = this._objects[fieldId];
|
||||
if (obj) {
|
||||
obj.obj._reset();
|
||||
}
|
||||
obj?.obj._reset();
|
||||
}
|
||||
}
|
||||
return;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue