diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2025-07-01 08:12:57 -0300 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2025-07-01 08:12:57 -0300 |
commit | 1f41b6f13fe1ccfa0a6e847629448a680b1b1be4 (patch) | |
tree | 3c14e4e0e92bfefd485e901ccfb3a7790866c2eb /src/data/composite/things | |
parent | 6802a68176ec7e97eda29999f130a4e63b853a94 (diff) |
data: exitWithoutArtwork
Diffstat (limited to 'src/data/composite/things')
-rw-r--r-- | src/data/composite/things/album/index.js | 2 | ||||
-rw-r--r-- | src/data/composite/things/album/withCoverArtDate.js | 50 | ||||
-rw-r--r-- | src/data/composite/things/album/withHasCoverArt.js | 64 |
3 files changed, 51 insertions, 65 deletions
diff --git a/src/data/composite/things/album/index.js b/src/data/composite/things/album/index.js index dfc6864f..de1d37c3 100644 --- a/src/data/composite/things/album/index.js +++ b/src/data/composite/things/album/index.js @@ -1,2 +1,2 @@ -export {default as withHasCoverArt} from './withHasCoverArt.js'; +export {default as withCoverArtDate} from './withCoverArtDate.js'; export {default as withTracks} from './withTracks.js'; diff --git a/src/data/composite/things/album/withCoverArtDate.js b/src/data/composite/things/album/withCoverArtDate.js new file mode 100644 index 00000000..978f566a --- /dev/null +++ b/src/data/composite/things/album/withCoverArtDate.js @@ -0,0 +1,50 @@ +import {input, templateCompositeFrom} from '#composite'; +import {isDate} from '#validators'; + +import {raiseOutputWithoutDependency} from '#composite/control-flow'; +import {withHasArtwork} from '#composite/wiki-data'; + +export default templateCompositeFrom({ + annotation: `withCoverArtDate`, + + inputs: { + from: input({ + validate: isDate, + defaultDependency: 'coverArtDate', + acceptsNull: true, + }), + }, + + outputs: ['#coverArtDate'], + + steps: () => [ + withHasArtwork({ + contribs: 'coverArtistContribs', + artworks: 'coverArtworks', + }), + + raiseOutputWithoutDependency({ + dependency: '#hasArtwork', + mode: input.value('falsy'), + output: input.value({'#coverArtDate': null}), + }), + + { + dependencies: [input('from')], + compute: (continuation, { + [input('from')]: from, + }) => + (from + ? continuation.raiseOutput({'#coverArtDate': from}) + : continuation()), + }, + + { + dependencies: ['date'], + compute: (continuation, {date}) => + (date + ? continuation({'#coverArtDate': date}) + : continuation({'#coverArtDate': null})), + }, + ], +}); diff --git a/src/data/composite/things/album/withHasCoverArt.js b/src/data/composite/things/album/withHasCoverArt.js deleted file mode 100644 index fd3f2894..00000000 --- a/src/data/composite/things/album/withHasCoverArt.js +++ /dev/null @@ -1,64 +0,0 @@ -// TODO: This shouldn't be coded as an Album-specific thing, -// or even really to do with cover artworks in particular, either. - -import {input, templateCompositeFrom} from '#composite'; - -import {raiseOutputWithoutDependency, withResultOfAvailabilityCheck} - from '#composite/control-flow'; -import {fillMissingListItems, withFlattenedList, withPropertyFromList} - from '#composite/data'; - -export default templateCompositeFrom({ - annotation: 'withHasCoverArt', - - outputs: ['#hasCoverArt'], - - steps: () => [ - withResultOfAvailabilityCheck({ - from: 'coverArtistContribs', - mode: input.value('empty'), - }), - - { - dependencies: ['#availability'], - compute: (continuation, { - ['#availability']: availability, - }) => - (availability - ? continuation.raiseOutput({ - ['#hasCoverArt']: true, - }) - : continuation()), - }, - - raiseOutputWithoutDependency({ - dependency: 'coverArtworks', - mode: input.value('empty'), - output: input.value({'#hasCoverArt': false}), - }), - - withPropertyFromList({ - list: 'coverArtworks', - property: input.value('artistContribs'), - internal: input.value(true), - }), - - // Since we're getting the update value for each artwork's artistContribs, - // it may not be set at all, and in that case won't be exposing as []. - fillMissingListItems({ - list: '#coverArtworks.artistContribs', - fill: input.value([]), - }), - - withFlattenedList({ - list: '#coverArtworks.artistContribs', - }), - - withResultOfAvailabilityCheck({ - from: '#flattenedList', - mode: input.value('empty'), - }).outputs({ - '#availability': '#hasCoverArt', - }), - ], -}); |