« get me outta code hell

album.js « thing « src - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/thing/album.js
blob: 1915ab850e521e42a8cacd4577e7477eeb87abad (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
import Thing from './thing.js';

import {
    validateReference
} from './structures.js';

import {
    showAggregate,
    withAggregate
} from '../util/sugar.js';

export default class Album extends Thing {
    #tracks;

    static updateError = {
        tracks: Thing.extendPropertyError('tracks')
    };

    update(source) {
        withAggregate(({ wrap, call, map }) => {
            if (source.tracks) {
                this.#tracks = map(source.tracks, validateReference('track'), {
                    errorClass: this.constructor.updateError.tracks
                });
            }
        });
    }
}

const album = new Album();

try {
    album.update({
        tracks: [
            'lol',
            123,
            'track:oh-yeah',
            'group:what-am-i-doing-here'
        ]
    });
} catch (error) {
    showAggregate(error);
}