« get me outta code hell

data: clean up Thing.composite.from debug messaging - 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 15:33:46 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-09-05 21:02:53 -0300
commit895712f5a0381c41557c6d306d6697019368bb7b (patch)
tree4eee69a5b6688b278bcd193446148733c67d5b04 /src/data/things/track.js
parent29580733b79872333f3f9e45d50d987218d334ea (diff)
data: clean up Thing.composite.from debug messaging
* print annotation next to every log message, instead of just
  the begin/end messages

* add Thing.composite.debug() to conveniently wrap one property
  access

* don't output (and don't access) track album in inspect.custom
  when depth < 0
Diffstat (limited to 'src/data/things/track.js')
-rw-r--r--src/data/things/track.js40
1 files changed, 14 insertions, 26 deletions
diff --git a/src/data/things/track.js b/src/data/things/track.js
index dc1f5f2a..8ddf3624 100644
--- a/src/data/things/track.js
+++ b/src/data/things/track.js
@@ -604,38 +604,26 @@ export class Track extends Thing {
       ]),
   };
 
-  [inspect.custom]() {
-    const base = Thing.prototype[inspect.custom].apply(this);
+  [inspect.custom](depth) {
+    const parts = [];
 
-    const rereleasePart =
-      (this.originalReleaseTrackByRef
-        ? `${color.yellow('[rerelease]')} `
-        : ``);
+    parts.push(Thing.prototype[inspect.custom].apply(this));
 
-    const {album, dataSourceAlbum} = this;
+    if (this.originalReleaseTrackByRef) {
+      parts.unshift(`${color.yellow('[rerelease]')} `);
+    }
 
-    const albumName =
-      (album
-        ? album.name
-        : dataSourceAlbum?.name);
-
-    const albumIndex =
-      albumName &&
-        (album
-          ? album.tracks.indexOf(this)
-          : dataSourceAlbum.tracks.indexOf(this));
-
-    const trackNum =
-      albumName &&
+    let album;
+    if (depth >= 0 && (album = this.album ?? this.dataSourceAlbum)) {
+      const albumName = album.name;
+      const albumIndex = album.tracks.indexOf(this);
+      const trackNum =
         (albumIndex === -1
           ? '#?'
           : `#${albumIndex + 1}`);
+      parts.push(` (${color.yellow(trackNum)} in ${color.green(albumName)})`);
+    }
 
-    const albumPart =
-      albumName
-        ? ` (${color.yellow(trackNum)} in ${color.green(albumName)})`
-        : ``;
-
-    return rereleasePart + base + albumPart;
+    return parts.join('');
   }
 }