From 04682cbea790fde874a8488777738d28758012a9 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Mon, 7 Jun 2021 14:50:01 -0300 Subject: experimental AggregateError & Thing class hijinks --- src/thing/album.js | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/thing/album.js (limited to 'src/thing/album.js') diff --git a/src/thing/album.js b/src/thing/album.js new file mode 100644 index 0000000..1915ab8 --- /dev/null +++ b/src/thing/album.js @@ -0,0 +1,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); +} -- cgit 1.3.0-6-gf8a5