« get me outta code hell

withPropertyFromMainRelease.js « track « 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/track/withPropertyFromMainRelease.js
blob: 393a4c632eeb642becd24ab33f9b75f4ee96e671 (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
77
78
79
80
81
82
83
84
85
86
// Provides a value inherited from the main release, if applicable, and a
// flag indicating if this track is a secondary release or not.
//
// Like withMainRelease, this will early exit (with notFoundValue) if the
// main release is specified by reference and that reference doesn't
// resolve to anything.

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

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

import withMainRelease from './withMainRelease.js';

export default templateCompositeFrom({
  annotation: `inheritFromMainRelease`,

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

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

  outputs: ({
    [input.staticValue('property')]: property,
  }) =>
    ['#isSecondaryRelease'].concat(
      (property
        ? ['#mainRelease.' + property]
        : ['#mainReleaseValue'])),

  steps: () => [
    withMainRelease({
      notFoundValue: input('notFoundValue'),
    }),

    withResultOfAvailabilityCheck({
      from: '#mainRelease',
    }),

    {
      dependencies: [
        '#availability',
        input.staticValue('property'),
      ],

      compute: (continuation, {
        ['#availability']: availability,
        [input.staticValue('property')]: property,
      }) =>
        (availability
          ? continuation()
          : continuation.raiseOutput(
              Object.assign(
                {'#isSecondaryRelease': false},
                (property
                  ? {['#mainRelease.' + property]: null}
                  : {'#mainReleaseValue': null})))),
    },

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

    {
      dependencies: [
        '#value',
        input.staticValue('property'),
      ],

      compute: (continuation, {
        ['#value']: value,
        [input.staticValue('property')]: property,
      }) =>
        continuation.raiseOutput(
          Object.assign(
            {'#isSecondaryRelease': true},
            (property
              ? {['#mainRelease.' + property]: value}
              : {'#mainReleaseValue': value}))),
    },
  ],
});