« get me outta code hell

withDate.js « track « things « composite « data « src - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/data/composite/things/track/withDate.js
blob: b5a770e926eb994386ad98887d8ce2515428a4f3 (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
// Gets the track's own date. This is either its dateFirstReleased property
// or, if unset, the album's date.

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

import withPropertyFromAlbum from './withPropertyFromAlbum.js';

export default templateCompositeFrom({
  annotation: `withDate`,

  outputs: ['#date'],

  steps: () => [
    {
      dependencies: ['dateFirstReleased'],
      compute: (continuation, {dateFirstReleased}) =>
        (dateFirstReleased
          ? continuation.raiseOutput({'#date': dateFirstReleased})
          : continuation()),
    },

    withPropertyFromAlbum({
      property: input.value('date'),
    }),

    {
      dependencies: ['#album.date'],
      compute: (continuation, {['#album.date']: albumDate}) =>
        (albumDate
          ? continuation.raiseOutput({'#date': albumDate})
          : continuation.raiseOutput({'#date': null})),
    },
  ],
})