« get me outta code hell

withPropertyFromOriginalRelease.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/withPropertyFromOriginalRelease.js
blob: fd37f6de4ce23a1d0e367d8d54836f9da2e5140b (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 original release, if applicable, and a
// flag indicating if this track is a rerelase or not.
//
// Like withOriginalRelease, this will early exit (with notFoundValue) if the
// original 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 withOriginalRelease from './withOriginalRelease.js';

export default templateCompositeFrom({
  annotation: `inheritFromOriginalRelease`,

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

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

  outputs: ({
    [input.staticValue('property')]: property,
  }) =>
    ['#isRerelease'].concat(
      (property
        ? ['#original.' + property]
        : ['#originalValue'])),

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

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

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

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

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

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

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