« get me outta code hell

data: update withPropertyFromList - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/data/composite
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-10-26 18:47:08 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-10-26 19:36:58 -0300
commitecac8276182436897dffff02aaf1a7d268738cba (patch)
tree40135e7b1700a23a48e4f083a213a196b51575d2 /src/data/composite
parentc7e21005beb8807216aac6ed3ae54029575007a1 (diff)
data: update withPropertyFromList
Diffstat (limited to 'src/data/composite')
-rw-r--r--src/data/composite/data/withPropertyFromList.js100
1 files changed, 63 insertions, 37 deletions
diff --git a/src/data/composite/data/withPropertyFromList.js b/src/data/composite/data/withPropertyFromList.js
index 3ce05fdf..1983ebbc 100644
--- a/src/data/composite/data/withPropertyFromList.js
+++ b/src/data/composite/data/withPropertyFromList.js
@@ -16,41 +16,67 @@
 //  - withUnflattenedList
 //
 
-import {empty} from '#sugar';
-
-// todo: OUHHH THIS ONE'S NOT UPDATED YET LOL
-export default function({
-  list,
-  property,
-  into = null,
-}) {
-  into ??=
-    (list.startsWith('#')
-      ? `${list}.${property}`
-      : `#${list}.${property}`);
-
-  return {
-    annotation: `withPropertyFromList`,
-    flags: {expose: true, compose: true},
-
-    expose: {
-      mapDependencies: {list},
-      mapContinuation: {into},
-      options: {property},
-
-      compute(continuation, {list, '#options': {property}}) {
-        if (list === undefined || empty(list)) {
-          return continuation({into: []});
-        }
-
-        return continuation({
-          into:
-            list.map(item =>
-              (item === null || item === undefined
-                ? null
-                : item[property] ?? null)),
-        });
-      },
-    },
-  };
+import {input, templateCompositeFrom} from '#composite';
+
+function getOutputName({list, property, prefix}) {
+  if (!property) return `#values`;
+  if (prefix) return `${prefix}.${property}`;
+  if (list) return `${list}.${property}`;
+  return `#list.${property}`;
 }
+
+export default templateCompositeFrom({
+  annotation: `withPropertyFromList`,
+
+  inputs: {
+    list: input({type: 'array'}),
+    property: input({type: 'string'}),
+    prefix: input.staticValue({type: 'string', defaultValue: null}),
+  },
+
+  outputs: ({
+    [input.staticDependency('list')]: list,
+    [input.staticValue('property')]: property,
+    [input.staticValue('prefix')]: prefix,
+  }) =>
+    [getOutputName({list, property, prefix})],
+
+  steps: () => [
+    {
+      dependencies: [input('list'), input('property')],
+      compute: (continuation, {
+        [input('list')]: list,
+        [input('property')]: property,
+      }) => continuation({
+        ['#values']:
+          list.map(item => item[property] ?? null),
+      }),
+    },
+
+    {
+      dependencies: [
+        input.staticDependency('list'),
+        input.staticValue('property'),
+        input.staticValue('prefix'),
+      ],
+
+      compute: (continuation, {
+        [input.staticDependency('list')]: list,
+        [input.staticValue('property')]: property,
+        [input.staticValue('prefix')]: prefix,
+      }) => continuation({
+        ['#outputName']:
+          getOutputName({list, property, prefix}),
+      }),
+    },
+
+    {
+      dependencies: ['#values', '#outputName'],
+      compute: (continuation, {
+        ['#values']: values,
+        ['#outputName']: outputName,
+      }) =>
+        continuation.raiseOutput({[outputName]: values}),
+    },
+  ],
+});