« get me outta code hell

data, upd8: auto-provide boundFind on 'find' dependency - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2025-01-10 22:29:18 -0400
committer(quasar) nebula <qznebula@protonmail.com>2025-01-10 22:29:18 -0400
commit11a6a76dc78aa6f30cc6860ba353ef68cf9e21c5 (patch)
tree457103f8cd08f3f41cd576ac1c384bf50b1140c1 /src
parentdff7dd72606338f2a29171a50d223ad6286b6e50 (diff)
data, upd8: auto-provide boundFind on 'find' dependency
Diffstat (limited to 'src')
-rw-r--r--src/data/yaml.js28
-rwxr-xr-xsrc/upd8.js4
2 files changed, 25 insertions, 7 deletions
diff --git a/src/data/yaml.js b/src/data/yaml.js
index 64223662..2420bf71 100644
--- a/src/data/yaml.js
+++ b/src/data/yaml.js
@@ -1225,7 +1225,7 @@ export async function loadAndProcessDataDocuments(dataSteps, {dataPath}) {
 // Data linking! Basically, provide (portions of) wikiData to the Things which
 // require it - they'll expose dynamically computed properties as a result (many
 // of which are required for page HTML generation and other expected behavior).
-export function linkWikiDataArrays(wikiData) {
+export function linkWikiDataArrays(wikiData, {bindFind}) {
   const linkWikiDataSpec = new Map([
     [wikiData.albumData, [
       'albumData',
@@ -1299,19 +1299,37 @@ export function linkWikiDataArrays(wikiData) {
     ]],
   ]);
 
+  const constructorHasFindMap = new Map();
+  const boundFind = bindFind(wikiData);
+
   for (const [things, keys] of linkWikiDataSpec.entries()) {
     if (things === undefined) continue;
+
     for (const thing of things) {
       if (thing === undefined) continue;
+
+      let hasFind;
+      if (constructorHasFindMap.has(thing.constructor)) {
+        hasFind = constructorHasFindMap.get(thing.constructor);
+      } else {
+        hasFind = 'find' in thing;
+        constructorHasFindMap.set(thing.constructor, hasFind);
+      }
+
+      if (hasFind) {
+        thing.find = boundFind;
+      }
+
       for (const key of keys) {
         if (!(key in wikiData)) continue;
+
         thing[key] = wikiData[key];
       }
     }
   }
 }
 
-export function sortWikiDataArrays(dataSteps, wikiData) {
+export function sortWikiDataArrays(dataSteps, wikiData, {bindFind}) {
   for (const [key, value] of Object.entries(wikiData)) {
     if (!Array.isArray(value)) continue;
     wikiData[key] = value.slice();
@@ -1327,7 +1345,7 @@ export function sortWikiDataArrays(dataSteps, wikiData) {
   // slices instead of the original arrays) - this is so that the object
   // caching system understands that it's working with a new ordering.
   // We still need to actually provide those updated arrays over again!
-  linkWikiDataArrays(wikiData);
+  linkWikiDataArrays(wikiData, {bindFind});
 }
 
 // Utility function for loading all wiki data from the provided YAML data
@@ -1363,7 +1381,7 @@ export async function quickLoadAllFromYAML(dataPath, {
     }
   }
 
-  linkWikiDataArrays(wikiData);
+  linkWikiDataArrays(wikiData, {bindFind});
 
   try {
     reportDirectoryErrors(wikiData, {getAllFindSpecs});
@@ -1389,7 +1407,7 @@ export async function quickLoadAllFromYAML(dataPath, {
     logWarn`Content text errors found.`;
   }
 
-  sortWikiDataArrays(dataSteps, wikiData);
+  sortWikiDataArrays(dataSteps, wikiData, {bindFind});
 
   return wikiData;
 }
diff --git a/src/upd8.js b/src/upd8.js
index f4c6326a..5c066ab7 100755
--- a/src/upd8.js
+++ b/src/upd8.js
@@ -1526,7 +1526,7 @@ async function main() {
     timeStart: Date.now(),
   });
 
-  linkWikiDataArrays(wikiData);
+  linkWikiDataArrays(wikiData, {bindFind});
 
   Object.assign(stepStatusSummary.linkWikiDataArrays, {
     status: STATUS_DONE_CLEAN,
@@ -1740,7 +1740,7 @@ async function main() {
     timeStart: Date.now(),
   });
 
-  sortWikiDataArrays(yamlDataSteps, wikiData);
+  sortWikiDataArrays(yamlDataSteps, wikiData, {bindFind});
 
   Object.assign(stepStatusSummary.sortWikiDataArrays, {
     status: STATUS_DONE_CLEAN,