« get me outta code hell

data: dynamicThingFromSingleReference -> resolvedReference - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-09-06 15:42:47 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-09-06 15:42:47 -0300
commit2437ac322a4c44f2fd9f6a77ac7a65bbb3afc2c0 (patch)
tree3df201d124ccb5cc561017b9c1f4f09090ad3910 /src
parent007c70642a60ed83bd840f550aa06563d4ba6a99 (diff)
data: dynamicThingFromSingleReference -> resolvedReference
Diffstat (limited to 'src')
-rw-r--r--src/data/things/composite.js4
-rw-r--r--src/data/things/homepage-layout.js10
-rw-r--r--src/data/things/thing.js40
-rw-r--r--src/data/things/track.js6
4 files changed, 22 insertions, 38 deletions
diff --git a/src/data/things/composite.js b/src/data/things/composite.js
index 138814d9..d3f76b11 100644
--- a/src/data/things/composite.js
+++ b/src/data/things/composite.js
@@ -1160,8 +1160,8 @@ export function withResolvedContribs({from, to}) {
 export function withResolvedReference({
   ref,
   data,
-  to,
   find: findFunction,
+  to = '#resolvedReference',
   earlyExitIfNotFound = false,
 }) {
   return compositeFrom(`Thing.composite.withResolvedReference`, [
@@ -1194,8 +1194,8 @@ export function withResolvedReference({
 export function withResolvedReferenceList({
   list,
   data,
-  to,
   find: findFunction,
+  to = '#resolvedReferenceList',
   notFoundMode = 'filter',
 }) {
   if (!['filter', 'exit', 'null'].includes(notFoundMode)) {
diff --git a/src/data/things/homepage-layout.js b/src/data/things/homepage-layout.js
index cbdcb99a..c478bc41 100644
--- a/src/data/things/homepage-layout.js
+++ b/src/data/things/homepage-layout.js
@@ -119,11 +119,11 @@ export class HomepageLayoutAlbumsRow extends HomepageLayoutRow {
 
     // Expose only
 
-    sourceGroup: Thing.common.dynamicThingFromSingleReference(
-      'sourceGroupByRef',
-      'groupData',
-      find.group
-    ),
+    sourceGroup: Thing.common.resolvedReference({
+      ref: 'sourceGroupByRef',
+      data: 'groupData',
+      find: find.group,
+    }),
 
     sourceAlbums: Thing.common.resolvedReferenceList({
       list: 'sourceAlbumsByRef',
diff --git a/src/data/things/thing.js b/src/data/things/thing.js
index 915474d4..36a1f58a 100644
--- a/src/data/things/thing.js
+++ b/src/data/things/thing.js
@@ -193,40 +193,23 @@ export default class Thing extends CacheableObject {
     // Corresponding dynamic property to referenceList, which takes the values
     // in the provided property and searches the specified wiki data for
     // matching actual Thing-subclass objects.
-    resolvedReferenceList({
-      list,
-      data,
-      find: findFunction,
-    }) {
+    resolvedReferenceList({list, data, find}) {
       return Thing.composite.from(`Thing.common.resolvedReferenceList`, [
         Thing.composite.withResolvedReferenceList({
-          list,
-          data,
-          to: '#things',
-          find: findFunction,
+          list, data, find,
           notFoundMode: 'filter',
         }),
-
-        Thing.composite.exposeDependency('#things'),
+        Thing.composite.exposeDependency('#resolvedReferenceList'),
       ]);
     },
 
     // Corresponding function for a single reference.
-    dynamicThingFromSingleReference: (
-      singleReferenceProperty,
-      thingDataProperty,
-      findFn
-    ) => ({
-      flags: {expose: true},
-
-      expose: {
-        dependencies: [singleReferenceProperty, thingDataProperty],
-        compute: ({
-          [singleReferenceProperty]: ref,
-          [thingDataProperty]: thingData,
-        }) => (ref && thingData ? findFn(ref, thingData, {mode: 'quiet'}) : null),
-      },
-    }),
+    resolvedReference({ref, data, find}) {
+      return Thing.composite.from(`Thing.common.resolvedReference`, [
+        Thing.composite.withResolvedReference({ref, data, find}),
+        Thing.composite.exposeDependency('#resolvedReference'),
+      ]);
+    },
 
     // Corresponding dynamic property to contribsByRef, which takes the values
     // in the provided property and searches the object's artistData for
@@ -273,10 +256,7 @@ export default class Thing extends CacheableObject {
     // you would use this to compute a corresponding "referenced *by* tracks"
     // property. Naturally, the passed ref list property is of the things in the
     // wiki data provided, not the requesting Thing itself.
-    reverseReferenceList({
-      data,
-      list,
-    }) {
+    reverseReferenceList({data, list}) {
       return Thing.composite.from(`Thing.common.reverseReferenceList`, [
         Thing.composite.withReverseReferenceList({data, list}),
         Thing.composite.exposeDependency('#reverseReferenceList'),
diff --git a/src/data/things/track.js b/src/data/things/track.js
index 87e796b9..2b628b66 100644
--- a/src/data/things/track.js
+++ b/src/data/things/track.js
@@ -145,7 +145,11 @@ export class Track extends Thing {
     // not generally relevant information). It's also not guaranteed that
     // dataSourceAlbum is available (depending on the Track creator to optionally
     // provide dataSourceAlbumByRef).
-    dataSourceAlbum: Thing.common.dynamicThingFromSingleReference('dataSourceAlbumByRef', 'albumData', find.album),
+    dataSourceAlbum: Thing.common.resolvedReference({
+      ref: 'dataSourceAlbumByRef',
+      data: 'albumData',
+      find: find.album,
+    }),
 
     date: Thing.composite.from(`Track.date`, [
       Thing.composite.exposeDependencyOrContinue('dateFirstReleased'),