1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-19 22:58:07 +02:00

Remove the PDFViewer.annotationEditorMode setter event listeners with AbortSignal.any()

This commit is contained in:
Jonas Jenwald 2024-10-03 15:55:06 +02:00
parent 4fb3adfc0f
commit b7ae92c11c

View file

@ -227,7 +227,7 @@ class PDFViewer {
#mlManager = null;
#onPageRenderedCallback = null;
#switchAnnotationEditorModeAC = null;
#switchAnnotationEditorModeTimeoutId = null;
@ -2280,10 +2280,9 @@ class PDFViewer {
}
#cleanupSwitchAnnotationEditorMode() {
if (this.#onPageRenderedCallback) {
this.eventBus._off("pagerendered", this.#onPageRenderedCallback);
this.#onPageRenderedCallback = null;
}
this.#switchAnnotationEditorModeAC?.abort();
this.#switchAnnotationEditorModeAC = null;
if (this.#switchAnnotationEditorModeTimeoutId !== null) {
clearTimeout(this.#switchAnnotationEditorModeTimeoutId);
this.#switchAnnotationEditorModeTimeoutId = null;
@ -2353,14 +2352,25 @@ class PDFViewer {
// We're editing so we must switch to editing mode when the rendering is
// done.
this.#cleanupSwitchAnnotationEditorMode();
this.#onPageRenderedCallback = ({ pageNumber }) => {
idsToRefresh.delete(pageNumber);
if (idsToRefresh.size === 0) {
this.#switchAnnotationEditorModeTimeoutId = setTimeout(updater, 0);
}
};
const { signal } = this.#eventAbortController;
eventBus._on("pagerendered", this.#onPageRenderedCallback, { signal });
this.#switchAnnotationEditorModeAC = new AbortController();
const signal = AbortSignal.any([
this.#eventAbortController.signal,
this.#switchAnnotationEditorModeAC.signal,
]);
eventBus._on(
"pagerendered",
({ pageNumber }) => {
idsToRefresh.delete(pageNumber);
if (idsToRefresh.size === 0) {
this.#switchAnnotationEditorModeTimeoutId = setTimeout(
updater,
0
);
}
},
{ signal }
);
return;
}
}