« get me outta code hell

withAlwaysReferenceByDirectory.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/withAlwaysReferenceByDirectory.js
blob: 7c59393cd629cbbfb51d6616bdfd1365dad9cbd6 (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
// Controls how find.track works - it'll never be matched by a reference
// just to the track's name, which means you don't have to always reference
// some *other* (much more commonly referenced) track by directory instead
// of more naturally by name.

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

import {exitWithoutDependency, exposeUpdateValueOrContinue}
  from '#composite/control-flow';
import {excludeFromList, withPropertyFromObject} from '#composite/data';

import withOriginalRelease from './withOriginalRelease.js';

export default templateCompositeFrom({
  annotation: `withAlwaysReferenceByDirectory`,

  outputs: ['#alwaysReferenceByDirectory'],

  steps: () => [
    exposeUpdateValueOrContinue({
      validate: input.value(isBoolean),
    }),

    excludeFromList({
      list: 'trackData',
      item: input.myself(),
    }),

    withOriginalRelease({
      data: '#trackData',
    }),

    exitWithoutDependency({
      dependency: '#originalRelease',
      value: input.value(false),
    }),

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

    {
      dependencies: ['name', '#originalRelease.name'],
      compute: (continuation, {
        name,
        ['#originalRelease.name']: originalName,
      }) => continuation({
        ['#alwaysReferenceByDirectory']: name === originalName,
      }),
    },
  ],
});