« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/thing
diff options
context:
space:
mode:
Diffstat (limited to 'src/thing')
-rw-r--r--src/thing/album.js10
-rw-r--r--src/thing/structures.js2
2 files changed, 10 insertions, 2 deletions
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;
     };
 }