From 9d62c4bae52f30cfd6536762eca46bfa2d2bbfdf Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Thu, 10 Jun 2021 16:58:48 -0300 Subject: src/things shenanigans --- src/thing/album.js | 10 ++++++++-- src/thing/structures.js | 2 ++ 2 files changed, 10 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/thing/album.js b/src/thing/album.js index 1915ab85..be37489d 100644 --- a/src/thing/album.js +++ b/src/thing/album.js @@ -10,7 +10,7 @@ import { } from '../util/sugar.js'; export default class Album extends Thing { - #tracks; + #tracks = []; static updateError = { tracks: Thing.extendPropertyError('tracks') @@ -19,16 +19,20 @@ export default class Album extends Thing { update(source) { withAggregate(({ wrap, call, map }) => { if (source.tracks) { - this.#tracks = map(source.tracks, validateReference('track'), { + 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: [ @@ -41,3 +45,5 @@ try { } catch (error) { showAggregate(error); } + +console.log('tracks (after):', album.tracks); diff --git a/src/thing/structures.js b/src/thing/structures.js index e6b9fd4b..e1bf06c0 100644 --- a/src/thing/structures.js +++ b/src/thing/structures.js @@ -13,5 +13,7 @@ export function validateReference(type = '') { if (typePart !== type) throw new TypeError(`Expected ref to begin with "${type}:", got "${typePart}:" (ref: ${ref})`); } + + return true; }; } -- cgit 1.3.0-6-gf8a5