From 4280c6240b88dadc8e5ea187b78c10aca9dfc163 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Tue, 2 May 2023 14:58:27 -0300 Subject: 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!! --- src/content/contracts/adjacentAlbumsInGroup.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/content/contracts/adjacentAlbumsInGroup.js (limited to 'src/content/contracts') 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}; + }, +}; -- cgit 1.3.0-6-gf8a5