« get me outta code hell

data: stub reverseContributionList - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/data/composite/wiki-data
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2024-01-17 13:58:47 -0400
committer(quasar) nebula <qznebula@protonmail.com>2024-01-17 15:35:33 -0400
commit301ed2a12f4716a85359b6cb50462e415539553f (patch)
tree22e7d1532464de4ebe69ffb35476c4dc7f0fa425 /src/data/composite/wiki-data
parent6e5f9a1e246640ddfa8472cf3dcb02baf9603c75 (diff)
data: stub reverseContributionList
Diffstat (limited to 'src/data/composite/wiki-data')
-rw-r--r--src/data/composite/wiki-data/index.js1
-rw-r--r--src/data/composite/wiki-data/withReverseContributionList.js45
2 files changed, 46 insertions, 0 deletions
diff --git a/src/data/composite/wiki-data/index.js b/src/data/composite/wiki-data/index.js
index a2ff09d8..d64930e1 100644
--- a/src/data/composite/wiki-data/index.js
+++ b/src/data/composite/wiki-data/index.js
@@ -11,5 +11,6 @@ export {default as withParsedCommentaryEntries} from './withParsedCommentaryEntr
 export {default as withResolvedContribs} from './withResolvedContribs.js';
 export {default as withResolvedReference} from './withResolvedReference.js';
 export {default as withResolvedReferenceList} from './withResolvedReferenceList.js';
+export {default as withReverseContributionList} from './withReverseContributionList.js';
 export {default as withReverseReferenceList} from './withReverseReferenceList.js';
 export {default as withThingsSortedAlphabetically} from './withThingsSortedAlphabetically.js';
diff --git a/src/data/composite/wiki-data/withReverseContributionList.js b/src/data/composite/wiki-data/withReverseContributionList.js
new file mode 100644
index 00000000..71e3c1a8
--- /dev/null
+++ b/src/data/composite/wiki-data/withReverseContributionList.js
@@ -0,0 +1,45 @@
+// Analogous implementation for withReverseReferenceList, but contributions.
+//
+// This implementation uses a global cache (via WeakMap) to attempt to speed
+// up subsequent similar accesses. Reverse contribution lists are the most
+// costly in live-dev-server, but we intend to expand the impelemntation here
+// to reverse reference lists in general later on.
+
+import {input, templateCompositeFrom} from '#composite';
+
+import {exitWithoutDependency} from '#composite/control-flow';
+
+import inputWikiData from './inputWikiData.js';
+
+export default templateCompositeFrom({
+  annotation: `withReverseContributionList`,
+
+  inputs: {
+    data: inputWikiData({allowMixedTypes: false}),
+    list: input({type: 'string'}),
+  },
+
+  outputs: ['#reverseContributionList'],
+
+  steps: () => [
+    exitWithoutDependency({
+      dependency: input('data'),
+      value: input.value([]),
+      mode: input.value('empty'),
+    }),
+
+    {
+      dependencies: [input.myself(), input('data'), input('list')],
+
+      compute: (continuation, {
+        [input.myself()]: myself,
+        [input('data')]: data,
+        [input('list')]: list,
+      }) =>
+        continuation({
+          ['#reverseContributionList']:
+            data.filter(thing => thing[list].some(({who}) => who === myself)),
+        }),
+    },
+  ],
+});