diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2025-02-19 16:47:45 -0400 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2025-03-02 08:24:12 -0400 |
commit | 586c3b9defc0d6222502f43a0cc4fa39c871a018 (patch) | |
tree | 3bbd9cc289b0c29e126a2aceec30ef3b6636bb9f /src/data/composite/things/track/withAllReleases.js | |
parent | 76e508ffe3818a78fb941ecde05fe9c269e8bc22 (diff) |
data: miscellaneous cleanup for withOtherReleases logic
Defines withOtherReleases in terms of new function withAllReleases (also exposed as Track.allReleases), in turn based on new property Track.secondaryReleases (of the main release), which is a reverse ref list, reverse.tracksWhichAreSecondaryReleasesOf().
Diffstat (limited to 'src/data/composite/things/track/withAllReleases.js')
-rw-r--r-- | src/data/composite/things/track/withAllReleases.js | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/data/composite/things/track/withAllReleases.js b/src/data/composite/things/track/withAllReleases.js new file mode 100644 index 00000000..b93bf753 --- /dev/null +++ b/src/data/composite/things/track/withAllReleases.js @@ -0,0 +1,47 @@ +// Gets all releases of the current track. All items of the outputs are +// distinct Track objects; one track is the main release; all else are +// secondary releases of that main release; and one item, which may be +// the main release or one of the secondary releases, is the current +// track. The results are sorted by date, and it is possible that the +// main release is not actually the earliest/first. + +import {input, templateCompositeFrom} from '#composite'; +import {sortByDate} from '#sort'; + +import {exitWithoutDependency} from '#composite/control-flow'; +import {withPropertyFromObject} from '#composite/data'; + +import withMainRelease from './withMainRelease.js'; + +export default templateCompositeFrom({ + annotation: `withAllReleases`, + + outputs: ['#allReleases'], + + steps: () => [ + withMainRelease({ + selfIfMain: input.value(true), + notFoundValue: input.value([]), + }), + + // We don't talk about bruno no no + // Yes, this can perform a normal access equivalent to + // `this.secondaryReleases` from within a data composition. + // Oooooooooooooooooooooooooooooooooooooooooooooooo + withPropertyFromObject({ + object: '#mainRelease', + property: input.value('secondaryReleases'), + }), + + { + dependencies: ['#mainRelease', '#mainRelease.secondaryReleases'], + compute: (continuation, { + ['#mainRelease']: mainRelease, + ['#mainRelease.secondaryReleases']: secondaryReleases, + }) => continuation({ + ['#allReleases']: + sortByDate([mainRelease, ...secondaryReleases]), + }), + }, + ], +}); |