From 6ac3a98cb60651b82d2f93a3ced0e56162ea4be7 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Sun, 3 Nov 2024 09:52:22 -0400 Subject: data: withDirectoryFromName: move to helpers Also remove the more-composable default behavior of using the current thing's name, because this is no longer meant to be composed generally. --- .../wiki-data/helpers/withDirectoryFromName.js | 41 +++++++++++++++++++++ src/data/composite/wiki-data/index.js | 1 - src/data/composite/wiki-data/withDirectory.js | 2 +- .../composite/wiki-data/withDirectoryFromName.js | 42 ---------------------- 4 files changed, 42 insertions(+), 44 deletions(-) create mode 100644 src/data/composite/wiki-data/helpers/withDirectoryFromName.js delete mode 100644 src/data/composite/wiki-data/withDirectoryFromName.js (limited to 'src/data/composite') diff --git a/src/data/composite/wiki-data/helpers/withDirectoryFromName.js b/src/data/composite/wiki-data/helpers/withDirectoryFromName.js new file mode 100644 index 00000000..f85dae16 --- /dev/null +++ b/src/data/composite/wiki-data/helpers/withDirectoryFromName.js @@ -0,0 +1,41 @@ +// Compute a directory from a name. + +import {input, templateCompositeFrom} from '#composite'; + +import {isName} from '#validators'; +import {getKebabCase} from '#wiki-data'; + +import {raiseOutputWithoutDependency} from '#composite/control-flow'; + +export default templateCompositeFrom({ + annotation: `withDirectoryFromName`, + + inputs: { + name: input({ + validate: isName, + acceptsNull: true, + }), + }, + + outputs: ['#directory'], + + steps: () => [ + raiseOutputWithoutDependency({ + dependency: input('name'), + mode: input.value('falsy'), + output: input.value({ + ['#directory']: null, + }), + }), + + { + dependencies: [input('name')], + compute: (continuation, { + [input('name')]: name, + }) => continuation({ + ['#directory']: + getKebabCase(name), + }), + }, + ], +}); diff --git a/src/data/composite/wiki-data/index.js b/src/data/composite/wiki-data/index.js index 451aa266..f99a1a14 100644 --- a/src/data/composite/wiki-data/index.js +++ b/src/data/composite/wiki-data/index.js @@ -10,7 +10,6 @@ export {default as withClonedThings} from './withClonedThings.js'; export {default as withContributionListSums} from './withContributionListSums.js'; export {default as withCoverArtDate} from './withCoverArtDate.js'; export {default as withDirectory} from './withDirectory.js'; -export {default as withDirectoryFromName} from './withDirectoryFromName.js'; export {default as withParsedCommentaryEntries} from './withParsedCommentaryEntries.js'; export {default as withRecontextualizedContributionList} from './withRecontextualizedContributionList.js'; export {default as withRedatedContributionList} from './withRedatedContributionList.js'; diff --git a/src/data/composite/wiki-data/withDirectory.js b/src/data/composite/wiki-data/withDirectory.js index b08b6153..a3f4ceda 100644 --- a/src/data/composite/wiki-data/withDirectory.js +++ b/src/data/composite/wiki-data/withDirectory.js @@ -9,7 +9,7 @@ import {isDirectory, isName} from '#validators'; import {withResultOfAvailabilityCheck} from '#composite/control-flow'; -import withDirectoryFromName from './withDirectoryFromName.js'; +import withDirectoryFromName from './helpers/withDirectoryFromName.js'; export default templateCompositeFrom({ annotation: `withDirectory`, diff --git a/src/data/composite/wiki-data/withDirectoryFromName.js b/src/data/composite/wiki-data/withDirectoryFromName.js deleted file mode 100644 index 034464e4..00000000 --- a/src/data/composite/wiki-data/withDirectoryFromName.js +++ /dev/null @@ -1,42 +0,0 @@ -// Compute a directory from a name - by default the current thing's own name. - -import {input, templateCompositeFrom} from '#composite'; - -import {isName} from '#validators'; -import {getKebabCase} from '#wiki-data'; - -import {raiseOutputWithoutDependency} from '#composite/control-flow'; - -export default templateCompositeFrom({ - annotation: `withDirectoryFromName`, - - inputs: { - name: input({ - validate: isName, - defaultDependency: 'name', - acceptsNull: true, - }), - }, - - outputs: ['#directory'], - - steps: () => [ - raiseOutputWithoutDependency({ - dependency: input('name'), - mode: input.value('falsy'), - output: input.value({ - ['#directory']: null, - }), - }), - - { - dependencies: [input('name')], - compute: (continuation, { - [input('name')]: name, - }) => continuation({ - ['#directory']: - getKebabCase(name), - }), - }, - ], -}); -- cgit 1.3.0-6-gf8a5