« 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.js20
1 files changed, 14 insertions, 6 deletions
diff --git a/src/data/things/flash.js b/src/data/things/flash.js
index dc6a32df..d0aef04a 100644
--- a/src/data/things/flash.js
+++ b/src/data/things/flash.js
@@ -2,6 +2,7 @@ export const FLASH_DATA_FILE = 'flashes.yaml';
 
 import {input} from '#composite';
 import find from '#find';
+import {empty} from '#sugar';
 import {sortFlashesChronologically} from '#sort';
 import Thing from '#thing';
 import {anyOf, isColor, isContentString, isDirectory, isNumber, isString}
@@ -308,15 +309,22 @@ export class FlashSide extends Thing {
         : Flash),
 
     save(results) {
-      let thing;
-      for (let index = 0; thing = results[index]; index++) {
-        if (index === 0 && !(thing instanceof FlashSide)) {
-          throw new Error(`Expected a side at top of flash data file`);
-        }
+      // JavaScript likes you.
+
+      if (!empty(results) && !(results[0] instanceof FlashSide)) {
+        throw new Error(`Expected a side at top of flash data file`);
+      }
 
-        // JavaScript likes you.
+      let index = 0;
+      let thing;
+      for (; thing = results[index]; index++) {
         const flashSide = thing;
         const flashActRefs = [];
+
+        if (results[index + 1] instanceof Flash) {
+          throw new Error(`Expected an act to immediately follow a side`);
+        }
+
         for (
           index++;
           (thing = results[index]) && thing instanceof FlashAct;