« get me outta code hell

withExpressedOrImplicitArtistReferences.js « helpers « content « 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/content/helpers/withExpressedOrImplicitArtistReferences.js
blob: 62799d43a68fcb1634c2da0143f97e0bae13b989 (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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import {input, templateCompositeFrom} from '#composite';

import {raiseOutputWithoutDependency} from '#composite/control-flow';
import {withFilteredList, withMappedList} from '#composite/data';
import {withContentNodes} from '#composite/wiki-data';

export default templateCompositeFrom({
  annotation: `withExpressedOrImplicitArtistReferences`,

  inputs: {
    from: input({type: 'array', acceptsNull: true}),
  },

  outputs: ['#artistReferences'],

  steps: () => [
    {
      dependencies: [input('from')],
      compute: (continuation, {
        [input('from')]: expressedArtistReferences,
      }) =>
        (expressedArtistReferences
          ? continuation.raiseOutput({'#artistReferences': expressedArtistReferences})
          : continuation()),
    },

    raiseOutputWithoutDependency({
      dependency: 'artistText',
      output: input.value({'#artistReferences': null}),
    }),

    withContentNodes({
      from: 'artistText',
    }),

    withMappedList({
      list: '#contentNodes',
      map: input.value(node =>
        node.type === 'tag' &&
        node.data.replacerKey?.data === 'artist'),
    }).outputs({
      '#mappedList': '#artistTagFilter',
    }),

    withFilteredList({
      list: '#contentNodes',
      filter: '#artistTagFilter',
    }).outputs({
      '#filteredList': '#artistTags',
    }),

    withMappedList({
      list: '#artistTags',
      map: input.value(node =>
        node.data.replacerValue[0].data),
    }).outputs({
      '#mappedList': '#artistReferences',
    }),
  ],
});