« get me outta code hell

constitutibleArtwork.js « wiki-properties « 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-properties/constitutibleArtwork.js
blob: e0f0f5211fcdcb8b5bc972d02d30fe5b426eec14 (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
import {input, templateCompositeFrom} from '#composite';
import {isContributionList, isDate, validateThing} from '#validators';

import {exitWithoutDependency, exposeDependency, exposeUpdateValueOrContinue}
  from '#composite/control-flow';
import {withConstitutedArtwork} from '#composite/wiki-data';

export default templateCompositeFrom({
  annotation: `constitutibleArtwork`,

  compose: false,

  inputs: {
    contribs: input.staticDependency({
      validate: isContributionList,
      acceptsNull: true,
    }),

    date: input.staticDependency({
      validate: isDate,
      acceptsNull: true,
    }),

    artistProperty: input.staticValue({
      type: 'string',
    }),
  },

  steps: () => [
    exposeUpdateValueOrContinue({
      validate: input.value(
        validateThing({
          referenceType: 'artwork',
        })),
    }),

    exitWithoutDependency({
      dependency: input('contribs'),
      value: input.value(null),
    }),

    {
      dependencies: [
        input.staticDependency('contribs'),
        input.staticDependency('date'),
      ],

      compute: (continuation, {
        [input.staticDependency('contribs')]: contribsProperty,
        [input.staticDependency('date')]: dateProperty,
      }) => continuation({
        ['#contribsProperty']: contribsProperty,
        ['#dateProperty']: dateProperty,
      })
    },

    withConstitutedArtwork({
      contribsProperty: '#contribsProperty',
      artistProperty: input('artistProperty'),
      dateProperty: '#dateProperty',
    }),

    exposeDependency({
      dependency: '#constitutedArtwork',
    }),
  ],
});