« get me outta code hell

write: reuse quickEvaluate directly for now - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/write/build-modes/live-dev-server.js
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-08-02 09:18:25 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-08-02 09:18:25 -0300
commit6d3b703b1278323ea37690c32185828a91feccba (patch)
tree28d78b94389a0c1aaffcab02263d2dc2ea985954 /src/write/build-modes/live-dev-server.js
parent84a4f21fefa1b7127f51463660740895fa7383a4 (diff)
write: reuse quickEvaluate directly for now
Diffstat (limited to 'src/write/build-modes/live-dev-server.js')
-rw-r--r--src/write/build-modes/live-dev-server.js119
1 files changed, 9 insertions, 110 deletions
diff --git a/src/write/build-modes/live-dev-server.js b/src/write/build-modes/live-dev-server.js
index 78c3928..1f74df1 100644
--- a/src/write/build-modes/live-dev-server.js
+++ b/src/write/build-modes/live-dev-server.js
@@ -28,12 +28,7 @@ import {
   watchContentDependencies,
 } from '../../content/dependencies/index.js';
 
-import {
-  fillRelationsLayoutFromSlotResults,
-  flattenRelationsTree,
-  getRelationsTree,
-  getNeededContentDependencyNames,
-} from '../../content-function.js';
+import {quickEvaluate} from '../../content-function.js';
 
 const defaultHost = '0.0.0.0';
 const defaultPort = 8002;
@@ -94,7 +89,7 @@ export async function go({
   const quietResponses = cliOptions['quiet-responses'] ?? false;
 
   const contentDependenciesWatcher = await watchContentDependencies();
-  const {contentDependencies: allContentDependencies} = contentDependenciesWatcher;
+  const {contentDependencies} = contentDependenciesWatcher;
 
   contentDependenciesWatcher.on('error', () => {});
   await new Promise(resolve => contentDependenciesWatcher.once('ready', resolve));
@@ -347,8 +342,6 @@ export async function go({
         urls,
       });
 
-      const {name, args = []} = page.contentFunction;
-
       const bound = bindUtilities({
         absoluteTo,
         cachebust,
@@ -363,108 +356,14 @@ export async function go({
         wikiData,
       });
 
-      const allExtraDependencies = {
-        ...bound,
-
-        appendIndexHTML: false,
-      };
-
-      // NOTE: ALL THIS STUFF IS PASTED, REVIEW AND INTEGRATE SOON(TM)
-
-      const treeInfo = getRelationsTree(allContentDependencies, name, wikiData, ...args);
-      const flatTreeInfo = flattenRelationsTree(treeInfo);
-      const {root, relationIdentifier, flatRelationSlots} = flatTreeInfo;
-
-      const neededContentDependencyNames =
-        getNeededContentDependencyNames(allContentDependencies, name);
-
-      // Content functions aren't recursive, so by following the set above
-      // sequentually, we will always provide fulfilled content functions as the
-      // dependencies for later content functions.
-      const fulfilledContentDependencies = {};
-      for (const name of neededContentDependencyNames) {
-        const unfulfilledContentFunction = allContentDependencies[name];
-        if (!unfulfilledContentFunction) continue;
-
-        const {contentDependencies, extraDependencies} = unfulfilledContentFunction;
-
-        if (empty(contentDependencies) && empty(extraDependencies)) {
-          fulfilledContentDependencies[name] = unfulfilledContentFunction;
-          continue;
-        }
+      const topLevelResult =
+        quickEvaluate({
+          contentDependencies,
+          extraDependencies: {...bound, appendIndexHTML: false},
 
-        const fulfillments = {};
-
-        for (const dependencyName of contentDependencies ?? []) {
-          if (dependencyName in fulfilledContentDependencies) {
-            fulfillments[dependencyName] =
-              fulfilledContentDependencies[dependencyName];
-          }
-        }
-
-        for (const dependencyName of extraDependencies ?? []) {
-          if (dependencyName in allExtraDependencies) {
-            fulfillments[dependencyName] =
-              allExtraDependencies[dependencyName];
-          }
-        }
-
-        fulfilledContentDependencies[name] =
-          unfulfilledContentFunction.fulfill(fulfillments);
-      }
-
-      // There might still be unfulfilled content functions if dependencies weren't
-      // provided as part of allContentDependencies or allExtraDependencies.
-      // Catch and report these early, together in an aggregate error.
-      const unfulfilledErrors = [];
-      const unfulfilledNames = [];
-      for (const name of neededContentDependencyNames) {
-        const contentFunction = fulfilledContentDependencies[name];
-        if (!contentFunction) continue;
-        if (!contentFunction.fulfilled) {
-          try {
-            contentFunction();
-          } catch (error) {
-            error.message = `(${name}) ${error.message}`;
-            unfulfilledErrors.push(error);
-            unfulfilledNames.push(name);
-          }
-        }
-      }
-
-      if (!empty(unfulfilledErrors)) {
-        throw new AggregateError(unfulfilledErrors, `Content functions unfulfilled (${unfulfilledNames.join(', ')})`);
-      }
-
-      const slotResults = {};
-
-      function runContentFunction({name, args, relations: layout}) {
-        const contentFunction = fulfilledContentDependencies[name];
-
-        if (!contentFunction) {
-          throw new Error(`Content function ${name} unfulfilled or not listed`);
-        }
-
-        const generateArgs = [];
-
-        if (contentFunction.data) {
-          generateArgs.push(contentFunction.data(...args));
-        }
-
-        if (layout) {
-          generateArgs.push(fillRelationsLayoutFromSlotResults(relationIdentifier, slotResults, layout));
-        }
-
-        return contentFunction(...generateArgs);
-      }
-
-      for (const slot of Object.getOwnPropertySymbols(flatRelationSlots)) {
-        slotResults[slot] = runContentFunction(flatRelationSlots[slot]);
-      }
-
-      const topLevelResult = runContentFunction(root);
-
-      // END PASTE
+          name: page.contentFunction.name,
+          args: page.contentFunction.args ?? [],
+        });
 
       const pageHTML = topLevelResult.toString();