« get me outta code hell

raiseResolvedReferenceList.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/raiseResolvedReferenceList.js
blob: d5980bfe4fc78de42371293cee695f24b902f914 (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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// Concludes compositions like withResolvedReferenceList, which share behavior
// in processing the resolved results before continuing further.

import {input, templateCompositeFrom} from '#composite';

import {withFilteredList} from '#composite/data';

import inputNotFoundMode from './inputNotFoundMode.js';

export default templateCompositeFrom({
  inputs: {
    notFoundMode: inputNotFoundMode(),

    results: input({type: 'array'}),
    filter: input({type: 'array'}),

    exitValue: input({defaultValue: []}),

    outputs: input.staticValue({type: 'string'}),
  },

  // TODO: Is it even necessary to specify outputs if you're using
  // raiseOutputAbove??
  outputs: ({
    [input.staticValue('outputs')]: outputs,
  }) => [outputs],

  steps: () => [
    {
      dependencies: [
        input('results'),
        input('filter'),
        input('outputs'),
      ],

      compute: (continuation, {
        [input('results')]: results,
        [input('filter')]: filter,
        [input('outputs')]: outputs,
      }) =>
        (filter.every(keep => keep)
          ? continuation.raiseOutput({[outputs]: results})
          : continuation()),
    },

    {
      dependencies: [
        input('notFoundMode'),
        input('exitValue'),
      ],

      compute: (continuation, {
        [input('notFoundMode')]: notFoundMode,
        [input('exitValue')]: exitValue,
      }) =>
        (notFoundMode === 'exit'
          ? continuation.exit(exitValue)
          : continuation()),
    },

    {
      dependencies: [
        input('results'),
        input('notFoundMode'),
        input('outputs'),
      ],

      compute: (continuation, {
        [input('results')]: results,
        [input('notFoundMode')]: notFoundMode,
        [input('outputs')]: outputs,
      }) =>
        (notFoundMode === 'null'
          ? continuation.raiseOutput({[outputs]: results})
          : continuation()),
    },

    withFilteredList({
      list: input('results'),
      filter: input('filter'),
    }),

    {
      dependencies: [
        '#filteredList',
        input('outputs'),
      ],

      compute: (continuation, {
        ['#filteredList']: filteredList,
        [input('outputs')]: outputs,
      }) => continuation({
        [outputs]:
          filteredList,
      }),
    },
  ],
});