« 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/composite/things/contribution
diff options
context:
space:
mode:
Diffstat (limited to 'src/data/composite/things/contribution')
-rw-r--r--src/data/composite/things/contribution/index.js4
-rw-r--r--src/data/composite/things/contribution/inheritFromContributionPresets.js19
-rw-r--r--src/data/composite/things/contribution/thingPropertyMatches.js33
-rw-r--r--src/data/composite/things/contribution/thingReferenceTypeMatches.js39
-rw-r--r--src/data/composite/things/contribution/withContainingReverseContributionList.js54
-rw-r--r--src/data/composite/things/contribution/withContributionArtist.js34
-rw-r--r--src/data/composite/things/contribution/withMatchingContributionPresets.js70
7 files changed, 49 insertions, 204 deletions
diff --git a/src/data/composite/things/contribution/index.js b/src/data/composite/things/contribution/index.js
index 9b22be2e..2bbf994d 100644
--- a/src/data/composite/things/contribution/index.js
+++ b/src/data/composite/things/contribution/index.js
@@ -1,7 +1,3 @@
 export {default as inheritFromContributionPresets} from './inheritFromContributionPresets.js';
-export {default as thingPropertyMatches} from './thingPropertyMatches.js';
-export {default as thingReferenceTypeMatches} from './thingReferenceTypeMatches.js';
 export {default as withContainingReverseContributionList} from './withContainingReverseContributionList.js';
-export {default as withContributionArtist} from './withContributionArtist.js';
 export {default as withContributionContext} from './withContributionContext.js';
-export {default as withMatchingContributionPresets} from './withMatchingContributionPresets.js';
diff --git a/src/data/composite/things/contribution/inheritFromContributionPresets.js b/src/data/composite/things/contribution/inheritFromContributionPresets.js
index 82425b9c..b429b3ef 100644
--- a/src/data/composite/things/contribution/inheritFromContributionPresets.js
+++ b/src/data/composite/things/contribution/inheritFromContributionPresets.js
@@ -1,31 +1,20 @@
 import {input, templateCompositeFrom} from '#composite';
 
 import {raiseOutputWithoutDependency} from '#composite/control-flow';
-import {withPropertyFromList, withPropertyFromObject} from '#composite/data';
-
-import withMatchingContributionPresets
-  from './withMatchingContributionPresets.js';
+import {withPropertyFromList} from '#composite/data';
 
 export default templateCompositeFrom({
   annotation: `inheritFromContributionPresets`,
 
-  inputs: {
-    property: input({type: 'string'}),
-  },
-
   steps: () => [
-    withMatchingContributionPresets().outputs({
-      '#matchingContributionPresets': '#presets',
-    }),
-
     raiseOutputWithoutDependency({
-      dependency: '#presets',
+      dependency: 'matchingContributionPresets',
       mode: input.value('empty'),
     }),
 
     withPropertyFromList({
-      list: '#presets',
-      property: input('property'),
+      list: 'matchingContributionPresets',
+      property: input.thisProperty(),
     }),
 
     {
diff --git a/src/data/composite/things/contribution/thingPropertyMatches.js b/src/data/composite/things/contribution/thingPropertyMatches.js
deleted file mode 100644
index 4a37f2cf..00000000
--- a/src/data/composite/things/contribution/thingPropertyMatches.js
+++ /dev/null
@@ -1,33 +0,0 @@
-import {input, templateCompositeFrom} from '#composite';
-
-import {exitWithoutDependency} from '#composite/control-flow';
-
-export default templateCompositeFrom({
-  annotation: `thingPropertyMatches`,
-
-  compose: false,
-
-  inputs: {
-    value: input({type: 'string'}),
-  },
-
-  steps: () => [
-    exitWithoutDependency({
-      dependency: 'thingProperty',
-      value: input.value(false),
-    }),
-
-    {
-      dependencies: [
-        'thingProperty',
-        input('value'),
-      ],
-
-      compute: ({
-        ['thingProperty']: thingProperty,
-        [input('value')]: value,
-      }) =>
-        thingProperty === value,
-    },
-  ],
-});
diff --git a/src/data/composite/things/contribution/thingReferenceTypeMatches.js b/src/data/composite/things/contribution/thingReferenceTypeMatches.js
deleted file mode 100644
index 2ee811af..00000000
--- a/src/data/composite/things/contribution/thingReferenceTypeMatches.js
+++ /dev/null
@@ -1,39 +0,0 @@
-import {input, templateCompositeFrom} from '#composite';
-
-import {exitWithoutDependency} from '#composite/control-flow';
-import {withPropertyFromObject} from '#composite/data';
-
-export default templateCompositeFrom({
-  annotation: `thingReferenceTypeMatches`,
-
-  compose: false,
-
-  inputs: {
-    value: input({type: 'string'}),
-  },
-
-  steps: () => [
-    exitWithoutDependency({
-      dependency: 'thing',
-      value: input.value(false),
-    }),
-
-    withPropertyFromObject({
-      object: 'thing',
-      property: input.value('constructor'),
-    }),
-
-    {
-      dependencies: [
-        '#thing.constructor',
-        input('value'),
-      ],
-
-      compute: ({
-        ['#thing.constructor']: constructor,
-        [input('value')]: value,
-      }) =>
-        constructor[Symbol.for('Thing.referenceType')] === value,
-    },
-  ],
-});
diff --git a/src/data/composite/things/contribution/withContainingReverseContributionList.js b/src/data/composite/things/contribution/withContainingReverseContributionList.js
index 56704c8b..a9ba31c9 100644
--- a/src/data/composite/things/contribution/withContainingReverseContributionList.js
+++ b/src/data/composite/things/contribution/withContainingReverseContributionList.js
@@ -1,18 +1,20 @@
-// Get the artist's contribution list containing this property.
+// Get the artist's contribution list containing this property. Although that
+// list literally includes both dated and dateless contributions, here, if the
+// current contribution is dateless, the list is filtered to only include
+// dateless contributions from the same immediately nearby context.
 
 import {input, templateCompositeFrom} from '#composite';
 
-import {raiseOutputWithoutDependency} from '#composite/control-flow';
+import {raiseOutputWithoutDependency, withResultOfAvailabilityCheck}
+  from '#composite/control-flow';
 import {withPropertyFromObject} from '#composite/data';
 
-import withContributionArtist from './withContributionArtist.js';
-
 export default templateCompositeFrom({
   annotation: `withContainingReverseContributionList`,
 
   inputs: {
     artistProperty: input({
-      defaultDependency: 'artistProperty',
+      defaultDependency: '_artistProperty',
       acceptsNull: true,
     }),
   },
@@ -28,13 +30,47 @@ export default templateCompositeFrom({
       }),
     }),
 
-    withContributionArtist(),
-
     withPropertyFromObject({
-      object: '#artist',
+      object: 'artist',
       property: input('artistProperty'),
     }).outputs({
-      ['#value']: '#containingReverseContributionList',
+      ['#value']: '#list',
+    }),
+
+    withResultOfAvailabilityCheck({
+      from: 'date',
+    }).outputs({
+      ['#availability']: '#hasDate',
     }),
+
+    {
+      dependencies: ['#hasDate', '#list'],
+      compute: (continuation, {
+        ['#hasDate']: hasDate,
+        ['#list']: list,
+      }) =>
+        (hasDate
+          ? continuation.raiseOutput({
+              ['#containingReverseContributionList']:
+                list.filter(contrib => contrib.date),
+            })
+          : continuation({
+              ['#list']:
+                list.filter(contrib => !contrib.date),
+            })),
+    },
+
+    {
+      dependencies: ['#list', 'thing'],
+      compute: (continuation, {
+        ['#list']: list,
+        ['thing']: thing,
+      }) => continuation({
+        ['#containingReverseContributionList']:
+          (thing.album
+            ? list.filter(contrib => contrib.thing.album === thing.album)
+            : list),
+      }),
+    },
   ],
 });
diff --git a/src/data/composite/things/contribution/withContributionArtist.js b/src/data/composite/things/contribution/withContributionArtist.js
deleted file mode 100644
index 5a611c1a..00000000
--- a/src/data/composite/things/contribution/withContributionArtist.js
+++ /dev/null
@@ -1,34 +0,0 @@
-import {input, templateCompositeFrom} from '#composite';
-import find from '#find';
-
-import {withPropertyFromObject} from '#composite/data';
-import {withResolvedReference} from '#composite/wiki-data';
-
-export default templateCompositeFrom({
-  annotation: `withContributionArtist`,
-
-  inputs: {
-    ref: input({
-      type: 'string',
-      defaultDependency: 'artist',
-    }),
-  },
-
-  outputs: ['#artist'],
-
-  steps: () => [
-    withPropertyFromObject({
-      object: 'thing',
-      property: input.value('artistData'),
-      internal: input.value(true),
-    }),
-
-    withResolvedReference({
-      ref: input('ref'),
-      data: '#thing.artistData',
-      find: input.value(find.artist),
-    }).outputs({
-      '#resolvedReference': '#artist',
-    }),
-  ],
-});
diff --git a/src/data/composite/things/contribution/withMatchingContributionPresets.js b/src/data/composite/things/contribution/withMatchingContributionPresets.js
deleted file mode 100644
index 09454164..00000000
--- a/src/data/composite/things/contribution/withMatchingContributionPresets.js
+++ /dev/null
@@ -1,70 +0,0 @@
-import {input, templateCompositeFrom} from '#composite';
-
-import {raiseOutputWithoutDependency} from '#composite/control-flow';
-import {withPropertyFromObject} from '#composite/data';
-
-import withContributionContext from './withContributionContext.js';
-
-export default templateCompositeFrom({
-  annotation: `withMatchingContributionPresets`,
-
-  outputs: ['#matchingContributionPresets'],
-
-  steps: () => [
-    withPropertyFromObject({
-      object: 'thing',
-      property: input.value('wikiInfo'),
-      internal: input.value(true),
-    }),
-
-    raiseOutputWithoutDependency({
-      dependency: '#thing.wikiInfo',
-      output: input.value({
-        '#matchingContributionPresets': null,
-      }),
-    }),
-
-    withPropertyFromObject({
-      object: '#thing.wikiInfo',
-      property: input.value('contributionPresets'),
-    }).outputs({
-      '#thing.wikiInfo.contributionPresets': '#contributionPresets',
-    }),
-
-    raiseOutputWithoutDependency({
-      dependency: '#contributionPresets',
-      mode: input.value('empty'),
-      output: input.value({
-        '#matchingContributionPresets': [],
-      }),
-    }),
-
-    withContributionContext(),
-
-    {
-      dependencies: [
-        '#contributionPresets',
-        '#contributionTarget',
-        '#contributionProperty',
-        'annotation',
-      ],
-
-      compute: (continuation, {
-        ['#contributionPresets']: presets,
-        ['#contributionTarget']: target,
-        ['#contributionProperty']: property,
-        ['annotation']: annotation,
-      }) => continuation({
-        ['#matchingContributionPresets']:
-          presets
-            .filter(preset =>
-              preset.context[0] === target &&
-              preset.context.slice(1).includes(property) &&
-              // For now, only match if the annotation is a complete match.
-              // Partial matches (e.g. because the contribution includes "two"
-              // annotations, separated by commas) don't count.
-              preset.annotation === annotation),
-      })
-    },
-  ],
-});