« 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: 175d6cbb3dc3557497538fad3d0fb7be8eccab67 (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
68
69
70
71
72
73
74
75
76
77
78
79
80
// Get the artist's contribution list containing this property. Although that
// list literally includes both dated and dateless contributions, here, if the
// current contribution is dateless, the list is filtered to only include
// dateless contributions from the same immediately nearby context.

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,
      }) =>
        (hasDate
          ? continuation.raiseOutput({
              ['#containingReverseContributionList']:
                list.filter(contrib => contrib.date),
            })
          : continuation({
              ['#list']:
                list.filter(contrib => !contrib.date),
            })),
    },

    {
      dependencies: ['#list', 'thing'],
      compute: (continuation, {
        ['#list']: list,
        ['thing']: thing,
      }) => continuation({
        ['#containingReverseContributionList']:
          (thing.album
            ? list.filter(contrib => contrib.thing.album === thing.album)
            : list),
      }),
    },
  ],
});