« get me outta code hell

withCoverArtDate.js « wiki-data « composite « data « src - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/data/composite/wiki-data/withCoverArtDate.js
blob: 7c16ce0fa071f553bdef29ea3563dbafd9fd5850 (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
// Gets the current thing's coverArtDate, or, if the 'fallback' option is set,
// the thing's date. This is always null if the thing doesn't actually have
// any coverArtistContribs.

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

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

import withResolvedContribs from './withResolvedContribs.js';

export default templateCompositeFrom({
  annotation: `withCoverArtDate`,

  inputs: {
    fallback: input({
      type: 'boolean',
      defaultValue: false,
    }),
  },

  outputs: ['#coverArtDate'],

  steps: () => [
    withResolvedContribs({
      from: 'coverArtistContribs',
      date: input.value(null),
    }),

    raiseOutputWithoutDependency({
      dependency: '#resolvedContribs',
      mode: input.value('empty'),
      output: input.value({'#coverArtDate': null}),
    }),

    {
      dependencies: ['coverArtDate', input('fallback')],
      compute: (continuation, {
        ['coverArtDate']: coverArtDate,
        [input('fallback')]: fallback,
      }) =>
        (coverArtDate
          ? continuation.raiseOutput({'#coverArtDate': coverArtDate})
       : fallback
          ? continuation()
          : continuation.raiseOutput({'#coverArtDate': null})),
    },

    {
      dependencies: ['date'],
      compute: (continuation, {date}) =>
        (date
          ? continuation.raiseOutput({'#coverArtDate': date})
          : continuation.raiseOutput({'#coverArtDate': null})),
    },
  ],
});