« get me outta code hell

data: withReverse{Reference,Contribution}List: better exiting - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2024-04-24 17:08:45 -0300
committer(quasar) nebula <qznebula@protonmail.com>2024-04-24 17:13:24 -0300
commit079b2bb3ed1561b1953139a03a31b37c9da868c4 (patch)
tree8f538f293200e4b5aaa3df4b6c52fb8096273dd0 /src
parentdd03642fc38be775b8f79940334f4e4ba2343638 (diff)
data: withReverse{Reference,Contribution}List: better exiting
An existing test for withAlbum (which is semi-newly based on
withUniqueReferencingThing, and thus withReverseReferenceList)
indicates that if we just can't *find* the album in a provided
data array, that's not an exit condition. This commit adapts
withReverseReferencingList to respect that when the data list
is empty.

(Treating an empty array as the same thing as an array that
 isn't provided at all - the existing behavior - is really just
 a bug!)
Diffstat (limited to 'src')
-rw-r--r--src/data/composite/wiki-data/withReverseContributionList.js10
-rw-r--r--src/data/composite/wiki-data/withReverseReferenceList.js10
-rw-r--r--src/data/composite/wiki-data/withUniqueReferencingThing.js5
3 files changed, 20 insertions, 5 deletions
diff --git a/src/data/composite/wiki-data/withReverseContributionList.js b/src/data/composite/wiki-data/withReverseContributionList.js
index c5dcad07..91e125e4 100644
--- a/src/data/composite/wiki-data/withReverseContributionList.js
+++ b/src/data/composite/wiki-data/withReverseContributionList.js
@@ -11,7 +11,8 @@
 
 import {input, templateCompositeFrom} from '#composite';
 
-import {exitWithoutDependency} from '#composite/control-flow';
+import {exitWithoutDependency, raiseOutputWithoutDependency}
+  from '#composite/control-flow';
 
 import inputWikiData from './inputWikiData.js';
 
@@ -32,10 +33,17 @@ export default templateCompositeFrom({
   outputs: ['#reverseContributionList'],
 
   steps: () => [
+    // Early exit with an empty array if the data list isn't available.
     exitWithoutDependency({
       dependency: input('data'),
       value: input.value([]),
+    }),
+
+    // Raise an empty array (don't early exit) if the data list is empty.
+    raiseOutputWithoutDependency({
+      dependency: input('data'),
       mode: input.value('empty'),
+      output: input.value({'#reverseContributionList': []}),
     }),
 
     {
diff --git a/src/data/composite/wiki-data/withReverseReferenceList.js b/src/data/composite/wiki-data/withReverseReferenceList.js
index 2d7a421b..8cd540a5 100644
--- a/src/data/composite/wiki-data/withReverseReferenceList.js
+++ b/src/data/composite/wiki-data/withReverseReferenceList.js
@@ -13,7 +13,8 @@
 
 import {input, templateCompositeFrom} from '#composite';
 
-import {exitWithoutDependency} from '#composite/control-flow';
+import {exitWithoutDependency, raiseOutputWithoutDependency}
+  from '#composite/control-flow';
 
 import inputWikiData from './inputWikiData.js';
 
@@ -34,10 +35,17 @@ export default templateCompositeFrom({
   outputs: ['#reverseReferenceList'],
 
   steps: () => [
+    // Early exit with an empty array if the data list isn't available.
     exitWithoutDependency({
       dependency: input('data'),
       value: input.value([]),
+    }),
+
+    // Raise an empty array (don't early exit) if the data list is empty.
+    raiseOutputWithoutDependency({
+      dependency: input('data'),
       mode: input.value('empty'),
+      output: input.value({'#reverseReferenceList': []}),
     }),
 
     {
diff --git a/src/data/composite/wiki-data/withUniqueReferencingThing.js b/src/data/composite/wiki-data/withUniqueReferencingThing.js
index ce04f838..61c10618 100644
--- a/src/data/composite/wiki-data/withUniqueReferencingThing.js
+++ b/src/data/composite/wiki-data/withUniqueReferencingThing.js
@@ -21,11 +21,10 @@ export default templateCompositeFrom({
   outputs: ['#uniqueReferencingThing'],
 
   steps: () => [
-    // withReverseRefernceList does this check too, but it early exits with
-    // an empty array. That's no good here!
+    // Early exit with null (not an empty array) if the data list
+    // isn't available.
     exitWithoutDependency({
       dependency: input('data'),
-      mode: input.value('empty'),
     }),
 
     withReverseReferenceList({