« get me outta code hell

data: update exposeConstant, fillMissingListItems - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-09-21 14:37:20 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-09-21 14:37:20 -0300
commitee3b52cfe889eb514f5d6a5f78297875f278e206 (patch)
treeb0d4312b77a40b9d3ecc190614e208b223b9873d
parent6ca1e4b3ad691478e94f09cfe94683cb079f6bdf (diff)
data: update exposeConstant, fillMissingListItems
-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 4be01a5..40f4fc1 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