« 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: 0c644c77b1421d3c8d6560d834b83b4885e64030 (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
// 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 {isDate} from '#validators';

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

import withResolvedContribs from './withResolvedContribs.js';

export default templateCompositeFrom({
  annotation: `withCoverArtDate`,

  inputs: {
    from: input({
      validate: isDate,
      defaultDependency: 'coverArtDate',
      acceptsNull: true,
    }),

    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: [input('from')],
      compute: (continuation, {
        [input('from')]: from,
      }) =>
        (from
          ? continuation.raiseOutput({'#coverArtDate': from})
          : continuation()),
    },

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

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