« get me outta code hell

data: cleaner withResolvedReferenceList notFoundMode implementation - 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>2023-09-08 17:20:48 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-09-08 17:20:48 -0300
commit6fe22802d8220b983a488f4efee1834bacbdb166 (patch)
tree37fbd7fda9465bd723a412384679cde67052c3e3 /src/data
parentcd3e2ae7384d82f0f2758beb0ae38ce0fe9f5e09 (diff)
data: cleaner withResolvedReferenceList notFoundMode implementation
Diffstat (limited to 'src/data')
-rw-r--r--src/data/things/thing.js42
1 files changed, 29 insertions, 13 deletions
diff --git a/src/data/things/thing.js b/src/data/things/thing.js
index 169fc1ca..96ac9b12 100644
--- a/src/data/things/thing.js
+++ b/src/data/things/thing.js
@@ -514,29 +514,45 @@ export function withResolvedReferenceList({
     }),
 
     {
-      options: {findFunction, notFoundMode},
       mapDependencies: {list, data},
-      mapContinuation: {matches: into},
+      options: {findFunction},
 
-      compute({list, data, '#options': {findFunction, notFoundMode}}, continuation) {
-        let matches =
-          list.map(ref => findFunction(ref, data, {mode: 'quiet'}));
+      compute: ({list, data, '#options': {findFunction}}, continuation) =>
+        continuation({
+          '#matches': list.map(ref => findFunction(ref, data, {mode: 'quiet'})),
+        }),
+    },
 
-        if (matches.every(match => match)) {
-          return continuation.raise({matches});
-        }
+    {
+      dependencies: ['#matches'],
+      mapContinuation: {into},
 
-        switch (notFoundMode) {
-          case 'filter':
-            matches = matches.filter(match => match);
-            return continuation.raise({matches});
+      compute: ({'#matches': matches}, continuation) =>
+        (matches.every(match => match)
+          ? continuation.raise({into: matches})
+          : continuation()),
+    },
+
+    {
+      dependencies: ['#matches'],
+      options: {notFoundMode},
+      mapContinuation: {into},
 
+      compute({
+        '#matches': matches,
+        '#options': {notFoundMode},
+      }, continuation) {
+        switch (notFoundMode) {
           case 'exit':
             return continuation.exit([]);
 
+          case 'filter':
+            matches = matches.filter(match => match);
+            return continuation.raise({into: matches});
+
           case 'null':
             matches = matches.map(match => match ?? null);
-            return continuation.raise({matches});
+            return continuation.raise({into: matches});
         }
       },
     },