« get me outta code hell

data: withDirectory, withDirectoryFromName - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/data/composite/wiki-properties
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2024-05-19 21:39:53 -0300
committer(quasar) nebula <qznebula@protonmail.com>2024-05-19 21:47:31 -0300
commit471de6e5ac73bd6c769a58392e3e49aff6d8f2cb (patch)
tree48cbdab24e36fa7e33026e8cbc42cd05cde02ada /src/data/composite/wiki-properties
parent9da8aa3ddcca68f3183ac2b1c187ce1b5f98e2d1 (diff)
data: withDirectory, withDirectoryFromName
Diffstat (limited to 'src/data/composite/wiki-properties')
-rw-r--r--src/data/composite/wiki-properties/directory.js48
1 files changed, 29 insertions, 19 deletions
diff --git a/src/data/composite/wiki-properties/directory.js b/src/data/composite/wiki-properties/directory.js
index 0b2181c9..41ce4b27 100644
--- a/src/data/composite/wiki-properties/directory.js
+++ b/src/data/composite/wiki-properties/directory.js
@@ -2,22 +2,32 @@
 // almost any data object. Also corresponds to a part of the URL which pages of
 // such objects are visited at.
 
-import {isDirectory} from '#validators';
-import {getKebabCase} from '#wiki-data';
-
-// TODO: Not templateCompositeFrom.
-
-export default function() {
-  return {
-    flags: {update: true, expose: true},
-    update: {validate: isDirectory},
-    expose: {
-      dependencies: ['name'],
-      transform(directory, {name}) {
-        if (directory === null && name === null) return null;
-        else if (directory === null) return getKebabCase(name);
-        else return directory;
-      },
-    },
-  };
-}
+import {input, templateCompositeFrom} from '#composite';
+
+import {isDirectory, isName} from '#validators';
+
+import {exposeDependency} from '#composite/control-flow';
+import {withDirectory} from '#composite/wiki-data';
+
+export default templateCompositeFrom({
+  annotation: `directory`,
+
+  compose: false,
+
+  inputs: {
+    name: input({
+      validate: isName,
+      defaultDependency: 'name',
+    }),
+  },
+
+  steps: () => [
+    withDirectory({
+      directory: input.updateValue({validate: isDirectory}),
+    }),
+
+    exposeDependency({
+      dependency: '#directory',
+    }),
+  ],
+});