« get me outta code hell

inheritFromContributionPresets.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/inheritFromContributionPresets.js
blob: 7264295742f58f44e09332277eaf58254f6cad7e (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
import {input, templateCompositeFrom} from '#composite';

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

import withMatchingContributionPresets
  from './withMatchingContributionPresets.js';

export default templateCompositeFrom({
  annotation: `inheritFromContributionPresets`,

  inputs: {
    property: input({type: 'string'}),
  },

  steps: () => [
    withMatchingContributionPresets().outputs({
      '#matchingContributionPresets': '#presets',
    }),

    raiseOutputWithoutDependency({
      dependency: '#presets',
      mode: input.value('empty'),
    }),

    withPropertyFromList({
      list: '#presets',
      property: input('property'),
    }),

    {
      dependencies: ['#values'],

      compute: (continuation, {
        ['#values']: values,
      }) => continuation({
        ['#presetIndex']:
          values.findIndex(value =>
            value !== undefined &&
            value !== null),
      }),
    },

    raiseOutputWithoutDependency({
      dependency: '#presetIndex',
      mode: input.value('index'),
    }),

    {
      dependencies: ['#presets', '#presetIndex'],

      compute: (continuation, {
        ['#presets']: presets,
        ['#presetIndex']: presetIndex,
      }) => continuation({
        ['#preset']:
          presets[presetIndex],
      }),
    },

    withPropertyFromObject({
      object: '#preset',
      property: input('property'),
    }),

    // Can't use exposeDependency here since it doesn't compose, and so looks
    // unfit to serve as the composition's base - even though we'll have raised
    // out of this composition in the relevant cases already!
    {
      dependencies: ['#value'],
      compute: (continuation, {
        ['#value']: value,
      }) => continuation.exit(value),
    },
  ],
});