« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/data/things/homepage-layout.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/data/things/homepage-layout.js')
-rw-r--r--src/data/things/homepage-layout.js77
1 files changed, 34 insertions, 43 deletions
diff --git a/src/data/things/homepage-layout.js b/src/data/things/homepage-layout.js
index 82bad2d3..c4dc2812 100644
--- a/src/data/things/homepage-layout.js
+++ b/src/data/things/homepage-layout.js
@@ -3,7 +3,7 @@ export const HOMEPAGE_LAYOUT_DATA_FILE = 'homepage.yaml';
 import {inspect} from 'node:util';
 
 import {colors} from '#cli';
-import {input} from '#composite';
+import {input, V} from '#composite';
 import Thing from '#thing';
 import {empty} from '#sugar';
 
@@ -17,7 +17,7 @@ import {
   validateReference,
 } from '#validators';
 
-import {exposeDependency} from '#composite/control-flow';
+import {exposeConstant, exposeDependency} from '#composite/control-flow';
 import {withResolvedReference} from '#composite/wiki-data';
 
 import {
@@ -32,6 +32,8 @@ import {
 
 export class HomepageLayout extends Thing {
   static [Thing.friendlyName] = `Homepage Layout`;
+  static [Thing.wikiData] = 'homepageLayout';
+  static [Thing.oneInstancePerWiki] = true;
 
   static [Thing.getPropertyDescriptors] = ({HomepageLayoutSection}) => ({
     // Update & expose
@@ -44,9 +46,11 @@ export class HomepageLayout extends Thing {
       expose: {transform: value => value ?? []},
     },
 
-    sections: thingList({
-      class: input.value(HomepageLayoutSection),
-    }),
+    sections: thingList(V(HomepageLayoutSection)),
+
+    // Expose only
+
+    isHomepageLayout: exposeConstant(V(true)),
   });
 
   static [Thing.yamlDocumentSpec] = {
@@ -63,7 +67,6 @@ export class HomepageLayout extends Thing {
     thingConstructors: {
       HomepageLayout,
       HomepageLayoutSection,
-      HomepageLayoutAlbumsRow,
     },
   }) => ({
     title: `Process homepage layout file`,
@@ -95,7 +98,7 @@ export class HomepageLayout extends Thing {
       return null;
     },
 
-    save(results) {
+    connect(results) {
       if (!empty(results) && !(results[0] instanceof HomepageLayout)) {
         throw new Error(`Expected 'Homepage' document at top of homepage layout file`);
       }
@@ -138,8 +141,6 @@ export class HomepageLayout extends Thing {
       closeCurrentSection();
 
       homepageLayout.sections = sections;
-
-      return {homepageLayout};
     },
   });
 }
@@ -150,13 +151,15 @@ export class HomepageLayoutSection extends Thing {
   static [Thing.getPropertyDescriptors] = ({HomepageLayoutRow}) => ({
     // Update & expose
 
-    name: name(`Unnamed Homepage Section`),
+    name: name(V(`Unnamed Homepage Section`)),
 
     color: color(),
 
-    rows: thingList({
-      class: input.value(HomepageLayoutRow),
-    }),
+    rows: thingList(V(HomepageLayoutRow)),
+
+    // Expose only
+
+    isHomepageLayoutSection: exposeConstant(V(true)),
   });
 
   static [Thing.yamlDocumentSpec] = {
@@ -173,9 +176,7 @@ export class HomepageLayoutRow extends Thing {
   static [Thing.getPropertyDescriptors] = ({HomepageLayoutSection}) => ({
     // Update & expose
 
-    section: thing({
-      class: input.value(HomepageLayoutSection),
-    }),
+    section: thing(V(HomepageLayoutSection)),
 
     // Update only
 
@@ -183,6 +184,8 @@ export class HomepageLayoutRow extends Thing {
 
     // Expose only
 
+    isHomepageLayoutRow: exposeConstant(V(true)),
+
     type: {
       flags: {expose: true},
 
@@ -222,9 +225,7 @@ export class HomepageLayoutRow extends Thing {
 export class HomepageLayoutActionsRow extends HomepageLayoutRow {
   static [Thing.friendlyName] = `Homepage Actions Row`;
 
-  static [Thing.getPropertyDescriptors] = (opts) => ({
-    ...HomepageLayoutRow[Thing.getPropertyDescriptors](opts),
-
+  static [Thing.getPropertyDescriptors] = () => ({
     // Update & expose
 
     actionLinks: {
@@ -234,25 +235,21 @@ export class HomepageLayoutActionsRow extends HomepageLayoutRow {
 
     // Expose only
 
-    type: {
-      flags: {expose: true},
-      expose: {compute: () => 'actions'},
-    },
+    isHomepageLayoutActionsRow: exposeConstant(V(true)),
+    type: exposeConstant(V('actions')),
   });
 
-  static [Thing.yamlDocumentSpec] = Thing.extendDocumentSpec(HomepageLayoutRow, {
+  static [Thing.yamlDocumentSpec] = {
     fields: {
       'Actions': {property: 'actionLinks'},
     },
-  });
+  };
 }
 
 export class HomepageLayoutAlbumCarouselRow extends HomepageLayoutRow {
   static [Thing.friendlyName] = `Homepage Album Carousel Row`;
 
-  static [Thing.getPropertyDescriptors] = (opts, {Album, Group} = opts) => ({
-    ...HomepageLayoutRow[Thing.getPropertyDescriptors](opts),
-
+  static [Thing.getPropertyDescriptors] = (opts, {Album} = opts) => ({
     // Update & expose
 
     albums: referenceList({
@@ -262,25 +259,21 @@ export class HomepageLayoutAlbumCarouselRow extends HomepageLayoutRow {
 
     // Expose only
 
-    type: {
-      flags: {expose: true},
-      expose: {compute: () => 'album carousel'},
-    },
+    isHomepageLayoutAlbumCarouselRow: exposeConstant(V(true)),
+    type: exposeConstant(V('album carousel')),
   });
 
-  static [Thing.yamlDocumentSpec] = Thing.extendDocumentSpec(HomepageLayoutRow, {
+  static [Thing.yamlDocumentSpec] = {
     fields: {
       'Albums': {property: 'albums'},
     },
-  });
+  };
 }
 
 export class HomepageLayoutAlbumGridRow extends HomepageLayoutRow {
   static [Thing.friendlyName] = `Homepage Album Grid Row`;
 
   static [Thing.getPropertyDescriptors] = (opts, {Album, Group} = opts) => ({
-    ...HomepageLayoutRow[Thing.getPropertyDescriptors](opts),
-
     // Update & expose
 
     sourceGroup: [
@@ -307,7 +300,7 @@ export class HomepageLayoutAlbumGridRow extends HomepageLayoutRow {
         find: soupyFind.input('group'),
       }),
 
-      exposeDependency({dependency: '#resolvedReference'}),
+      exposeDependency('#resolvedReference'),
     ],
 
     sourceAlbums: referenceList({
@@ -322,17 +315,15 @@ export class HomepageLayoutAlbumGridRow extends HomepageLayoutRow {
 
     // Expose only
 
-    type: {
-      flags: {expose: true},
-      expose: {compute: () => 'album grid'},
-    },
+    isHomepageLayoutAlbumGridRow: exposeConstant(V(true)),
+    type: exposeConstant(V('album grid')),
   });
 
-  static [Thing.yamlDocumentSpec] = Thing.extendDocumentSpec(HomepageLayoutRow, {
+  static [Thing.yamlDocumentSpec] = {
     fields: {
       'Group': {property: 'sourceGroup'},
       'Count': {property: 'countAlbumsFromGroup'},
       'Albums': {property: 'sourceAlbums'},
     },
-  });
+  };
 }