diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2024-03-07 10:54:24 -0400 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2024-06-12 17:26:38 -0300 |
commit | 0e85744d5527774b7d6988cc543bb58b64d9e5f6 (patch) | |
tree | bb7ded9e2ffb7a3838ad42f862c66ed725eff2f5 /src/data/composite/things/track/withDate.js | |
parent | 3d51b9e53029c3995ad4a90c4dda93bdb696ae29 (diff) |
data: track: withDate
Diffstat (limited to 'src/data/composite/things/track/withDate.js')
-rw-r--r-- | src/data/composite/things/track/withDate.js | 34 |
1 files changed, 34 insertions, 0 deletions
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})), + }, + ], +}) |