Skip to content

Commit

Permalink
Replace onScrollModeChanged and onSpreadModeChanged with one func…
Browse files Browse the repository at this point in the history
…tion

Given that these event handlers are virtually identical, obviously with the exception of the name-parameter, let's reduce a little bit of code duplication.
  • Loading branch information
Snuffleupagus committed Aug 2, 2024
1 parent f37ad9b commit 412ab6b
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions web/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -1966,15 +1966,19 @@ const PDFViewerApplication = {
eventBus._on("switchscrollmode", evt => (pdfViewer.scrollMode = evt.mode), {
signal,
});
eventBus._on("scrollmodechanged", onScrollModeChanged.bind(this), {
signal,
});
eventBus._on(
"scrollmodechanged",
onViewerModesChanged.bind(this, "scrollMode"),
{ signal }
);
eventBus._on("switchspreadmode", evt => (pdfViewer.spreadMode = evt.mode), {
signal,
});
eventBus._on("spreadmodechanged", onSpreadModeChanged.bind(this), {
signal,
});
eventBus._on(
"spreadmodechanged",
onViewerModesChanged.bind(this, "spreadMode"),
{ signal }
);
eventBus._on("imagealttextsettings", onImageAltTextSettings.bind(this), {
signal,
});
Expand Down Expand Up @@ -2399,19 +2403,10 @@ function onUpdateViewarea({ location }) {
}
}

function onScrollModeChanged(evt) {
if (this.isInitialViewSet && !this.pdfViewer.isInPresentationMode) {
// Only update the storage when the document has been loaded *and* rendered.
this.store?.set("scrollMode", evt.mode).catch(() => {
// Unable to write to storage.
});
}
}

function onSpreadModeChanged(evt) {
function onViewerModesChanged(name, evt) {
if (this.isInitialViewSet && !this.pdfViewer.isInPresentationMode) {
// Only update the storage when the document has been loaded *and* rendered.
this.store?.set("spreadMode", evt.mode).catch(() => {
this.store?.set(name, evt.mode).catch(() => {
// Unable to write to storage.
});
}
Expand Down

0 comments on commit 412ab6b

Please sign in to comment.