diff --git a/src/content/dependencies/listAlbumsByDuration.js b/src/content/dependencies/listAlbumsByDuration.js index c60685abf..cb2707867 100644 --- a/src/content/dependencies/listAlbumsByDuration.js +++ b/src/content/dependencies/listAlbumsByDuration.js @@ -1,43 +1,25 @@ -import {sortAlphabetically, sortByCount} from '#sort'; -import {filterByCount, stitchArrays} from '#sugar'; -import {getTotalDuration} from '#wiki-data'; +import {stitchArrays} from '#sugar'; export default { contentDependencies: ['generateListingPage', 'linkAlbum'], extraDependencies: ['language', 'wikiData'], - sprawl({albumData}) { - return {albumData}; - }, + relations: (relation, listing) => ({ + page: + relation('generateListingPage', listing), - query({albumData}, spec) { - const albums = sortAlphabetically(albumData.slice()); - const durations = albums.map(album => getTotalDuration(album.tracks)); + albumLinks: + listing.data.albums + .map(album => relation('linkAlbum', album)), + }), - filterByCount(albums, durations); - sortByCount(albums, durations, {greatestFirst: true}); + data: (listing) => ({ + durations: + listing.data.durations, + }), - return {spec, albums, durations}; - }, - - relations(relation, query) { - return { - page: relation('generateListingPage', query.spec), - - albumLinks: - query.albums - .map(album => relation('linkAlbum', album)), - }; - }, - - data(query) { - return { - durations: query.durations, - }; - }, - - generate(data, relations, {language}) { - return relations.page.slots({ + generate: (data, relations, {language}) => + relations.page.slots({ type: 'rows', rows: stitchArrays({ @@ -47,6 +29,5 @@ export default { album: link, duration: language.formatDuration(duration), })), - }); - }, + }), }; diff --git a/src/content/dependencies/listAlbumsByName.js b/src/content/dependencies/listAlbumsByName.js index 214195378..c45d2e87b 100644 --- a/src/content/dependencies/listAlbumsByName.js +++ b/src/content/dependencies/listAlbumsByName.js @@ -1,41 +1,26 @@ -import {sortAlphabetically} from '#sort'; import {stitchArrays} from '#sugar'; export default { contentDependencies: ['generateListingPage', 'linkAlbum'], - extraDependencies: ['language', 'wikiData'], + extraDependencies: ['language'], - sprawl({albumData}) { - return {albumData}; - }, + relations: (relation, listing) => ({ + page: + relation('generateListingPage', listing), - query({albumData}, spec) { - return { - spec, - albums: sortAlphabetically(albumData.slice()), - }; - }, + albumLinks: + listing.data + .map(album => relation('linkAlbum', album)), + }), - relations(relation, query) { - return { - page: relation('generateListingPage', query.spec), + data: (listing) => ({ + counts: + listing.data + .map(album => album.tracks.length), + }), - albumLinks: - query.albums - .map(album => relation('linkAlbum', album)), - }; - }, - - data(query) { - return { - counts: - query.albums - .map(album => album.tracks.length), - }; - }, - - generate(data, relations, {language}) { - return relations.page.slots({ + generate: (data, relations, {language}) => + relations.page.slots({ type: 'rows', rows: stitchArrays({ @@ -45,6 +30,5 @@ export default { album: link, tracks: language.countTracks(count, {unit: true}), })), - }); - }, + }), }; diff --git a/src/content/dependencies/listAlbumsByTracks.js b/src/content/dependencies/listAlbumsByTracks.js index 798e6c2eb..e55c29d21 100644 --- a/src/content/dependencies/listAlbumsByTracks.js +++ b/src/content/dependencies/listAlbumsByTracks.js @@ -1,42 +1,25 @@ -import {sortAlphabetically, sortByCount} from '#sort'; -import {filterByCount, stitchArrays} from '#sugar'; +import {stitchArrays} from '#sugar'; export default { contentDependencies: ['generateListingPage', 'linkAlbum'], - extraDependencies: ['language', 'wikiData'], + extraDependencies: ['language'], - sprawl({albumData}) { - return {albumData}; - }, + relations: (relation, listing) => ({ + page: + relation('generateListingPage', listing), - query({albumData}, spec) { - const albums = sortAlphabetically(albumData.slice()); - const counts = albums.map(album => album.tracks.length); + albumLinks: + listing.data.albums + .map(album => relation('linkAlbum', album)), + }), - filterByCount(albums, counts); - sortByCount(albums, counts, {greatestFirst: true}); + data: (listing) => ({ + counts: + listing.data.counts, + }), - return {spec, albums, counts}; - }, - - relations(relation, query) { - return { - page: relation('generateListingPage', query.spec), - - albumLinks: - query.albums - .map(album => relation('linkAlbum', album)), - }; - }, - - data(query) { - return { - counts: query.counts, - }; - }, - - generate(data, relations, {language}) { - return relations.page.slots({ + generate: (data, relations, {language}) => + relations.page.slots({ type: 'rows', rows: stitchArrays({ @@ -46,6 +29,5 @@ export default { album: link, tracks: language.countTracks(count, {unit: true}), })), - }); - }, + }), }; diff --git a/src/listing-spec/wiki/albums/by-duration.js b/src/listing-spec/wiki/albums/by-duration.js index 61e1e5749..89f857c52 100644 --- a/src/listing-spec/wiki/albums/by-duration.js +++ b/src/listing-spec/wiki/albums/by-duration.js @@ -1,3 +1,12 @@ +import {input} from '#composite'; +import {sortAlphabetically, sortByCount} from '#sort'; +import {filterByCount} from '#sugar'; +import {getTotalDuration} from '#wiki-data'; + +import {exitWithoutDependency} from '#composite/control-flow'; +import {withMappedList, withPropertyFromList} from '#composite/data'; +import {withThingsSortedAlphabetically} from '#composite/wiki-data'; + export default { scope: 'wiki', directory: 'albums/by-duration', @@ -5,4 +14,41 @@ export default { stringsKey: 'listAlbums.byDuration', contentFunction: 'listAlbumsByDuration', + + data: () => [ + exitWithoutDependency({ + dependency: 'albumData', + value: input.value([]), + }), + + withThingsSortedAlphabetically({ + things: 'albumData', + }).outputs({ + '#sortedThings': '#albums', + }), + + withPropertyFromList({ + list: '#albums', + property: input.value('tracks'), + }), + + withMappedList({ + list: '#albums.tracks', + map: input.value(getTotalDuration) + }).outputs({ + '#mappedList': '#durations', + }), + + { + dependencies: ['#albums', '#durations'], + compute: ({ + ['#albums']: albums, + ['#durations']: durations, + }) => { + filterByCount(albums, durations); + sortByCount(albums, durations, {greatestFirst: true}); + return {albums, durations}; + }, + }, + ], }; diff --git a/src/listing-spec/wiki/albums/by-name.js b/src/listing-spec/wiki/albums/by-name.js index 5b84cdf57..9dcc64bd7 100644 --- a/src/listing-spec/wiki/albums/by-name.js +++ b/src/listing-spec/wiki/albums/by-name.js @@ -1,3 +1,9 @@ +import {input} from '#composite'; + +import {exitWithoutDependency, exposeDependency} + from '#composite/control-flow'; +import {withThingsSortedAlphabetically} from '#composite/wiki-data'; + export default { scope: 'wiki', directory: 'albums/by-name', @@ -9,4 +15,19 @@ export default { seeAlsoListings: [ 'tracks/by-album', ], + + data: () => [ + exitWithoutDependency({ + dependency: 'albumData', + value: input.value([]), + }), + + withThingsSortedAlphabetically({ + things: 'albumData', + }), + + exposeDependency({ + dependency: '#sortedThings', + }), + ], }; diff --git a/src/listing-spec/wiki/albums/by-tracks.js b/src/listing-spec/wiki/albums/by-tracks.js index 9091fbf82..9914b7f21 100644 --- a/src/listing-spec/wiki/albums/by-tracks.js +++ b/src/listing-spec/wiki/albums/by-tracks.js @@ -1,3 +1,11 @@ +import {input} from '#composite'; +import {sortByCount} from '#sort'; +import {filterByCount} from '#sugar'; + +import {exitWithoutDependency} from '#composite/control-flow'; +import {withPropertyFromList} from '#composite/data'; +import {withThingsSortedAlphabetically} from '#composite/wiki-data'; + export default { scope: 'wiki', directory: 'albums/by-tracks', @@ -5,4 +13,41 @@ export default { stringsKey: 'listAlbums.byTracks', contentFunction: 'listAlbumsByTracks', + + data: () => [ + exitWithoutDependency({ + dependency: 'albumData', + value: input.value([]), + }), + + withThingsSortedAlphabetically({ + things: 'albumData', + }).outputs({ + '#sortedThings': '#albums', + }), + + withPropertyFromList({ + list: '#albums', + property: input.value('tracks'), + }), + + withPropertyFromList({ + list: '#albums.tracks', + property: input.value('length'), + }).outputs({ + '#albums.tracks.length': '#counts', + }), + + { + dependencies: ['#albums', '#counts'], + compute: ({ + ['#albums']: albums, + ['#counts']: counts, + }) => { + filterByCount(albums, counts); + sortByCount(albums, counts, {greatestFirst: true}); + return {albums, counts}; + }, + }, + ], };