« get me outta code hell

withRecontextualizedContributionList.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/withRecontextualizedContributionList.js
blob: 1c86c0ab234754953ff169e9be2a0042d9a01118 (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
// Clones all the contributions in a list, with thing and thingProperty both
// updated to match the current thing. Overwrite the provided dependency.
// Doesn't do anything if the provided dependency is null.

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

import {raiseOutputWithoutDependency} from '#composite/control-flow';
import {withClonedThings} from '#composite/wiki-data';

export default templateCompositeFrom({
  annotation: `withRecontextualizedContributionList`,

  inputs: {
    list: input.staticDependency({
      type: 'array',
      acceptsNull: true,
    }),
  },

  outputs: ({
    [input.staticDependency('list')]: list,
  }) => [list],

  steps: () => [
    // TODO: Is raiseOutputWithoutDependency workable here?
    // Is it true that not specifying any output wouldn't overwrite
    // the provided dependency?
    {
      dependencies: [
        input.staticDependency('list'),
        input('list'),
      ],

      compute: (continuation, {
        [input.staticDependency('list')]: dependency,
        [input('list')]: list,
      }) =>
        (list
          ? continuation()
          : continuation.raiseOutput({
              [dependency]: list,
            })),
    },

    {
      dependencies: [input.myself(), input.thisProperty()],

      compute: (continuation, {
        [input.myself()]: myself,
        [input.thisProperty()]: thisProperty,
      }) => continuation({
        ['#assignment']: {
          thing: myself,
          thingProperty: thisProperty,
        },
      }),
    },

    withClonedThings({
      things: input('list'),
      assign: '#assignment',
    }).outputs({
      '#clonedThings': '#newContributions',
    }),

    {
      dependencies: [
        input.staticDependency('list'),
        '#newContributions',
      ],

      compute: (continuation, {
        [input.staticDependency('list')]: listDependency,
        ['#newContributions']: newContributions,
      }) => continuation({
        [listDependency]:
          newContributions,
      }),
    },
  ],
});