« get me outta code hell

data: withFilteredList: flip option - 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:
author(quasar) nebula <qznebula@protonmail.com>2024-10-30 15:41:21 -0300
committer(quasar) nebula <qznebula@protonmail.com>2024-10-30 16:04:27 -0300
commitf5f21156d205a1ad8533a717e5552707d26551a2 (patch)
tree7953a902df6ab0ed6d3118e1f843d4f0348f8717 /src/data
parente5b2698286232986a31325cefd72467bf19f89a8 (diff)
data: withFilteredList: flip option
Diffstat (limited to 'src/data')
-rw-r--r--src/data/composite/data/withFilteredList.js16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/data/composite/data/withFilteredList.js b/src/data/composite/data/withFilteredList.js
index 60fe66f4..1dbbd3af 100644
--- a/src/data/composite/data/withFilteredList.js
+++ b/src/data/composite/data/withFilteredList.js
@@ -2,6 +2,9 @@
 // corresponding items in a list. Items which correspond to a truthy value
 // are kept, and the rest are excluded from the output list.
 //
+// If the flip option is set, only items corresponding with a *falsy* value in
+// the filter are kept.
+//
 // TODO: It would be neat to apply an availability check here, e.g. to allow
 // not providing a filter at all and performing the check on the contents of
 // the list (though on the filter, if present, is fine too). But that's best
@@ -25,19 +28,28 @@ export default templateCompositeFrom({
   inputs: {
     list: input({type: 'array'}),
     filter: input({type: 'array'}),
+
+    flip: input({
+      type: 'boolean',
+      defaultValue: false,
+    }),
   },
 
   outputs: ['#filteredList'],
 
   steps: () => [
     {
-      dependencies: [input('list'), input('filter')],
+      dependencies: [input('list'), input('filter'), input('flip')],
       compute: (continuation, {
         [input('list')]: list,
         [input('filter')]: filter,
+        [input('flip')]: flip,
       }) => continuation({
         '#filteredList':
-          list.filter((item, index) => filter[index]),
+          list.filter((_item, index) =>
+            (flip
+              ? !filter[index]
+              :  filter[index])),
       }),
     },
   ],