« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/data/checks.js4
-rw-r--r--src/data/composite/things/flash-act/index.js1
-rw-r--r--src/data/composite/things/flash-act/withFlashSide.js22
-rw-r--r--src/data/composite/things/flash/index.js1
-rw-r--r--src/data/composite/things/flash/withFlashAct.js22
-rw-r--r--src/data/things/flash.js153
6 files changed, 83 insertions, 120 deletions
diff --git a/src/data/checks.js b/src/data/checks.js
index fd2c4931..ac1b6257 100644
--- a/src/data/checks.js
+++ b/src/data/checks.js
@@ -285,10 +285,6 @@ export function filterReferenceErrors(wikiData, {
       featuredTracks: 'track',
     }],
 
-    ['flashActData', {
-      flashes: 'flash',
-    }],
-
     ['seriesData', {
       albums: 'album',
     }],
diff --git a/src/data/composite/things/flash-act/index.js b/src/data/composite/things/flash-act/index.js
deleted file mode 100644
index 40fecd2f..00000000
--- a/src/data/composite/things/flash-act/index.js
+++ /dev/null
@@ -1 +0,0 @@
-export {default as withFlashSide} from './withFlashSide.js';
diff --git a/src/data/composite/things/flash-act/withFlashSide.js b/src/data/composite/things/flash-act/withFlashSide.js
deleted file mode 100644
index e09f06e6..00000000
--- a/src/data/composite/things/flash-act/withFlashSide.js
+++ /dev/null
@@ -1,22 +0,0 @@
-// Gets the flash act's side. This will early exit if flashSideData is missing.
-// If there's no side whose list of flash acts includes this act, the output
-// dependency will be null.
-
-import {templateCompositeFrom} from '#composite';
-
-import {withUniqueReferencingThing} from '#composite/wiki-data';
-import {soupyReverse} from '#composite/wiki-properties';
-
-export default templateCompositeFrom({
-  annotation: `withFlashSide`,
-
-  outputs: ['#flashSide'],
-
-  steps: () => [
-    withUniqueReferencingThing({
-      reverse: soupyReverse.input('flashSidesWhoseActsInclude'),
-    }).outputs({
-      ['#uniqueReferencingThing']: '#flashSide',
-    }),
-  ],
-});
diff --git a/src/data/composite/things/flash/index.js b/src/data/composite/things/flash/index.js
deleted file mode 100644
index 63ac13da..00000000
--- a/src/data/composite/things/flash/index.js
+++ /dev/null
@@ -1 +0,0 @@
-export {default as withFlashAct} from './withFlashAct.js';
diff --git a/src/data/composite/things/flash/withFlashAct.js b/src/data/composite/things/flash/withFlashAct.js
deleted file mode 100644
index 87922aff..00000000
--- a/src/data/composite/things/flash/withFlashAct.js
+++ /dev/null
@@ -1,22 +0,0 @@
-// Gets the flash's act. This will early exit if flashActData is missing.
-// If there's no flash whose list of flashes includes this flash, the output
-// dependency will be null.
-
-import {templateCompositeFrom} from '#composite';
-
-import {withUniqueReferencingThing} from '#composite/wiki-data';
-import {soupyReverse} from '#composite/wiki-properties';
-
-export default templateCompositeFrom({
-  annotation: `withFlashAct`,
-
-  outputs: ['#flashAct'],
-
-  steps: () => [
-    withUniqueReferencingThing({
-      reverse: soupyReverse.input('flashActsWhoseFlashesInclude'),
-    }).outputs({
-      ['#uniqueReferencingThing']: '#flashAct',
-    }),
-  ],
-});
diff --git a/src/data/things/flash.js b/src/data/things/flash.js
index 73b22746..5c9023fa 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 {sortFlashesChronologically} from '#sort';
 import Thing from '#thing';
 import {anyOf, isColor, isContentString, isDirectory, isNumber, isString}
@@ -45,9 +44,6 @@ import {
   urls,
 } 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';
 
@@ -55,11 +51,16 @@ export class Flash extends Thing {
     AdditionalName,
     CommentaryEntry,
     CreditingSourcesEntry,
+    FlashAct,
     Track,
     WikiInfo,
   }) => ({
     // Update & expose
 
+    act: thing({
+      class: input.value(FlashAct),
+    }),
+
     name: name('Unnamed Flash'),
 
     directory: {
@@ -93,14 +94,12 @@ export class Flash extends Thing {
         validate: input.value(isColor),
       }),
 
-      withFlashAct(),
-
       withPropertyFromObject({
-        object: '#flashAct',
+        object: 'act',
         property: input.value('color'),
       }),
 
-      exposeDependency({dependency: '#flashAct.color'}),
+      exposeDependency({dependency: '#act.color'}),
     ],
 
     date: simpleDate(),
@@ -157,16 +156,9 @@ export class Flash extends Thing {
 
     commentatorArtists: commentatorArtists(),
 
-    act: [
-      withFlashAct(),
-      exposeDependency({dependency: '#flashAct'}),
-    ],
-
     side: [
-      withFlashAct(),
-
       withPropertyFromObject({
-        object: '#flashAct',
+        object: 'act',
         property: input.value('side'),
       }),
 
@@ -283,9 +275,13 @@ export class FlashAct extends Thing {
   static [Thing.referenceType] = 'flash-act';
   static [Thing.friendlyName] = `Flash Act`;
 
-  static [Thing.getPropertyDescriptors] = () => ({
+  static [Thing.getPropertyDescriptors] = ({Flash, FlashSide}) => ({
     // Update & expose
 
+    side: thing({
+      class: input.value(FlashSide),
+    }),
+
     name: name('Unnamed Flash Act'),
     directory: directory(),
     color: color(),
@@ -295,15 +291,13 @@ export class FlashAct extends Thing {
         validate: input.value(isContentString),
       }),
 
-      withFlashSide(),
-
       withPropertyFromObject({
-        object: '#flashSide',
+        object: 'side',
         property: input.value('listTerminology'),
       }),
 
       exposeDependencyOrContinue({
-        dependency: '#flashSide.listTerminology',
+        dependency: '#side.listTerminology',
       }),
 
       exposeConstant({
@@ -311,9 +305,8 @@ export class FlashAct extends Thing {
       }),
     ],
 
-    flashes: referenceList({
+    flashes: thingList({
       class: input.value(Flash),
-      find: soupyFind.input('flash'),
     }),
 
     // Update only
@@ -328,11 +321,6 @@ export class FlashAct extends Thing {
         value: input.value(true),
       }),
     ],
-
-    side: [
-      withFlashSide(),
-      exposeDependency({dependency: '#flashSide'}),
-    ],
   });
 
   static [Thing.findSpecs] = {
@@ -368,7 +356,7 @@ export class FlashSide extends Thing {
   static [Thing.referenceType] = 'flash-side';
   static [Thing.friendlyName] = `Flash Side`;
 
-  static [Thing.getPropertyDescriptors] = () => ({
+  static [Thing.getPropertyDescriptors] = ({FlashAct}) => ({
     // Update & expose
 
     name: name('Unnamed Flash Side'),
@@ -376,9 +364,8 @@ export class FlashSide extends Thing {
     color: color(),
     listTerminology: contentString(),
 
-    acts: referenceList({
+    acts: thingList({
       class: input.value(FlashAct),
-      find: soupyFind.input('flashAct'),
     }),
 
     // Update only
@@ -435,56 +422,82 @@ export class FlashSide extends Thing {
         : Flash),
 
     save(results) {
-      // JavaScript likes you.
+      const flashSideData = [];
+      const flashActData = [];
+      const flashData = [];
 
-      if (!empty(results) && !(results[0] instanceof FlashSide)) {
-        throw new Error(`Expected a side at top of flash data file`);
-      }
+      const artworkData = [];
+      const commentaryData = [];
+      const creditingSourceData = [];
 
-      let index = 0;
-      let thing;
-      for (; thing = results[index]; index++) {
-        const flashSide = thing;
-        const flashActRefs = [];
+      let thing, i;
 
-        if (results[index + 1] instanceof Flash) {
-          throw new Error(`Expected an act to immediately follow a side`);
-        }
+      for (i = 0; thing = results[i]; i++) {
+        if (thing.isFlashSide) {
+          const side = thing;
+          const acts = [];
+
+          for (i++; thing = results[i]; i++) {
+            if (thing.isFlashAct) {
+              const act = thing;
+              const flashes = [];
+
+              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));
+                  flashData.push(flash);
+                  artworkData.push(flash.coverArtwork);
+                  commentaryData.push(...flash.commentary);
+                  creditingSourceData.push(...flash.creditingSources);
+
+                  continue;
+                }
+
+                i--;
+                break;
+              }
+
+              act.side = side;
+              act.flashes = flashes;
+              acts.push(act);
+
+              flashActData.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));
+
+          side.acts = acts;
+
+          flashSideData.push(side);
+
+          continue;
         }
-        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);
+        if (thing.isFlashAct) {
+          throw new Error(`Acts must be under a side`);
+        }
 
-      const artworkData = flashData.map(flash => flash.coverArtwork);
-      const commentaryData = flashData.flatMap(flash => flash.commentary);
-      const creditingSourceData = flashData.flatMap(flash => flash.creditingSources);
+        if (thing.isFlash) {
+          throw new Error(`Flashes must be under a side and act`);
+        }
+      }
 
       return {
-        flashData,
-        flashActData,
         flashSideData,
+        flashActData,
+        flashData,
 
         artworkData,
         commentaryData,