« get me outta code hell

src/things shenanigans - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
author(quasar) nebula <towerofnix@gmail.com>2021-06-10 16:58:48 -0300
committer(quasar) nebula <towerofnix@gmail.com>2021-06-10 16:58:48 -0300
commit9d62c4bae52f30cfd6536762eca46bfa2d2bbfdf (patch)
treef57d0393e49bf6b9f41e0472fe9a73d41f53785f /src
parent4b04056f18555824dde09914553fde71ad2e009b (diff)
src/things shenanigans
Diffstat (limited to 'src')
-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;
     };
 }