« get me outta code hell

withReverseAnnotatedReferenceList.js « wiki-data « composite « data « src - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/data/composite/wiki-data/withReverseAnnotatedReferenceList.js
blob: 168b68c0581ffe2bbb477bb0b4cfd4f6c734537c (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
70
71
72
73
74
75
76
77
78
79
80
81
// Analogous implementation for withReverseReferenceList, for annotated
// references.
//
// Unlike withReverseContributionList, this composition is responsible for
// "flipping" the directionality of references: in a forward reference list,
// `thing` points to the thing being referenced, while here, it points to the
// referencing thing.

import withReverseList_template from './helpers/withReverseList-template.js';

import {input} from '#composite';
import {stitchArrays} from '#sugar';

import {
  withFlattenedList,
  withMappedList,
  withPropertyFromList,
  withStretchedList,
} from '#composite/data';

export default withReverseList_template({
  annotation: `withReverseAnnotatedReferenceList`,

  propertyInputName: 'list',
  outputName: '#reverseAnnotatedReferenceList',

  customCompositionSteps: () => [
    withPropertyFromList({
      list: input('data'),
      property: input('list'),
    }).outputs({
      '#values': '#referenceLists',
    }),

    withPropertyFromList({
      list: '#referenceLists',
      property: input.value('length'),
    }),

    withFlattenedList({
      list: '#referenceLists',
    }).outputs({
      '#flattenedList': '#references',
    }),

    withStretchedList({
      list: input('data'),
      lengths: '#referenceLists.length',
    }).outputs({
      '#stretchedList': '#things',
    }),

    withPropertyFromList({
      list: '#references',
      property: input.value('annotation'),
    }).outputs({
      '#references.annotation': '#annotations',
    }),

    {
      dependencies: ['#things', '#annotations'],
      compute: (continuation, {
        ['#things']: things,
        ['#annotations']: annotations,
      }) => continuation({
        ['#referencingThings']:
          stitchArrays({
            thing: things,
            annotation: annotations,
          }),
      }),
    },

    withMappedList({
      list: '#references',
      map: input.value(reference => [reference.thing]),
    }).outputs({
      '#mappedList': '#referencedThings',
    }),
  ],
});