« get me outta code hell

experimental AggregateError & Thing class hijinks - 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:
author(quasar) nebula <towerofnix@gmail.com>2021-06-07 14:50:01 -0300
committer(quasar) nebula <towerofnix@gmail.com>2021-06-07 14:50:01 -0300
commit04682cbea790fde874a8488777738d28758012a9 (patch)
tree8791f4eff39905d577749c5f70d4587b2607f000 /src/thing/album.js
parentb2469c03bd4bdb29c5e80752f812203a6755c159 (diff)
experimental AggregateError & Thing class hijinks
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);
+}