« get me outta code hell

avoid stray nulls in (a Track).otherReleases - 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>2022-02-27 08:55:10 -0400
committer(quasar) nebula <qznebula@protonmail.com>2022-02-27 08:55:10 -0400
commit1d5078c972c8b2f625aa341cf75cead82323f909 (patch)
tree8dc214bc0cb4add1f7ed24a93e442f99e9f87e30 /src/data
parent6e2df0d972dcfa45be1e5f7f070fdebb969f4498 (diff)
avoid stray nulls in (a Track).otherReleases
Diffstat (limited to 'src/data')
-rw-r--r--src/data/things.js37
1 files changed, 22 insertions, 15 deletions
diff --git a/src/data/things.js b/src/data/things.js
index 5aa43f30..c09f740c 100644
--- a/src/data/things.js
+++ b/src/data/things.js
@@ -671,21 +671,28 @@ Track.propertyDescriptors = {
         expose: {
             dependencies: ['originalReleaseTrackByRef', 'trackData'],
 
-            compute: ({ originalReleaseTrackByRef: ref1, trackData, [Track.instance]: t1 }) => (
-                (ref1 && trackData
-                    ? [
-                        find.track(ref1, {wikiData: {trackData}}),
-                        ...trackData.filter(t2 => {
-                            const { originalReleaseTrackByRef: ref2 } = t2;
-                            return (
-                                t2 !== t1 &&
-                                ref2 &&
-                                (
-                                    find.track(ref2, {wikiData: {trackData}}) ===
-                                    find.track(ref1, {wikiData: {trackData}})))
-                        })]
-                    : [])
-            )
+            compute: ({ originalReleaseTrackByRef: ref1, trackData, [Track.instance]: t1 }) => {
+                if (!(ref1 && trackData)) {
+                    return [];
+                }
+
+                const tOrig = find.track(ref1, {wikiData: {trackData}});
+                if (!tOrig) {
+                    return [];
+                }
+
+                return [
+                    tOrig,
+                    ...trackData.filter(t2 => {
+                        const { originalReleaseTrackByRef: ref2 } = t2;
+                        return (
+                            t2 !== t1 &&
+                            ref2 &&
+                            find.track(ref2, {wikiData: {trackData}}) === tOrig
+                        );
+                    })
+                ];
+            }
         }
     },