« get me outta code hell

client: get results from dispatchInternalEvent + merge fixes - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/static/client3.js
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-11-24 15:17:09 -0400
committer(quasar) nebula <qznebula@protonmail.com>2023-11-24 15:17:09 -0400
commit4263dc13d48b385e78bbc5e1112dfe7a47054909 (patch)
tree83622dd432196d8fccfc6b2036184ea2cb403ac9 /src/static/client3.js
parenta8d4f86d9456cc713430410287aedcd8ed32f48e (diff)
client: get results from dispatchInternalEvent + merge fixes
Diffstat (limited to 'src/static/client3.js')
-rw-r--r--src/static/client3.js39
1 files changed, 19 insertions, 20 deletions
diff --git a/src/static/client3.js b/src/static/client3.js
index af0c381c..866b9ba2 100644
--- a/src/static/client3.js
+++ b/src/static/client3.js
@@ -96,14 +96,18 @@ function dispatchInternalEvent(event, eventName, ...args) {
     throw new Error(`Event name "${eventName}" isn't stored on ${infoName}.event`);
   }
 
+  let results = [];
   for (const listener of listeners) {
     try {
-      listener(...args);
+      results.push(listener(...args));
     } catch (error) {
       console.warn(`Uncaught error in listener for ${infoName}.${eventName}`);
       console.debug(error);
+      results.push(undefined);
     }
   }
+
+  return results;
 }
 
 // JS-based links -----------------------------------------
@@ -1102,13 +1106,14 @@ function addHashLinkListeners() {
       }
 
       // Allow event handlers to prevent scrolling.
-      for (const handler of event.beforeHashLinkScrolls) {
-        if (handler({
+      const listenerResults =
+        dispatchInternalEvent(event, 'beforeHashLinkScrolls', {
           link: hashLink,
           target,
-        }) === false) {
-          return;
-        }
+        });
+
+      if (listenerResults.includes(false)) {
+        return;
       }
 
       // Hide skipper box right away, so the layout is updated on time for the
@@ -1145,14 +1150,10 @@ function addHashLinkListeners() {
 
       processScrollingAfterHashLinkClicked();
 
-      dispatchInternalEvent(event, 'whenHashLinkClicked', {link: hashLink});
-
-      for (const handler of event.whenHashLinkClicked) {
-        handler({
-          link: hashLink,
-          target,
-        });
-      }
+      dispatchInternalEvent(event, 'whenHashLinkClicked', {
+        link: hashLink,
+        target,
+      });
     });
   }
 
@@ -1399,12 +1400,10 @@ function updateStickySubheadingContent(index) {
 
   state.displayedHeading = closestHeading;
 
-  for (const handler of event.whenDisplayedHeadingChanges) {
-    handler(index, {
-      oldHeading: oldDisplayedHeading,
-      newHeading: closestHeading,
-    });
-  }
+  dispatchInternalEvent(event, 'whenDisplayedHeadingChanges', index, {
+    oldHeading: oldDisplayedHeading,
+    newHeading: closestHeading,
+  });
 }
 
 function updateStickyHeadings(index) {