« get me outta code hell

alwaysReferenceByDirectory.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/alwaysReferenceByDirectory.js
blob: a342d38b69944d347f1d2ffe8bfb3bb614a0a83e (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
// 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 {getKebabCase} from '#wiki-data';

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

import {
  exitWithoutDependency,
  exposeDependencyOrContinue,
  exposeUpdateValueOrContinue,
} from '#composite/control-flow';

import withMainReleaseTrack from './withMainReleaseTrack.js';
import withPropertyFromAlbum from './withPropertyFromAlbum.js';

export default templateCompositeFrom({
  annotation: `alwaysReferenceByDirectory`,

  compose: false,

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

    withPropertyFromAlbum({
      property: input.value('alwaysReferenceTracksByDirectory'),
    }),

    // Falsy mode means this exposes true if the album's property is true,
    // but continues if the property is false (which is also the default).
    exposeDependencyOrContinue({
      dependency: '#album.alwaysReferenceTracksByDirectory',
      mode: input.value('falsy'),
    }),

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

    withMainReleaseTrack(),

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

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

    {
      dependencies: ['name', '#mainReleaseTrack.name'],
      compute: ({
        ['name']: name,
        ['#mainReleaseTrack.name']: mainReleaseName,
      }) =>
        getKebabCase(name) ===
        getKebabCase(mainReleaseName),
    },
  ],
});