« get me outta code hell

withContainingReverseContributionList.js « contribution « 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/contribution/withContainingReverseContributionList.js
blob: dc990ca5030e3032c0188b37929e3a5e83e21ce3 (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
// Get the artist's contribution list containing this property. Although that
// list literally includes both dated and un-dated contributions, here the list
// is filtered including only the matching subset (has dates vs dateless).

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

import {raiseOutputWithoutDependency, withResultOfAvailabilityCheck}
  from '#composite/control-flow';
import {withPropertyFromObject} from '#composite/data';

import withContributionArtist from './withContributionArtist.js';

export default templateCompositeFrom({
  annotation: `withContainingReverseContributionList`,

  inputs: {
    artistProperty: input({
      defaultDependency: 'artistProperty',
      acceptsNull: true,
    }),
  },

  outputs: ['#containingReverseContributionList'],

  steps: () => [
    raiseOutputWithoutDependency({
      dependency: input('artistProperty'),
      output: input.value({
        ['#containingReverseContributionList']:
          null,
      }),
    }),

    withContributionArtist(),

    withPropertyFromObject({
      object: '#artist',
      property: input('artistProperty'),
    }).outputs({
      ['#value']: '#list',
    }),

    withResultOfAvailabilityCheck({
      from: 'date',
    }).outputs({
      ['#availability']: '#hasDate',
    }),

    {
      dependencies: ['#hasDate', '#list'],
      compute: (continuation, {
        ['#hasDate']: hasDate,
        ['#list']: list,
      }) => continuation({
        ['#containingReverseContributionList']:
          list.filter(contribution => !!contribution.date === hasDate),
      }),
    },
  ],
});