From 0e85744d5527774b7d6988cc543bb58b64d9e5f6 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Thu, 7 Mar 2024 10:54:24 -0400 Subject: data: track: withDate --- src/data/composite/things/track/index.js | 1 + src/data/composite/things/track/withDate.js | 34 +++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 src/data/composite/things/track/withDate.js (limited to 'src/data/composite/things/track') diff --git a/src/data/composite/things/track/index.js b/src/data/composite/things/track/index.js index 14fbdef0..4f913a5e 100644 --- a/src/data/composite/things/track/index.js +++ b/src/data/composite/things/track/index.js @@ -7,6 +7,7 @@ export {default as trackReverseReferenceList} from './trackReverseReferenceList. export {default as withAlbum} from './withAlbum.js'; export {default as withAlwaysReferenceByDirectory} from './withAlwaysReferenceByDirectory.js'; export {default as withContainingTrackSection} from './withContainingTrackSection.js'; +export {default as withDate} from './withDate.js'; export {default as withHasUniqueCoverArt} from './withHasUniqueCoverArt.js'; export {default as withOriginalRelease} from './withOriginalRelease.js'; export {default as withOtherReleases} from './withOtherReleases.js'; diff --git a/src/data/composite/things/track/withDate.js b/src/data/composite/things/track/withDate.js new file mode 100644 index 00000000..b5a770e9 --- /dev/null +++ b/src/data/composite/things/track/withDate.js @@ -0,0 +1,34 @@ +// Gets the track's own date. This is either its dateFirstReleased property +// or, if unset, the album's date. + +import {input, templateCompositeFrom} from '#composite'; + +import withPropertyFromAlbum from './withPropertyFromAlbum.js'; + +export default templateCompositeFrom({ + annotation: `withDate`, + + outputs: ['#date'], + + steps: () => [ + { + dependencies: ['dateFirstReleased'], + compute: (continuation, {dateFirstReleased}) => + (dateFirstReleased + ? continuation.raiseOutput({'#date': dateFirstReleased}) + : continuation()), + }, + + withPropertyFromAlbum({ + property: input.value('date'), + }), + + { + dependencies: ['#album.date'], + compute: (continuation, {['#album.date']: albumDate}) => + (albumDate + ? continuation.raiseOutput({'#date': albumDate}) + : continuation.raiseOutput({'#date': null})), + }, + ], +}) -- cgit 1.3.0-6-gf8a5