diff options
Diffstat (limited to 'src/data')
-rw-r--r-- | src/data/composite/things/track/withOriginalRelease.js | 45 | ||||
-rw-r--r-- | src/data/composite/wiki-data/withResolvedReference.js | 32 |
2 files changed, 39 insertions, 38 deletions
diff --git a/src/data/composite/things/track/withOriginalRelease.js b/src/data/composite/things/track/withOriginalRelease.js index d2ee39df..6e30a0a0 100644 --- a/src/data/composite/things/track/withOriginalRelease.js +++ b/src/data/composite/things/track/withOriginalRelease.js @@ -9,6 +9,8 @@ import {input, templateCompositeFrom} from '#composite'; import find from '#find'; import {validateWikiData} from '#validators'; +import {exitWithoutDependency, withResultOfAvailabilityCheck} + from '#composite/control-flow'; import {withResolvedReference} from '#composite/wiki-data'; export default templateCompositeFrom({ @@ -26,33 +28,48 @@ export default templateCompositeFrom({ outputs: ['#originalRelease'], steps: () => [ - withResolvedReference({ - ref: 'originalReleaseTrack', - data: input('data'), - find: input.value(find.track), - notFoundMode: input.value('exit'), - }).outputs({ - ['#resolvedReference']: '#originalRelease', + withResultOfAvailabilityCheck({ + from: 'originalReleaseTrack', }), { dependencies: [ input.myself(), input('selfIfOriginal'), - '#originalRelease', + '#availability', ], compute: (continuation, { [input.myself()]: track, [input('selfIfOriginal')]: selfIfOriginal, - ['#originalRelease']: originalRelease, + '#availability': availability, + }) => + (availability + ? continuation() + : continuation.raiseOutput({ + ['#originalRelease']: + (selfIfOriginal ? track : null), + })), + }, + + withResolvedReference({ + ref: 'originalReleaseTrack', + data: input('data'), + find: input.value(find.track), + }), + + exitWithoutDependency({ + dependency: '#resolvedReference', + }), + + { + dependencies: ['#resolvedReference'], + + compute: (continuation, { + ['#resolvedReference']: resolvedReference, }) => continuation({ - ['#originalRelease']: - (originalRelease ?? - (selfIfOriginal - ? track - : null)), + ['#originalRelease']: resolvedReference, }), }, ], diff --git a/src/data/composite/wiki-data/withResolvedReference.js b/src/data/composite/wiki-data/withResolvedReference.js index 0fa5c554..ea71707e 100644 --- a/src/data/composite/wiki-data/withResolvedReference.js +++ b/src/data/composite/wiki-data/withResolvedReference.js @@ -1,12 +1,10 @@ // Resolves a reference by using the provided find function to match it // within the provided thingData dependency. This will early exit if the -// data dependency is null, or, if notFoundMode is set to 'exit', if the find -// function doesn't match anything for the reference. Otherwise, the data -// object is provided on the output dependency; or null, if the reference -// doesn't match anything or itself was null to begin with. +// data dependency is null. Otherwise, the data object is provided on the +// output dependency, or null, if the reference doesn't match anything or +// itself was null to begin with. import {input, templateCompositeFrom} from '#composite'; -import {is} from '#validators'; import { exitWithoutDependency, @@ -23,11 +21,6 @@ export default templateCompositeFrom({ data: inputWikiData({allowMixedTypes: false}), find: input({type: 'function'}), - - notFoundMode: input({ - validate: is('null', 'exit'), - defaultValue: 'null', - }), }, outputs: ['#resolvedReference'], @@ -49,25 +42,16 @@ export default templateCompositeFrom({ input('ref'), input('data'), input('find'), - input('notFoundMode'), ], - compute(continuation, { + compute: (continuation, { [input('ref')]: ref, [input('data')]: data, [input('find')]: findFunction, - [input('notFoundMode')]: notFoundMode, - }) { - const match = findFunction(ref, data, {mode: 'quiet'}); - - if (match === null && notFoundMode === 'exit') { - return continuation.exit(null); - } - - return continuation.raiseOutput({ - ['#resolvedReference']: match ?? null, - }); - }, + }) => continuation({ + ['#resolvedReference']: + findFunction(ref, data, {mode: 'quiet'}) ?? null, + }), }, ], }); |