« 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/flash.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/data/things/flash.js')
-rw-r--r--src/data/things/flash.js210
1 files changed, 86 insertions, 124 deletions
diff --git a/src/data/things/flash.js b/src/data/things/flash.js
index 11b19ebc..b595ec58 100644
--- a/src/data/things/flash.js
+++ b/src/data/things/flash.js
@@ -1,7 +1,6 @@
 export const FLASH_DATA_FILE = 'flashes.yaml';
 
-import {input} from '#composite';
-import {empty} from '#sugar';
+import {input, V} from '#composite';
 import {sortFlashesChronologically} from '#sort';
 import Thing from '#thing';
 import {anyOf, isColor, isContentString, isDirectory, isNumber, isString}
@@ -22,7 +21,6 @@ import {withPropertyFromObject} from '#composite/data';
 import {
   exposeConstant,
   exposeDependency,
-  exposeDependencyOrContinue,
   exposeUpdateValueOrContinue,
 } from '#composite/control-flow';
 
@@ -43,26 +41,29 @@ import {
   thing,
   thingList,
   urls,
-  wikiData,
 } from '#composite/wiki-properties';
 
-import {withFlashAct} from '#composite/things/flash';
-import {withFlashSide} from '#composite/things/flash-act';
-
 export class Flash extends Thing {
   static [Thing.referenceType] = 'flash';
+  static [Thing.wikiData] = 'flashData';
+
+  static [Thing.constitutibleProperties] = [
+    'coverArtwork', // from inline fields
+  ];
 
   static [Thing.getPropertyDescriptors] = ({
     AdditionalName,
     CommentaryEntry,
     CreditingSourcesEntry,
-    Track,
     FlashAct,
+    Track,
     WikiInfo,
   }) => ({
     // Update & expose
 
-    name: name('Unnamed Flash'),
+    act: thing(V(FlashAct)),
+
+    name: name(V('Unnamed Flash')),
 
     directory: {
       flags: {update: true, expose: true},
@@ -95,19 +96,13 @@ export class Flash extends Thing {
         validate: input.value(isColor),
       }),
 
-      withFlashAct(),
-
-      withPropertyFromObject({
-        object: '#flashAct',
-        property: input.value('color'),
-      }),
-
-      exposeDependency({dependency: '#flashAct.color'}),
+      withPropertyFromObject('act', V('color')),
+      exposeDependency('#act.color'),
     ],
 
     date: simpleDate(),
 
-    coverArtFileExtension: fileExtension('jpg'),
+    coverArtFileExtension: fileExtension(V('jpg')),
 
     coverArtDimensions: dimensions(),
 
@@ -116,7 +111,6 @@ export class Flash extends Thing {
         .call(this, 'Cover Artwork'),
 
     contributorContribs: contributionList({
-      date: 'date',
       artistProperty: input.value('flashContributorContributions'),
     }),
 
@@ -127,17 +121,10 @@ export class Flash extends Thing {
 
     urls: urls(),
 
-    additionalNames: thingList({
-      class: input.value(AdditionalName),
-    }),
-
-    commentary: thingList({
-      class: input.value(CommentaryEntry),
-    }),
+    additionalNames: thingList(V(AdditionalName)),
 
-    creditSources: thingList({
-      class: input.value(CreditingSourcesEntry),
-    }),
+    commentary: thingList(V(CommentaryEntry)),
+    creditingSources: thingList(V(CreditingSourcesEntry)),
 
     // Update only
 
@@ -145,28 +132,17 @@ export class Flash extends Thing {
     reverse: soupyReverse(),
 
     // used for withMatchingContributionPresets (indirectly by Contribution)
-    wikiInfo: thing({
-      class: input.value(WikiInfo),
-    }),
+    wikiInfo: thing(V(WikiInfo)),
 
     // Expose only
 
-    commentatorArtists: commentatorArtists(),
+    isFlash: exposeConstant(V(true)),
 
-    act: [
-      withFlashAct(),
-      exposeDependency({dependency: '#flashAct'}),
-    ],
+    commentatorArtists: commentatorArtists(),
 
     side: [
-      withFlashAct(),
-
-      withPropertyFromObject({
-        object: '#flashAct',
-        property: input.value('side'),
-      }),
-
-      exposeDependency({dependency: '#flashAct.side'}),
+      withPropertyFromObject('act', V('side')),
+      exposeDependency('#act.side'),
     ],
   });
 
@@ -257,8 +233,8 @@ export class Flash extends Thing {
         transform: parseCommentary,
       },
 
-      'Credit Sources': {
-        property: 'creditSources',
+      'Crediting Sources': {
+        property: 'creditingSources',
         transform: parseCreditingSources,
       },
 
@@ -278,11 +254,14 @@ export class Flash extends Thing {
 export class FlashAct extends Thing {
   static [Thing.referenceType] = 'flash-act';
   static [Thing.friendlyName] = `Flash Act`;
+  static [Thing.wikiData] = 'flashActData';
 
-  static [Thing.getPropertyDescriptors] = () => ({
+  static [Thing.getPropertyDescriptors] = ({Flash, FlashSide}) => ({
     // Update & expose
 
-    name: name('Unnamed Flash Act'),
+    side: thing(V(FlashSide)),
+
+    name: name(V('Unnamed Flash Act')),
     directory: directory(),
     color: color(),
 
@@ -291,26 +270,11 @@ export class FlashAct extends Thing {
         validate: input.value(isContentString),
       }),
 
-      withFlashSide(),
-
-      withPropertyFromObject({
-        object: '#flashSide',
-        property: input.value('listTerminology'),
-      }),
-
-      exposeDependencyOrContinue({
-        dependency: '#flashSide.listTerminology',
-      }),
-
-      exposeConstant({
-        value: input.value(null),
-      }),
+      withPropertyFromObject('side', V('listTerminology')),
+      exposeDependency('#side.listTerminology'),
     ],
 
-    flashes: referenceList({
-      class: input.value(Flash),
-      find: soupyFind.input('flash'),
-    }),
+    flashes: thingList(V(Flash)),
 
     // Update only
 
@@ -319,10 +283,7 @@ export class FlashAct extends Thing {
 
     // Expose only
 
-    side: [
-      withFlashSide(),
-      exposeDependency({dependency: '#flashSide'}),
-    ],
+    isFlashAct: exposeConstant(V(true)),
   });
 
   static [Thing.findSpecs] = {
@@ -357,23 +318,25 @@ export class FlashAct extends Thing {
 export class FlashSide extends Thing {
   static [Thing.referenceType] = 'flash-side';
   static [Thing.friendlyName] = `Flash Side`;
+  static [Thing.wikiData] = 'flashSideData';
 
-  static [Thing.getPropertyDescriptors] = () => ({
+  static [Thing.getPropertyDescriptors] = ({FlashAct}) => ({
     // Update & expose
 
-    name: name('Unnamed Flash Side'),
+    name: name(V('Unnamed Flash Side')),
     directory: directory(),
     color: color(),
     listTerminology: contentString(),
 
-    acts: referenceList({
-      class: input.value(FlashAct),
-      find: soupyFind.input('flashAct'),
-    }),
+    acts: thingList(V(FlashAct)),
 
     // Update only
 
     find: soupyFind(),
+
+    // Expose only
+
+    isFlashSide: exposeConstant(V(true)),
   });
 
   static [Thing.yamlDocumentSpec] = {
@@ -416,62 +379,61 @@ export class FlashSide extends Thing {
         ? FlashAct
         : Flash),
 
-    save(results) {
-      // JavaScript likes you.
+    connect(results) {
+      let thing, i;
 
-      if (!empty(results) && !(results[0] instanceof FlashSide)) {
-        throw new Error(`Expected a side at top of flash data file`);
-      }
+      for (i = 0; thing = results[i]; i++) {
+        if (thing.isFlashSide) {
+          const side = thing;
+          const acts = [];
 
-      let index = 0;
-      let thing;
-      for (; thing = results[index]; index++) {
-        const flashSide = thing;
-        const flashActRefs = [];
+          for (i++; thing = results[i]; i++) {
+            if (thing.isFlashAct) {
+              const act = thing;
+              const flashes = [];
 
-        if (results[index + 1] instanceof Flash) {
-          throw new Error(`Expected an act to immediately follow a side`);
-        }
+              for (i++; thing = results[i]; i++) {
+                if (thing.isFlash) {
+                  const flash = thing;
+
+                  flash.act = act;
+                  flashes.push(flash);
 
-        for (
-          index++;
-          (thing = results[index]) && thing instanceof FlashAct;
-          index++
-        ) {
-          const flashAct = thing;
-          const flashRefs = [];
-          for (
-            index++;
-            (thing = results[index]) && thing instanceof Flash;
-            index++
-          ) {
-            flashRefs.push(Thing.getReference(thing));
+                  continue;
+                }
+
+                i--;
+                break;
+              }
+
+              act.side = side;
+              act.flashes = flashes;
+              acts.push(act);
+
+              continue;
+            }
+
+            if (thing.isFlash) {
+              throw new Error(`Flashes must be under an act`);
+            }
+
+            i--;
+            break;
           }
-          index--;
-          flashAct.flashes = flashRefs;
-          flashActRefs.push(Thing.getReference(flashAct));
-        }
-        index--;
-        flashSide.acts = flashActRefs;
-      }
 
-      const flashData = results.filter(x => x instanceof Flash);
-      const flashActData = results.filter(x => x instanceof FlashAct);
-      const flashSideData = results.filter(x => x instanceof FlashSide);
+          side.acts = acts;
 
-      const artworkData = flashData.map(flash => flash.coverArtwork);
-      const commentaryData = flashData.flatMap(flash => flash.commentary);
-      const creditingSourceData = flashData.flatMap(flash => flash.creditSources);
+          continue;
+        }
 
-      return {
-        flashData,
-        flashActData,
-        flashSideData,
+        if (thing.isFlashAct) {
+          throw new Error(`Acts must be under a side`);
+        }
 
-        artworkData,
-        commentaryData,
-        creditingSourceData,
-      };
+        if (thing.isFlash) {
+          throw new Error(`Flashes must be under a side and act`);
+        }
+      }
     },
 
     sort({flashData}) {