« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/content
diff options
context:
space:
mode:
Diffstat (limited to 'src/content')
-rw-r--r--src/content/contracts/adjacentAlbumsInGroup.js17
-rw-r--r--src/content/dependencies/generateAlbumSidebar.js46
-rw-r--r--src/content/dependencies/generateAlbumSidebarGroupBox.js22
3 files changed, 64 insertions, 21 deletions
diff --git a/src/content/contracts/adjacentAlbumsInGroup.js b/src/content/contracts/adjacentAlbumsInGroup.js
new file mode 100644
index 00000000..e982fa5b
--- /dev/null
+++ b/src/content/contracts/adjacentAlbumsInGroup.js
@@ -0,0 +1,17 @@
+export default {
+  hook(contract, [album, group]) {
+    contract.provide({
+      group,
+      album,
+      albums: contract.selectProperty(group, 'albums'),
+    });
+  },
+
+  compute({group, album, albums}) {
+    const datedAlbums = albums.filter(album => album.date);
+    const index = datedAlbums.indexOf(album);
+    const previousAlbum = (index > 0) && datedAlbums[index - 1];
+    const nextAlbum = (index < datedAlbums.length - 1) && datedAlbums[index + 1];
+    return {previousAlbum, nextAlbum};
+  },
+};
diff --git a/src/content/dependencies/generateAlbumSidebar.js b/src/content/dependencies/generateAlbumSidebar.js
index bf6b091a..4eef62b2 100644
--- a/src/content/dependencies/generateAlbumSidebar.js
+++ b/src/content/dependencies/generateAlbumSidebar.js
@@ -7,26 +7,44 @@ export default {
 
   extraDependencies: ['html'],
 
+  contracts: {
+    relations: {
+      hook(contract, [relation, album, track]) {
+        contract.provide({
+          relation, album, track,
 
-  relations(relation, album, track) {
-    const relations = {};
+          groups: contract.selectProperty(album, 'groups'),
+          trackSections: contract.selectProperty(album, 'trackSections'),
+        });
+      },
 
-    relations.albumLink =
-      relation('linkAlbum', album);
+      compute({relation, album, track, groups, trackSections}) {
+        const relations = {};
 
-    relations.groupBoxes =
-      album.groups.map(group =>
-        relation('generateAlbumSidebarGroupBox', album, group));
+        relations.albumLink =
+          relation('linkAlbum', album);
 
-    relations.trackSections =
-      album.trackSections.map(trackSection =>
-        relation('generateAlbumSidebarTrackSection', album, track, trackSection));
+        relations.groupBoxes =
+          groups.map(group =>
+            relation('generateAlbumSidebarGroupBox', album, group));
 
-    return relations;
-  },
+        relations.trackSections =
+          trackSections.map(trackSection =>
+            relation('generateAlbumSidebarTrackSection', album, track, trackSection));
+
+        return relations;
+      },
+    },
+
+    data: {
+      hook(contract, [album, track]) {
+        contract.provide({track});
+      },
 
-  data(album, track) {
-    return {isAlbumPage: !track};
+      compute({track}) {
+        return {isAlbumPage: !track};
+      },
+    },
   },
 
   generate(data, relations, {html}) {
diff --git a/src/content/dependencies/generateAlbumSidebarGroupBox.js b/src/content/dependencies/generateAlbumSidebarGroupBox.js
index 0679e8fc..4e46c931 100644
--- a/src/content/dependencies/generateAlbumSidebarGroupBox.js
+++ b/src/content/dependencies/generateAlbumSidebarGroupBox.js
@@ -4,20 +4,28 @@ export default {
   contentDependencies: ['linkAlbum', 'linkExternal', 'linkGroup'],
   extraDependencies: ['html', 'language', 'transformMultiline'],
 
-  relations(relation, album, group) {
+  contracts: {
+    relations(contract, [album, group]) {
+      contract.provide({
+        group, album,
+
+        urls: contract.selectProperty(group, 'urls'),
+        adjacentAlbums: contract.subcontract('adjacentAlbumsInGroup', album, group),
+      });
+    },
+  },
+
+  relations(relation, {group, album, urls, adjacentAlbums}) {
     const relations = {};
 
     relations.groupLink =
       relation('linkGroup', group);
 
     relations.externalLinks =
-      group.urls.map(url =>
-        relation('linkExternal', url));
+      urls.map(url =>
+        relation('linkExternal', urls));
 
-    const albums = group.albums.filter(album => album.date);
-    const index = albums.indexOf(album);
-    const previousAlbum = (index > 0) && albums[index - 1];
-    const nextAlbum = (index < albums.length - 1) && albums[index + 1];
+    const {previousAlbum, nextAlbum} = adjacentAlbums;
 
     if (previousAlbum) {
       relations.previousAlbumLink =