« 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/composite/things/content
diff options
context:
space:
mode:
Diffstat (limited to 'src/data/composite/things/content')
-rw-r--r--src/data/composite/things/content/hasAnnotationPart.js28
-rw-r--r--src/data/composite/things/content/index.js1
-rw-r--r--src/data/composite/things/content/withHasAnnotationPart.js43
3 files changed, 50 insertions, 22 deletions
diff --git a/src/data/composite/things/content/hasAnnotationPart.js b/src/data/composite/things/content/hasAnnotationPart.js
index 8b2cbb8b..83d175e3 100644
--- a/src/data/composite/things/content/hasAnnotationPart.js
+++ b/src/data/composite/things/content/hasAnnotationPart.js
@@ -1,8 +1,8 @@
 import {input, templateCompositeFrom} from '#composite';
 
-import {exitWithoutDependency} from '#composite/control-flow';
+import {exposeDependency} from '#composite/control-flow';
 
-import withAnnotationParts from './withAnnotationParts.js';
+import withHasAnnotationPart from './withHasAnnotationPart.js';
 
 export default templateCompositeFrom({
   annotation: `hasAnnotationPart`,
@@ -14,28 +14,12 @@ export default templateCompositeFrom({
   },
 
   steps: () => [
-    withAnnotationParts({
-      mode: input.value('strings'),
+    withHasAnnotationPart({
+      part: input('part'),
     }),
 
-    exitWithoutDependency({
-      dependency: '#annotationParts',
-      value: input.value(false),
+    exposeDependency({
+      dependency: '#hasAnnotationPart',
     }),
-
-    {
-      dependencies: [
-        input('part'),
-        '#annotationParts',
-      ],
-
-      compute: ({
-        [input('part')]: search,
-        ['#annotationParts']: parts,
-      }) =>
-        parts.some(part =>
-          part.toLowerCase() ===
-          search.toLowerCase()),
-    },
   ],
 });
diff --git a/src/data/composite/things/content/index.js b/src/data/composite/things/content/index.js
index b03db684..4176337d 100644
--- a/src/data/composite/things/content/index.js
+++ b/src/data/composite/things/content/index.js
@@ -1,6 +1,7 @@
 export {default as contentArtists} from './contentArtists.js';
 export {default as hasAnnotationPart} from './hasAnnotationPart.js';
 export {default as withAnnotationParts} from './withAnnotationParts.js';
+export {default as withHasAnnotationPart} from './withHasAnnotationPart.js';
 export {default as withSourceText} from './withSourceText.js';
 export {default as withSourceURLs} from './withSourceURLs.js';
 export {default as withWebArchiveDate} from './withWebArchiveDate.js';
diff --git a/src/data/composite/things/content/withHasAnnotationPart.js b/src/data/composite/things/content/withHasAnnotationPart.js
new file mode 100644
index 00000000..4af554f3
--- /dev/null
+++ b/src/data/composite/things/content/withHasAnnotationPart.js
@@ -0,0 +1,43 @@
+import {input, templateCompositeFrom} from '#composite';
+
+import {raiseOutputWithoutDependency} from '#composite/control-flow';
+
+import withAnnotationParts from './withAnnotationParts.js';
+
+export default templateCompositeFrom({
+  annotation: `withHasAnnotationPart`,
+
+  inputs: {
+    part: input({type: 'string'}),
+  },
+
+  outputs: ['#hasAnnotationPart'],
+
+  steps: () => [
+    withAnnotationParts({
+      mode: input.value('strings'),
+    }),
+
+    raiseOutputWithoutDependency({
+      dependency: '#annotationParts',
+      output: input.value({'#hasAnnotationPart': false}),
+    }),
+
+    {
+      dependencies: [
+        input('part'),
+        '#annotationParts',
+      ],
+
+      compute: (continuation, {
+        [input('part')]: search,
+        ['#annotationParts']: parts,
+      }) => continuation({
+        ['#hasAnnotationPart']:
+          parts.some(part =>
+            part.toLowerCase() ===
+            search.toLowerCase()),
+      }),
+    },
+  ],
+});