From aae223f79b315486d9fea5d4dc156aabdec76e21 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Thu, 1 Aug 2024 14:33:20 +0200 Subject: [PATCH] Replace `onScrollModeChanged` and `onSpreadModeChanged` with one function 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. --- web/app.js | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/web/app.js b/web/app.js index 2a3e36cb1..ddc3b051c 100644 --- a/web/app.js +++ b/web/app.js @@ -1969,15 +1969,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, }); @@ -2402,19 +2406,10 @@ function onUpdateViewarea({ location }) { } } -function onScrollModeChanged(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("scrollMode", evt.mode).catch(() => { - // Unable to write to storage. - }); - } -} - -function onSpreadModeChanged(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. }); }