« 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/album.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/thing/album.js')
-rw-r--r--src/thing/album.js43
1 files changed, 43 insertions, 0 deletions
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);
+}