« get me outta code hell

withAvailabilityFilter.js « control-flow « composite « data « src - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/data/composite/control-flow/withAvailabilityFilter.js
blob: cfea998e9dd03d0874e77f2eb6ba05327ee5c0e0 (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
// Performs the same availability check across all items of a list, providing
// a list that's suitable anywhere a filter is expected.
//
// Accepts the same mode options as withResultOfAvailabilityCheck.
//
// See also:
//  - withFilteredList
//  - withResultOfAvailabilityCheck
//

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

import inputAvailabilityCheckMode from './inputAvailabilityCheckMode.js';

import performAvailabilityCheck from './helpers/performAvailabilityCheck.js';

export default templateCompositeFrom({
  annotation: `withAvailabilityFilter`,

  inputs: {
    from: input({type: 'array'}),
    mode: inputAvailabilityCheckMode(),
  },

  outputs: ['#availabilityFilter'],

  steps: () => [
    {
      dependencies: [input('from'), input('mode')],
      compute: (continuation, {
        [input('from')]: list,
        [input('mode')]: mode,
      }) => continuation({
        ['#availabilityFilter']:
          list.map(value =>
            performAvailabilityCheck(value, mode)),
      }),
    },
  ],
});