« get me outta code hell

withSharedAdditionalNames.js « track « things « composite « data « src - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/data/composite/things/track/withSharedAdditionalNames.js
blob: bba675c93156cf7d2b244f96c44172b47b3dff24 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Compiles additional names directly provided on other releases.

import {input, templateCompositeFrom} from '#composite';

import {raiseOutputWithoutDependency} from '#composite/control-flow';
import {withFlattenedList} from '#composite/data';

import CacheableObject from '#cacheable-object';

import withOtherReleases from './withOtherReleases.js';

export default templateCompositeFrom({
  annotation: `withSharedAdditionalNames`,

  outputs: ['#sharedAdditionalNames'],

  steps: () => [
    withOtherReleases(),

    raiseOutputWithoutDependency({
      dependency: '#otherReleases',
      mode: input.value('empty'),
      output: input.value({'#sharedAdditionalNames': []}),
    }),

    // TODO: Using getUpdateValue is always a bit janky.

    {
      dependencies: ['#otherReleases'],
      compute: (continuation, {
        ['#otherReleases']: otherReleases,
      }) => continuation({
        ['#otherReleases.additionalNames']:
          otherReleases.map(release =>
            CacheableObject.getUpdateValue(release, 'additionalNames')
              ?? []),
      }),
    },

    withFlattenedList({
      list: '#otherReleases.additionalNames',
    }).outputs({
      '#flattenedList': '#sharedAdditionalNames',
    }),
  ],
});