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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
import {input, templateCompositeFrom} from '#composite';
import find from '#find';
import {empty, stitchArrays} from '#sugar';
import {isTrackSectionList} from '#validators';
import {filterMultipleArrays} from '#wiki-data';
import {exitWithoutDependency, exitWithoutUpdateValue}
from '#composite/control-flow';
import {withResolvedReferenceList} from '#composite/wiki-data';
import {
fillMissingListItems,
withFlattenedList,
withPropertiesFromList,
withUnflattenedList,
} from '#composite/data';
export default templateCompositeFrom({
annotation: `withTrackSections`,
outputs: ['#trackSections'],
steps: () => [
exitWithoutDependency({
dependency: 'trackData',
value: input.value([]),
}),
exitWithoutUpdateValue({
mode: input.value('empty'),
value: input.value([]),
}),
// TODO: input.updateValue description down here is a kludge.
withPropertiesFromList({
list: input.updateValue({
validate: isTrackSectionList,
}),
prefix: input.value('#sections'),
properties: input.value([
'tracks',
'dateOriginallyReleased',
'isDefaultTrackSection',
'name',
'color',
]),
}),
fillMissingListItems({
list: '#sections.tracks',
fill: input.value([]),
}),
fillMissingListItems({
list: '#sections.isDefaultTrackSection',
fill: input.value(false),
}),
fillMissingListItems({
list: '#sections.name',
fill: input.value('Unnamed Track Section'),
}),
fillMissingListItems({
list: '#sections.color',
fill: input.dependency('color'),
}),
withFlattenedList({
list: '#sections.tracks',
}).outputs({
['#flattenedList']: '#trackRefs',
['#flattenedIndices']: '#sections.startIndex',
}),
withResolvedReferenceList({
list: '#trackRefs',
data: 'trackData',
notFoundMode: input.value('null'),
find: input.value(find.track),
}).outputs({
['#resolvedReferenceList']: '#tracks',
}),
withUnflattenedList({
list: '#tracks',
indices: '#sections.startIndex',
}).outputs({
['#unflattenedList']: '#sections.tracks',
}),
{
dependencies: [
'#sections.tracks',
'#sections.name',
'#sections.color',
'#sections.dateOriginallyReleased',
'#sections.isDefaultTrackSection',
'#sections.startIndex',
],
compute: (continuation, {
'#sections.tracks': tracks,
'#sections.name': name,
'#sections.color': color,
'#sections.dateOriginallyReleased': dateOriginallyReleased,
'#sections.isDefaultTrackSection': isDefaultTrackSection,
'#sections.startIndex': startIndex,
}) => {
filterMultipleArrays(
tracks, name, color, dateOriginallyReleased, isDefaultTrackSection, startIndex,
tracks => !empty(tracks));
return continuation({
['#trackSections']:
stitchArrays({
tracks,
name,
color,
dateOriginallyReleased,
isDefaultTrackSection,
startIndex,
}),
});
},
},
],
});
|