« get me outta code hell

inferredAdditionalNameList.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/inferredAdditionalNameList.js
blob: 9cf158c6c32f04706c8cb7b8d9df464d6c1c759d (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
61
62
63
64
65
66
67
// Infers additional name entries from other releases that were titled
// differently; the corresponding releases are stored in eacn entry's "from"
// array, which will include multiple items, if more than one other release
// shares the same name differing from this one's.

import {input, templateCompositeFrom} from '#composite';
import {chunkByProperties} from '#wiki-data';

import {exitWithoutDependency} from '#composite/control-flow';
import {withFilteredList, withPropertyFromList} from '#composite/data';
import {withThingsSortedAlphabetically} from '#composite/wiki-data';

import withOtherReleases from './withOtherReleases.js';

export default templateCompositeFrom({
  annotation: `inferredAdditionalNameList`,

  compose: false,

  steps: () => [
    withOtherReleases(),

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

    withPropertyFromList({
      list: '#otherReleases',
      property: input.value('name'),
    }),

    {
      dependencies: ['#otherReleases.name', 'name'],
      compute: (continuation, {
        ['#otherReleases.name']: releaseNames,
        ['name']: ownName,
      }) => continuation({
        ['#nameFilter']:
          releaseNames.map(name => name !== ownName),
      }),
    },

    withFilteredList({
      list: '#otherReleases',
      filter: '#nameFilter',
    }).outputs({
      '#filteredList': '#differentlyNamedReleases',
    }),

    withThingsSortedAlphabetically({
      things: '#differentlyNamedReleases',
    }).outputs({
      '#sortedThings': '#differentlyNamedReleases',
    }),

    {
      dependencies: ['#differentlyNamedReleases'],
      compute: ({
        ['#differentlyNamedReleases']: releases,
      }) =>
        chunkByProperties(releases, ['name'])
          .map(({name, chunk}) => ({name, from: chunk})),
    },
  ],
});