« get me outta code hell

data: earlyExitIfNotFound -> notFoundMode - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/data/things/thing.js
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-09-07 10:32:41 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-09-07 10:32:41 -0300
commitb076c87e435bbe2403122158ee03e4934c220c6c (patch)
tree7c10939e4692ecb1e9ca5133bb3a0c8f80c8b313 /src/data/things/thing.js
parent3437936e6127192d30a308b68731cd4aa33555e7 (diff)
data: earlyExitIfNotFound -> notFoundMode
Diffstat (limited to 'src/data/things/thing.js')
-rw-r--r--src/data/things/thing.js21
1 files changed, 12 insertions, 9 deletions
diff --git a/src/data/things/thing.js b/src/data/things/thing.js
index 5d407153..93f19799 100644
--- a/src/data/things/thing.js
+++ b/src/data/things/thing.js
@@ -375,31 +375,34 @@ export function withResolvedContribs({from, to}) {
 
 // Resolves a reference by using the provided find function to match it
 // within the provided thingData dependency. This will early exit if the
-// data dependency is null, or, if earlyExitIfNotFound is set to true,
-// if the find function doesn't match anything for the reference.
-// Otherwise, the data object is provided on the output dependency;
-// or null, if the reference doesn't match anything or itself was null
-// to begin with.
+// data dependency is null, or, if notFoundMode is set to 'exit', if the find
+// function doesn't match anything for the reference. Otherwise, the data
+// object is provided on the output dependency; or null, if the reference
+// doesn't match anything or itself was null to begin with.
 export function withResolvedReference({
   ref,
   data,
   find: findFunction,
   to = '#resolvedReference',
-  earlyExitIfNotFound = false,
+  notFoundMode = 'null',
 }) {
+  if (!['exit', 'null'].includes(notFoundMode)) {
+    throw new TypeError(`Expected notFoundMode to be exit or null`);
+  }
+
   return compositeFrom(`withResolvedReference`, [
     raiseWithoutDependency(ref, {map: {to}, raise: {to: null}}),
     exitWithoutDependency(data),
 
     {
-      options: {findFunction, earlyExitIfNotFound},
+      options: {findFunction, notFoundMode},
       mapDependencies: {ref, data},
       mapContinuation: {match: to},
 
-      compute({ref, data, '#options': {findFunction, earlyExitIfNotFound}}, continuation) {
+      compute({ref, data, '#options': {findFunction, notFoundMode}}, continuation) {
         const match = findFunction(ref, data, {mode: 'quiet'});
 
-        if (match === null && earlyExitIfNotFound) {
+        if (match === null && notFoundMode === 'exit') {
           return continuation.exit(null);
         }