« get me outta code hell

data steps: generateAlbumInfoPage & relations implementation - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/content-function.js
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-03-19 17:57:27 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-03-19 17:57:27 -0300
commita213861e467ec99b2a197c4c54f9034a4d9f1516 (patch)
tree03b8b2e3affb17ab26dc88feaf2b4dc627f273ed /src/content-function.js
parent41c22a553d43fbcc04b7a17ec6f83583ed7f3443 (diff)
data steps: generateAlbumInfoPage & relations implementation
Diffstat (limited to 'src/content-function.js')
-rw-r--r--src/content-function.js45
1 files changed, 32 insertions, 13 deletions
diff --git a/src/content-function.js b/src/content-function.js
index 654a294..93bef6b 100644
--- a/src/content-function.js
+++ b/src/content-function.js
@@ -6,10 +6,12 @@ export default function contentFunction({
 
   data,
   generate,
+  relations,
 }) {
   return expectDependencies({
     data,
     generate,
+    relations,
 
     expectedContentDependencyKeys: contentDependencies,
     expectedExtraDependencyKeys: extraDependencies,
@@ -20,8 +22,9 @@ export default function contentFunction({
 contentFunction.identifyingSymbol = Symbol(`Is a content function?`);
 
 export function expectDependencies({
-  generate,
   data,
+  generate,
+  relations,
 
   expectedContentDependencyKeys,
   expectedExtraDependencyKeys,
@@ -59,8 +62,12 @@ export function expectDependencies({
   }
 
   if (empty(missingContentDependencyKeys) && empty(missingExtraDependencyKeys)) {
-    wrappedGenerate ??= function(data) {
-      return generate(data, fulfilledDependencies);
+    wrappedGenerate ??= function(data, relations) {
+      if (relations) {
+        return generate(data, relations, fulfilledDependencies);
+      } else {
+        return generate(data, fulfilledDependencies);
+      }
     };
 
     annotateFunction(wrappedGenerate, {name: generate, trait: 'fulfilled'});
@@ -71,15 +78,19 @@ export function expectDependencies({
     };
   }
 
-  wrappedGenerate ??= function() {
-    throw new Error(`Dependencies still needed: ${missingContentDependencyKeys.concat(missingExtraDependencyKeys).join(', ')}`);
-  };
+  if (!wrappedGenerate) {
+    wrappedGenerate = function() {
+      throw new Error(`Dependencies still needed: ${missingContentDependencyKeys.concat(missingExtraDependencyKeys).join(', ')}`);
+    };
+
+    annotateFunction(wrappedGenerate, {name: generate, trait: 'unfulfilled'});
+    wrappedGenerate.fulfilled = false;
+  }
 
-  annotateFunction(wrappedGenerate, {name: generate, trait: 'unfulfilled'});
-  wrappedGenerate.fulfilled ??= false;
   wrappedGenerate[contentFunction.identifyingSymbol] = true;
 
   if (empty(missingContentDependencyKeys)) {
+    /*
     const dataDependencies = {};
 
     for (const key of expectedContentDependencyKeys) {
@@ -97,18 +108,26 @@ export function expectDependencies({
     };
 
     annotateFunction(wrappedGenerate.data, {name: data, trait: 'fulfilled'});
+    */
+
+    wrappedGenerate.data = data;
   }
 
-  wrappedGenerate.data ??= function() {
-    throw new Error(`Dependencies still needed: ${missingContentDependencyKeys.join(', ')}`);
-  };
+  if (!wrappedGenerate.data) {
+    wrappedGenerate.data = function() {
+      throw new Error(`Dependencies still needed: ${missingContentDependencyKeys.join(', ')}`);
+    };
 
-  annotateFunction(wrappedGenerate.data, {name: data, trait: 'unfulfilled'});
+    annotateFunction(wrappedGenerate.data, {name: data, trait: 'unfulfilled'});
+  }
+
+  wrappedGenerate.relations = relations;
 
   wrappedGenerate.fulfill ??= function fulfill(dependencies) {
     return expectDependencies({
-      generate,
       data,
+      generate,
+      relations,
 
       expectedContentDependencyKeys,
       expectedExtraDependencyKeys,