« get me outta code hell

data: always define composite utilities with `key() {}` syntax - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/data/things/track.js
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-08-30 16:28:47 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-09-05 21:02:54 -0300
commit011c197aeedab56d501b03b800433dd0cd9bc4f7 (patch)
tree86c24338c20fc92fdb5dfcbb2f0eb335993f6a01 /src/data/things/track.js
parent7d6d8a2839ece38c4a70bd9e3fda73b2e0aa39b8 (diff)
data: always define composite utilities with `key() {}` syntax
Sublime Text doesn't index the key in `key: () => {}` as a symbol
for function definitions if the parameter list takes up more than
one line, but always works for `key() {}`.

This also just makes it a little easier to add "preamble" before
the main return value, when relevant. Consistent syntax is usually
a plus for recurring behavioral forms!
Diffstat (limited to 'src/data/things/track.js')
-rw-r--r--src/data/things/track.js123
1 files changed, 69 insertions, 54 deletions
diff --git a/src/data/things/track.js b/src/data/things/track.js
index 8ddf3624..cdc9cec3 100644
--- a/src/data/things/track.js
+++ b/src/data/things/track.js
@@ -366,8 +366,11 @@ export class Track extends Thing {
     // dependencies provided. If allowOverride is true, then the continuation
     // will also be called if the original release exposed the requested
     // property as null.
-    inheritFromOriginalRelease: ({property: originalProperty, allowOverride = false}) =>
-      Thing.composite.from(`Track.composite.inheritFromOriginalRelease`, [
+    inheritFromOriginalRelease({
+      property: originalProperty,
+      allowOverride = false,
+    }) {
+      return Thing.composite.from(`Track.composite.inheritFromOriginalRelease`, [
         Track.composite.withOriginalRelease(),
 
         {
@@ -386,56 +389,59 @@ export class Track extends Thing {
             },
           },
         }
-      ]),
+      ]);
+    },
 
     // Gets the track's album. Unless earlyExitIfNotFound is overridden false,
     // this will early exit with null in two cases - albumData being missing,
     // or not including an album whose .tracks array includes this track.
-    withAlbum: ({to = '#album', earlyExitIfNotFound = true} = {}) => ({
-      annotation: `Track.composite.withAlbum`,
-      flags: {expose: true, compose: true},
-
-      expose: {
-        dependencies: ['this', 'albumData'],
-        mapContinuation: {to},
-        options: {earlyExitIfNotFound},
-
-        compute({
-          this: track,
-          albumData,
-          '#options': {earlyExitIfNotFound},
-        }, continuation) {
-          if (empty(albumData)) {
-            return (
-              (earlyExitIfNotFound
-                ? continuation.exit(null)
-                : continuation({to: null})));
-          }
-
-          const album =
-            albumData?.find(album => album.tracks.includes(track));
-
-          if (!album) {
-            return (
-              (earlyExitIfNotFound
-                ? continuation.exit(null)
-                : continuation({to: null})));
-          }
+    withAlbum({to = '#album', earlyExitIfNotFound = true} = {}) {
+      return {
+        annotation: `Track.composite.withAlbum`,
+        flags: {expose: true, compose: true},
 
-          return continuation({to: album});
+        expose: {
+          dependencies: ['this', 'albumData'],
+          mapContinuation: {to},
+          options: {earlyExitIfNotFound},
+
+          compute({
+            this: track,
+            albumData,
+            '#options': {earlyExitIfNotFound},
+          }, continuation) {
+            if (empty(albumData)) {
+              return (
+                (earlyExitIfNotFound
+                  ? continuation.exit(null)
+                  : continuation({to: null})));
+            }
+
+            const album =
+              albumData?.find(album => album.tracks.includes(track));
+
+            if (!album) {
+              return (
+                (earlyExitIfNotFound
+                  ? continuation.exit(null)
+                  : continuation({to: null})));
+            }
+
+            return continuation({to: album});
+          },
         },
-      },
-    }),
+      };
+    },
 
     // Gets a single property from this track's album, providing it as the same
     // property name prefixed with '#album.' (by default). If the track's album
     // isn't available, and earlyExitIfNotFound hasn't been set, the property
     // will be provided as null.
-    withAlbumProperty: (property, {
+    withAlbumProperty(property, {
       to = '#album.' + property,
       earlyExitIfNotFound = false,
-    } = {}) =>
-      Thing.composite.from(`Track.composite.withAlbumProperty`, [
+    } = {}) {
+      return Thing.composite.from(`Track.composite.withAlbumProperty`, [
         Track.composite.withAlbum({earlyExitIfNotFound}),
 
         {
@@ -454,18 +460,19 @@ export class Track extends Thing {
                 : continuation.raise({to: null})),
           },
         },
-      ]),
+      ]);
+    },
 
     // Gets the listed properties from this track's album, providing them as
     // dependencies (by default) with '#album.' prefixed before each property
     // name. If the track's album isn't available, and earlyExitIfNotFound
     // hasn't been set, the same dependency names will be provided as null.
-    withAlbumProperties: ({
+    withAlbumProperties({
       properties,
       prefix = '#album',
       earlyExitIfNotFound = false,
-    }) =>
-      Thing.composite.from(`Track.composite.withAlbumProperties`, [
+    }) {
+      return Thing.composite.from(`Track.composite.withAlbumProperties`, [
         Track.composite.withAlbum({earlyExitIfNotFound}),
 
         {
@@ -494,17 +501,18 @@ export class Track extends Thing {
             },
           },
         },
-      ]),
+      ]);
+    },
 
     // Gets the track section containing this track from its album's track list.
     // Unless earlyExitIfNotFound is overridden false, this will early exit if
     // the album can't be found or if none of its trackSections includes the
     // track for some reason.
-    withContainingTrackSection: ({
+    withContainingTrackSection({
       to = '#trackSection',
       earlyExitIfNotFound = true,
-    } = {}) =>
-      Thing.composite.from(`Track.composite.withContainingTrackSection`, [
+    } = {}) {
+      return Thing.composite.from(`Track.composite.withContainingTrackSection`, [
         Track.composite.withAlbumProperty('trackSections', {earlyExitIfNotFound}),
 
         {
@@ -534,14 +542,17 @@ export class Track extends Thing {
             },
           },
         },
-      ]),
+      ]);
+    },
 
     // Just includes the original release of this track as a dependency, or
     // null, if it's not a rerelease. Note that this will early exit if the
     // original release is specified by reference and that reference doesn't
     // resolve to anything. Outputs to '#originalRelease' by default.
-    withOriginalRelease: ({to: outputDependency = '#originalRelease'} = {}) =>
-      Thing.composite.from(`Track.composite.withOriginalRelease`, [
+    withOriginalRelease({
+      to = '#originalRelease',
+    } = {}) {
+      return Thing.composite.from(`Track.composite.withOriginalRelease`, [
         Thing.composite.withResolvedReference({
           ref: 'originalReleaseTrackByRef',
           data: 'trackData',
@@ -553,12 +564,15 @@ export class Track extends Thing {
         Thing.composite.export({
           [outputDependency]: '#originalRelease',
         }),
-      ]),
+      ]);
+    },
 
     // The algorithm for checking if a track has unique cover art is used in a
     // couple places, so it's defined in full as a compositional step.
-    withHasUniqueCoverArt: ({to = '#hasUniqueCoverArt'} = {}) =>
-      Thing.composite.from(`Track.composite.withHasUniqueCoverArt`, [
+    withHasUniqueCoverArt({
+      to = '#hasUniqueCoverArt',
+    } = {}) {
+      return Thing.composite.from(`Track.composite.withHasUniqueCoverArt`, [
         {
           flags: {expose: true, compose: true},
           expose: {
@@ -601,7 +615,8 @@ export class Track extends Thing {
                 : continuation.raise({to: true})),
           },
         },
-      ]),
+      ]);
+    },
   };
 
   [inspect.custom](depth) {