« 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/things
diff options
context:
space:
mode:
Diffstat (limited to 'src/data/things')
-rw-r--r--src/data/things/composite.js5
-rw-r--r--src/data/things/track.js21
2 files changed, 20 insertions, 6 deletions
diff --git a/src/data/things/composite.js b/src/data/things/composite.js
index fd52aa0f..29f5770c 100644
--- a/src/data/things/composite.js
+++ b/src/data/things/composite.js
@@ -853,8 +853,9 @@ export function exposeConstant({
 // consider using instead. Customize {mode} to select one of these modes,
 // or leave unset and default to 'null':
 //
-// * 'null':  Check that the value isn't null.
+// * 'null':  Check that the value isn't null (and not undefined either).
 // * 'empty': Check that the value is neither null nor an empty array.
+//            This will outright error for undefined.
 // * 'falsy': Check that the value isn't false when treated as a boolean
 //            (nor an empty array). Keep in mind this will also be false
 //            for values like zero and the empty string!
@@ -879,7 +880,7 @@ export function withResultOfAvailabilityCheck({
 
   const checkAvailability = (value, mode) => {
     switch (mode) {
-      case 'null': return value !== null;
+      case 'null': return value !== null && value !== undefined;
       case 'empty': return !empty(value);
       case 'falsy': return !!value && (!Array.isArray(value) || !empty(value));
       default: return false;
diff --git a/src/data/things/track.js b/src/data/things/track.js
index 41c92092..fcfd39c7 100644
--- a/src/data/things/track.js
+++ b/src/data/things/track.js
@@ -411,21 +411,34 @@ function withAlbum({
         }),
     },
 
+    withResultOfAvailabilityCheck({
+      fromDependency: '#album',
+      mode: 'null',
+      into: '#albumAvailability',
+    }),
+
     {
-      dependencies: ['#album'],
+      dependencies: ['#albumAvailability'],
       options: {notFoundMode},
       mapContinuation: {into},
 
       compute: ({
-        '#album': album,
+        '#albumAvailability': albumAvailability,
         '#options': {notFoundMode},
       }, continuation) =>
-        (album
-          ? continuation.raise({into: album})
+        (albumAvailability
+          ? continuation()
           : (notFoundMode === 'exit'
               ? continuation.exit(null)
               : continuation.raise({into: null}))),
     },
+
+    {
+      dependencies: ['#album'],
+      mapContinuation: {into},
+      compute: ({'#album': album}, continuation) =>
+        continuation({into: album}),
+    },
   ]);
 }