blob: be37489d03d46287bdb85b77e134fc3829d722db (
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
|
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, t => validateReference('track')(t) && t, {
errorClass: this.constructor.updateError.tracks
});
}
});
}
get tracks() { return this.#tracks; }
}
const album = new Album();
console.log('tracks (before):', album.tracks);
try {
album.update({
tracks: [
'lol',
123,
'track:oh-yeah',
'group:what-am-i-doing-here'
]
});
} catch (error) {
showAggregate(error);
}
console.log('tracks (after):', album.tracks);
|