Merge pull request #14116 from Snuffleupagus/api-more-optional-chaining

Use even more optional chaining in the `src/display/api.js` file
This commit is contained in:
Tim van der Meij 2021-10-13 19:38:03 +02:00 committed by GitHub
commit f6d9d91965
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2592,16 +2592,14 @@ class WorkerTransport {
// If stream or range are disabled, it's our only way to report // If stream or range are disabled, it's our only way to report
// loading progress. // loading progress.
if (!fullReader.isStreamingSupported || !fullReader.isRangeSupported) { if (!fullReader.isStreamingSupported || !fullReader.isRangeSupported) {
if (this._lastProgress && loadingTask.onProgress) { if (this._lastProgress) {
loadingTask.onProgress(this._lastProgress); loadingTask.onProgress?.(this._lastProgress);
} }
fullReader.onProgress = evt => { fullReader.onProgress = evt => {
if (loadingTask.onProgress) { loadingTask.onProgress?.({
loadingTask.onProgress({ loaded: evt.loaded,
loaded: evt.loaded, total: evt.total,
total: evt.total, });
});
}
}; };
} }
@ -2727,12 +2725,11 @@ class WorkerTransport {
messageHandler.on("DataLoaded", data => { messageHandler.on("DataLoaded", data => {
// For consistency: Ensure that progress is always reported when the // For consistency: Ensure that progress is always reported when the
// entire PDF file has been loaded, regardless of how it was fetched. // entire PDF file has been loaded, regardless of how it was fetched.
if (loadingTask.onProgress) { loadingTask.onProgress?.({
loadingTask.onProgress({ loaded: data.length,
loaded: data.length, total: data.length,
total: data.length, });
});
}
this.downloadInfoCapability.resolve(data); this.downloadInfoCapability.resolve(data);
}); });
@ -2811,13 +2808,13 @@ class WorkerTransport {
messageHandler.on("obj", data => { messageHandler.on("obj", data => {
if (this.destroyed) { if (this.destroyed) {
// Ignore any pending requests if the worker was terminated. // Ignore any pending requests if the worker was terminated.
return undefined; return;
} }
const [id, pageIndex, type, imageData] = data; const [id, pageIndex, type, imageData] = data;
const pageProxy = this.pageCache[pageIndex]; const pageProxy = this.pageCache[pageIndex];
if (pageProxy.objs.has(id)) { if (pageProxy.objs.has(id)) {
return undefined; return;
} }
switch (type) { switch (type) {
@ -2836,20 +2833,16 @@ class WorkerTransport {
default: default:
throw new Error(`Got unknown object type ${type}`); throw new Error(`Got unknown object type ${type}`);
} }
return undefined;
}); });
messageHandler.on("DocProgress", data => { messageHandler.on("DocProgress", data => {
if (this.destroyed) { if (this.destroyed) {
return; // Ignore any pending requests if the worker was terminated. return; // Ignore any pending requests if the worker was terminated.
} }
loadingTask.onProgress?.({
if (loadingTask.onProgress) { loaded: data.loaded,
loadingTask.onProgress({ total: data.total,
loaded: data.loaded, });
total: data.total,
});
}
}); });
messageHandler.on( messageHandler.on(
@ -2890,9 +2883,7 @@ class WorkerTransport {
if (this.destroyed) { if (this.destroyed) {
return; // Ignore any pending requests if the worker was terminated. return; // Ignore any pending requests if the worker was terminated.
} }
if (this.loadingTask.onUnsupportedFeature) { this.loadingTask.onUnsupportedFeature?.(featureId);
this.loadingTask.onUnsupportedFeature(featureId);
}
} }
getData() { getData() {