mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-20 15:18:08 +02:00
Change the createPromiseCapability
helper function into a PromiseCapability
class
This is not only slightly more compact, but it also simplifies the handling of the `settled` getter.
This commit is contained in:
parent
f9c2a8d437
commit
317abd6d07
24 changed files with 117 additions and 122 deletions
|
@ -36,7 +36,6 @@ import {
|
|||
import {
|
||||
AnnotationEditorType,
|
||||
build,
|
||||
createPromiseCapability,
|
||||
FeatureTest,
|
||||
getDocument,
|
||||
getFilenameFromUrl,
|
||||
|
@ -49,6 +48,7 @@ import {
|
|||
MissingPDFException,
|
||||
OPS,
|
||||
PDFWorker,
|
||||
PromiseCapability,
|
||||
shadow,
|
||||
UnexpectedResponseException,
|
||||
version,
|
||||
|
@ -156,7 +156,7 @@ class DefaultExternalServices {
|
|||
|
||||
const PDFViewerApplication = {
|
||||
initialBookmark: document.location.hash.substring(1),
|
||||
_initializedCapability: createPromiseCapability(),
|
||||
_initializedCapability: new PromiseCapability(),
|
||||
appConfig: null,
|
||||
pdfDocument: null,
|
||||
pdfLoadingTask: null,
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { createPromiseCapability, PasswordResponses } from "pdfjs-lib";
|
||||
import { PasswordResponses, PromiseCapability } from "pdfjs-lib";
|
||||
|
||||
/**
|
||||
* @typedef {Object} PasswordPromptOptions
|
||||
|
@ -69,7 +69,7 @@ class PasswordPrompt {
|
|||
if (this.#activeCapability) {
|
||||
await this.#activeCapability.promise;
|
||||
}
|
||||
this.#activeCapability = createPromiseCapability();
|
||||
this.#activeCapability = new PromiseCapability();
|
||||
|
||||
try {
|
||||
await this.overlayManager.open(this.dialog);
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { createPromiseCapability, getFilenameFromUrl } from "pdfjs-lib";
|
||||
import { getFilenameFromUrl, PromiseCapability } from "pdfjs-lib";
|
||||
import { BaseTreeViewer } from "./base_tree_viewer.js";
|
||||
import { waitOnEventOrTimeout } from "./event_utils.js";
|
||||
|
||||
|
@ -50,7 +50,7 @@ class PDFAttachmentViewer extends BaseTreeViewer {
|
|||
if (!keepRenderedCapability) {
|
||||
// The only situation in which the `_renderedCapability` should *not* be
|
||||
// replaced is when appending FileAttachment annotations.
|
||||
this._renderedCapability = createPromiseCapability();
|
||||
this._renderedCapability = new PromiseCapability();
|
||||
}
|
||||
this._pendingDispatchEvent = false;
|
||||
}
|
||||
|
|
|
@ -13,8 +13,8 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { createPromiseCapability, PDFDateString } from "pdfjs-lib";
|
||||
import { getPageSizeInches, isPortraitOrientation } from "./ui_utils.js";
|
||||
import { PDFDateString, PromiseCapability } from "pdfjs-lib";
|
||||
|
||||
const DEFAULT_FIELD_CONTENT = "-";
|
||||
|
||||
|
@ -201,7 +201,7 @@ class PDFDocumentProperties {
|
|||
this.pdfDocument = null;
|
||||
|
||||
this.#fieldData = null;
|
||||
this._dataAvailableCapability = createPromiseCapability();
|
||||
this._dataAvailableCapability = new PromiseCapability();
|
||||
this._currentPageNumber = 1;
|
||||
this._pagesRotation = 0;
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
import { binarySearchFirstItem, scrollIntoView } from "./ui_utils.js";
|
||||
import { getCharacterType, getNormalizeWithNFKC } from "./pdf_find_utils.js";
|
||||
import { createPromiseCapability } from "pdfjs-lib";
|
||||
import { PromiseCapability } from "pdfjs-lib";
|
||||
|
||||
const FindState = {
|
||||
FOUND: 0,
|
||||
|
@ -582,7 +582,7 @@ class PDFFindController {
|
|||
clearTimeout(this._findTimeout);
|
||||
this._findTimeout = null;
|
||||
|
||||
this._firstPageCapability = createPromiseCapability();
|
||||
this._firstPageCapability = new PromiseCapability();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -849,7 +849,7 @@ class PDFFindController {
|
|||
let promise = Promise.resolve();
|
||||
const textOptions = { disableNormalization: true };
|
||||
for (let i = 0, ii = this._linkService.pagesCount; i < ii; i++) {
|
||||
const extractTextCapability = createPromiseCapability();
|
||||
const extractTextCapability = new PromiseCapability();
|
||||
this._extractTextPromises[i] = extractTextCapability.promise;
|
||||
|
||||
promise = promise.then(() => {
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
*/
|
||||
|
||||
import { BaseTreeViewer } from "./base_tree_viewer.js";
|
||||
import { createPromiseCapability } from "pdfjs-lib";
|
||||
import { PromiseCapability } from "pdfjs-lib";
|
||||
import { SidebarView } from "./ui_utils.js";
|
||||
|
||||
/**
|
||||
|
@ -89,7 +89,7 @@ class PDFOutlineViewer extends BaseTreeViewer {
|
|||
* @private
|
||||
*/
|
||||
_dispatchEvent(outlineCount) {
|
||||
this._currentOutlineItemCapability = createPromiseCapability();
|
||||
this._currentOutlineItemCapability = new PromiseCapability();
|
||||
if (
|
||||
outlineCount === 0 ||
|
||||
this._pdfDocument?.loadingParams.disableAutoFetch
|
||||
|
@ -308,7 +308,7 @@ class PDFOutlineViewer extends BaseTreeViewer {
|
|||
if (this._pageNumberToDestHashCapability) {
|
||||
return this._pageNumberToDestHashCapability.promise;
|
||||
}
|
||||
this._pageNumberToDestHashCapability = createPromiseCapability();
|
||||
this._pageNumberToDestHashCapability = new PromiseCapability();
|
||||
|
||||
const pageNumberToDestHash = new Map(),
|
||||
pageNumberNesting = new Map();
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
/** @typedef {import("./event_utils").EventBus} EventBus */
|
||||
|
||||
import { apiPageLayoutToViewerModes, RenderingStates } from "./ui_utils.js";
|
||||
import { createPromiseCapability, shadow } from "pdfjs-lib";
|
||||
import { PromiseCapability, shadow } from "pdfjs-lib";
|
||||
|
||||
/**
|
||||
* @typedef {Object} PDFScriptingManagerOptions
|
||||
|
@ -357,7 +357,7 @@ class PDFScriptingManager {
|
|||
visitedPages = this._visitedPages;
|
||||
|
||||
if (initialize) {
|
||||
this._closeCapability = createPromiseCapability();
|
||||
this._closeCapability = new PromiseCapability();
|
||||
}
|
||||
if (!this._closeCapability) {
|
||||
return; // Scripting isn't fully initialized yet.
|
||||
|
@ -443,7 +443,7 @@ class PDFScriptingManager {
|
|||
* @private
|
||||
*/
|
||||
_createScripting() {
|
||||
this._destroyCapability = createPromiseCapability();
|
||||
this._destroyCapability = new PromiseCapability();
|
||||
|
||||
if (this._scripting) {
|
||||
throw new Error("_createScripting: Scripting already exists.");
|
||||
|
|
|
@ -28,9 +28,9 @@ import {
|
|||
AnnotationEditorType,
|
||||
AnnotationEditorUIManager,
|
||||
AnnotationMode,
|
||||
createPromiseCapability,
|
||||
PermissionFlag,
|
||||
PixelsPerInch,
|
||||
PromiseCapability,
|
||||
version,
|
||||
} from "pdfjs-lib";
|
||||
import {
|
||||
|
@ -1025,9 +1025,9 @@ class PDFViewer {
|
|||
this._location = null;
|
||||
this._pagesRotation = 0;
|
||||
this._optionalContentConfigPromise = null;
|
||||
this._firstPageCapability = createPromiseCapability();
|
||||
this._onePageRenderedCapability = createPromiseCapability();
|
||||
this._pagesCapability = createPromiseCapability();
|
||||
this._firstPageCapability = new PromiseCapability();
|
||||
this._onePageRenderedCapability = new PromiseCapability();
|
||||
this._pagesCapability = new PromiseCapability();
|
||||
this._scrollMode = ScrollMode.VERTICAL;
|
||||
this._previousScrollMode = ScrollMode.UNKNOWN;
|
||||
this._spreadMode = SpreadMode.NONE;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue