« get me outta code hell

exitWithoutContribs.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/exitWithoutContribs.js
blob: 2c8219fce694e19a617b845b8fd2127e7ed8dc5e (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
// Shorthand for exiting if the contribution list (usually a property's update
// value) resolves to empty - ensuring that the later computed results are only
// returned if these contributions are present.

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

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

import withResolvedContribs from './withResolvedContribs.js';

export default templateCompositeFrom({
  annotation: `exitWithoutContribs`,

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

    value: input({defaultValue: null}),
  },

  steps: () => [
    withResolvedContribs({
      from: input('contribs'),
    }),

    // TODO: Fairly certain exitWithoutDependency would be sufficient here.

    withResultOfAvailabilityCheck({
      from: '#resolvedContribs',
      mode: input.value('empty'),
    }),

    {
      dependencies: ['#availability', input('value')],
      compute: (continuation, {
        ['#availability']: availability,
        [input('value')]: value,
      }) =>
        (availability
          ? continuation()
          : continuation.exit(value)),
    },
  ],
});