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
|
import {input, templateCompositeFrom} from '#composite';
import {raiseOutputWithoutDependency} from '#composite/control-flow';
import {withIndexInList, withPropertiesFromObject} from '#composite/data';
import withContainingTrackSection from './withContainingTrackSection.js';
export default templateCompositeFrom({
annotation: `withTrackNumber`,
outputs: ['#trackNumber'],
steps: () => [
withContainingTrackSection(),
// Zero is the fallback, not one, but in most albums the first track
// (and its intended output by this composition) will be one.
raiseOutputWithoutDependency({
dependency: '#trackSection',
output: input.value({'#trackNumber': 0}),
}),
withPropertiesFromObject({
object: '#trackSection',
properties: input.value(['tracks', 'startCountingFrom']),
}),
withIndexInList({
list: '#trackSection.tracks',
item: input.myself(),
}),
raiseOutputWithoutDependency({
dependency: '#index',
output: input.value({'#trackNumber': 0}),
}),
{
dependencies: ['#trackSection.startCountingFrom', '#index'],
compute: (continuation, {
['#trackSection.startCountingFrom']: startCountingFrom,
['#index']: index,
}) => continuation({
['#trackNumber']:
startCountingFrom +
index,
}),
},
],
});
|