« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/data
diff options
context:
space:
mode:
Diffstat (limited to 'src/data')
-rw-r--r--src/data/things/composite.js103
1 files changed, 49 insertions, 54 deletions
diff --git a/src/data/things/composite.js b/src/data/things/composite.js
index 4be01a55..40f4fc16 100644
--- a/src/data/things/composite.js
+++ b/src/data/things/composite.js
@@ -1451,17 +1451,24 @@ export const exposeDependency = templateCompositeFrom({
 // descriptor. It generally follows steps which will conditionally early
 // exit with some other value, with the exposeConstant base serving as the
 // fallback default value.
-export function exposeConstant({value}) {
-  return {
-    annotation: `exposeConstant`,
-    flags: {expose: true},
+export const exposeConstant = templateCompositeFrom({
+  annotation: `exposeConstant`,
 
-    expose: {
-      options: {value},
-      compute: ({'#options': {value}}) => value,
+  compose: false,
+
+  inputs: {
+    value: input.staticValue(),
+  },
+
+  steps: () => [
+    {
+      dependencies: [input('value')],
+      compute: ({
+        [input('value')]: value,
+      }) => value,
     },
-  };
-}
+  ],
+});
 
 // Checks the availability of a dependency and provides the result to later
 // steps under '#availability' (by default). This is mainly intended for use
@@ -1964,55 +1971,43 @@ export const withPropertiesFromList = templateCompositeFrom({
 });
 
 // Replaces items of a list, which are null or undefined, with some fallback
-// value, either a constant (set {value}) or from a dependency ({dependency}).
-// By default, this replaces the passed dependency.
-export function fillMissingListItems({
-  list,
-  value,
-  dependency,
-  into = list,
-}) {
-  if (value !== undefined && dependency !== undefined) {
-    throw new TypeError(`Don't provide both value and dependency`);
-  }
+// value. By default, this replaces the passed dependency.
+export const fillMissingListItems = templateCompositeFrom({
+  annotation: `fillMissingListItems`,
 
-  if (value === undefined && dependency === undefined) {
-    throw new TypeError(`Missing value or dependency`);
-  }
-
-  if (dependency) {
-    return {
-      annotation: `fillMissingListItems.fromDependency`,
-      flags: {expose: true, compose: true},
-
-      expose: {
-        mapDependencies: {list, dependency},
-        mapContinuation: {into},
+  inputs: {
+    list: input({type: 'array'}),
+    fill: input(),
+  },
 
-        compute: (continuation, {list, dependency}) =>
-          continuation({
-            into: list.map(item => item ?? dependency),
-          }),
-      },
-    };
-  } else {
-    return {
-      annotation: `fillMissingListItems.fromValue`,
-      flags: {expose: true, compose: true},
+  outputs: ({
+    [input.staticDependency('list')]: list,
+  }) => [list ?? '#list'],
 
-      expose: {
-        mapDependencies: {list},
-        mapContinuation: {into},
-        options: {value},
+  steps: () => [
+    {
+      dependencies: [input('list'), input('fill')],
+      compute: (continuation, {
+        [input('list')]: list,
+        [input('fill')]: fill,
+      }) => continuation({
+        ['#filled']:
+          list.map(item => item ?? fill),
+      }),
+    },
 
-        compute: (continuation, {list, '#options': {value}}) =>
-          continuation({
-            into: list.map(item => item ?? value),
-          }),
-      },
-    };
-  }
-}
+    {
+      dependencies: [input.staticDependency('list'), '#filled'],
+      compute: (continuation, {
+        [input.staticDependency('list')]: list,
+        ['#filled']: filled,
+      }) => continuation({
+        [list ?? '#list']:
+          filled,
+      }),
+    },
+  ],
+});
 
 // Filters particular values out of a list. Note that this will always
 // completely skip over null, but can be used to filter out any other