« 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: ba3e2275b8508479f6a4b23e4fdb58f1b2565037 (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
// Provides a value inherited from the main release, or null,
// if this track is not a secondary release.

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

import {withPropertyFromObject} from '#composite/data';

export default templateCompositeFrom({
  annotation: `withPropertyFromMainRelease`,

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

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

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

    withPropertyFromObject({
      object: 'mainReleaseTrack',
      property: input('property'),
    }),

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