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
|
// Gets the track's album. This will early exit if albumData is missing.
// If there's no album whose list of tracks includes this track, the output
// dependency will be null.
//
// This step models with Flash.withFlashAct.
import {input, templateCompositeFrom} from '#composite';
import {is} from '#validators';
import {exitWithoutDependency, raiseOutputWithoutDependency}
from '#composite/control-flow';
import {withPropertyFromList} from '#composite/data';
export default templateCompositeFrom({
annotation: `withAlbum`,
outputs: ['#album'],
steps: () => [
exitWithoutDependency({
dependency: 'albumData',
mode: input.value('null'),
}),
withPropertyFromList({
list: 'albumData',
property: input.value('tracks'),
}),
{
dependencies: [input.myself(), '#albumData.tracks'],
compute: (continuation, {
[input.myself()]: track,
['#albumData.tracks']: trackLists,
}) => continuation({
['#albumIndex']:
trackLists.findIndex(tracks => tracks.includes(track)),
}),
},
raiseOutputWithoutDependency({
dependency: '#albumIndex',
mode: input.value('index'),
output: input.value({'#album': null}),
}),
{
dependencies: ['albumData', '#albumIndex'],
compute: (continuation, {
['albumData']: albumData,
['#albumIndex']: albumIndex,
}) => continuation.raiseOutput({
['#album']:
albumData[albumIndex],
}),
},
],
});
|