diff options
Diffstat (limited to 'src/data/composite/things/track/withContainingTrackSection.js')
-rw-r--r-- | src/data/composite/things/track/withContainingTrackSection.js | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/data/composite/things/track/withContainingTrackSection.js b/src/data/composite/things/track/withContainingTrackSection.js new file mode 100644 index 0000000..eaac14d --- /dev/null +++ b/src/data/composite/things/track/withContainingTrackSection.js @@ -0,0 +1,42 @@ +// Gets the track section containing this track from its album's track list. + +import {input, templateCompositeFrom} from '#composite'; +import {is} from '#validators'; + +import {raiseOutputWithoutDependency} from '#composite/control-flow'; + +import withPropertyFromAlbum from './withPropertyFromAlbum.js'; + +export default templateCompositeFrom({ + annotation: `withContainingTrackSection`, + + outputs: ['#trackSection'], + + steps: () => [ + withPropertyFromAlbum({ + property: input.value('trackSections'), + }), + + raiseOutputWithoutDependency({ + dependency: '#album.trackSections', + output: input.value({'#trackSection': null}), + }), + + { + dependencies: [ + input.myself(), + '#album.trackSections', + ], + + compute: (continuation, { + [input.myself()]: track, + [input('notFoundMode')]: notFoundMode, + ['#album.trackSections']: trackSections, + }) => continuation({ + ['#trackSection']: + trackSections.find(({tracks}) => tracks.includes(track)) + ?? null, + }), + }, + ], +}); |