Skip to content
This repository was archived by the owner on Feb 19, 2025. It is now read-only.

Commit cfc6f6c

Browse files
committed
Added debouncing to auto XFDF update
1 parent 5932e1b commit cfc6f6c

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

package-lock.json

Lines changed: 4 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
},
3131
"dependencies": {
3232
"@pdftron/webviewer": "^8.10.0-20221128",
33-
"classnames": "^2.2.6"
33+
"classnames": "^2.2.6",
34+
"lodash": "^4.17.21"
3435
}
3536
}

src/components/PDFViewer.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { createElement, useRef, useEffect, useState } from "react";
2+
import { debounce } from "lodash";
23
import viewer, { WebViewerInstance } from "@pdftron/webviewer";
34
import WebViewerModuleClient from "../clients/WebViewerModuleClient";
45

@@ -151,6 +152,8 @@ const PDFViewer: React.FC<InputProps> = props => {
151152
props.xfdfAttribute.setValue(xfdfString);
152153
};
153154

155+
const debouncedXfdfUpdate = debounce(updateXfdfAttribute, 1000);
156+
154157
if (props.enableXfdfExportButton) {
155158
UI.setHeaderItems(header => {
156159
header.push({
@@ -163,7 +166,7 @@ const PDFViewer: React.FC<InputProps> = props => {
163166
}
164167

165168
if (props.enableAutoXfdfExport) {
166-
Core.annotationManager.addEventListener("annotationChanged", updateXfdfAttribute);
169+
Core.annotationManager.addEventListener("annotationChanged", debouncedXfdfUpdate);
167170
}
168171
}
169172
}

0 commit comments

Comments
 (0)