« get me outta code hell

withStartCountingFrom.js « track-section « 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-section/withStartCountingFrom.js
blob: ef34532716fb8c189df136a6245b30e27958f8f0 (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
import {input, templateCompositeFrom} from '#composite';

import {raiseOutputWithoutDependency} from '#composite/control-flow';
import {withNearbyItemFromList, withPropertyFromObject} from '#composite/data';

import withAlbum from './withAlbum.js';

export default templateCompositeFrom({
  annotation: `withStartCountingFrom`,

  inputs: {
    from: input({
      type: 'number',
      defaultDependency: 'startCountingFrom',
      acceptsNull: true,
    }),
  },

  outputs: ['#startCountingFrom'],

  steps: () => [
    {
      dependencies: [input('from')],
      compute: (continuation, {
        [input('from')]: from,
      }) =>
        (from === null
          ? continuation()
          : continuation.raiseOutput({'#startCountingFrom': from})),
    },

    withAlbum(),

    raiseOutputWithoutDependency({
      dependency: '#album',
      output: input.value({'#startCountingFrom': 1}),
    }),

    withPropertyFromObject({
      object: '#album',
      property: input.value('trackSections'),
    }),

    withNearbyItemFromList({
      list: '#album.trackSections',
      item: input.myself(),
      offset: input.value(-1),
    }).outputs({
      '#nearbyItem': '#previousTrackSection',
    }),

    raiseOutputWithoutDependency({
      dependency: '#previousTrackSection',
      output: input.value({'#startCountingFrom': 1}),
    }),

    withPropertyFromObject({
      object: '#previousTrackSection',
      property: input.value('continueCountingFrom'),
    }).outputs({
      '#previousTrackSection.continueCountingFrom': '#startCountingFrom',
    }),
  ],
});