« get me outta code hell

contracts: initial commit - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/content/dependencies/generateAlbumSidebar.js
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-05-02 14:58:27 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-05-02 14:58:54 -0300
commit4280c6240b88dadc8e5ea187b78c10aca9dfc163 (patch)
tree93ea9f2986fc378e7054c99f7e59c536cc2d5e20 /src/content/dependencies/generateAlbumSidebar.js
parentbf6bff764880f96597f915bd9a59abfaaf310db1 (diff)
contracts: initial commit
All draft stuff here for now, but this is *relatively* un-naive
as it's based on a lot of recent research and discussion.
But none of this code is evaluated yet!!
Diffstat (limited to 'src/content/dependencies/generateAlbumSidebar.js')
-rw-r--r--src/content/dependencies/generateAlbumSidebar.js46
1 files changed, 32 insertions, 14 deletions
diff --git a/src/content/dependencies/generateAlbumSidebar.js b/src/content/dependencies/generateAlbumSidebar.js
index bf6b091..4eef62b 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}) {