diff options
Diffstat (limited to 'src/data/composite')
4 files changed, 27 insertions, 157 deletions
diff --git a/src/data/composite/things/flash/withFlashAct.js b/src/data/composite/things/flash/withFlashAct.js index ada2dcfe..2c985fe0 100644 --- a/src/data/composite/things/flash/withFlashAct.js +++ b/src/data/composite/things/flash/withFlashAct.js @@ -1,60 +1,27 @@ // Gets the flash's act. This will early exit if flashActData is missing. -// By default, if there's no flash whose list of flashes includes this flash, -// the output dependency will be null; set {notFoundMode: 'exit'} to early -// exit instead. +// If there's no flash whose list of flashes includes this flash, the output +// dependency will be null. // // This step models with Flash.withAlbum. import {input, templateCompositeFrom} from '#composite'; import {is} from '#validators'; -import {exitWithoutDependency, withResultOfAvailabilityCheck} +import {exitWithoutDependency, raiseOutputWithoutDependency} from '#composite/control-flow'; import {withPropertyFromList} from '#composite/data'; export default templateCompositeFrom({ annotation: `withFlashAct`, - inputs: { - notFoundMode: input({ - validate: is('exit', 'null'), - defaultValue: 'null', - }), - }, - outputs: ['#flashAct'], steps: () => [ - // null flashActData is always an early exit. - exitWithoutDependency({ dependency: 'flashActData', mode: input.value('null'), }), - // empty flashActData conditionally exits early or outputs null. - - withResultOfAvailabilityCheck({ - from: 'flashActData', - mode: input.value('empty'), - }).outputs({ - '#availability': '#flashActDataAvailability', - }), - - { - dependencies: [input('notFoundMode'), '#flashActDataAvailability'], - compute(continuation, { - [input('notFoundMode')]: notFoundMode, - ['#flashActDataAvailability']: flashActDataIsAvailable, - }) { - if (flashActDataIsAvailable) return continuation(); - switch (notFoundMode) { - case 'exit': return continuation.exit(null); - case 'null': return continuation.raiseOutput({'#flashAct': null}); - } - }, - }, - withPropertyFromList({ list: 'flashActData', property: input.value('flashes'), @@ -71,30 +38,13 @@ export default templateCompositeFrom({ }), }, - // album not found conditionally exits or outputs null. - - withResultOfAvailabilityCheck({ - from: '#flashActIndex', + raiseOutputWithoutDependency({ + dependency: '#flashActIndex', mode: input.value('index'), - }).outputs({ - '#availability': '#flashActAvailability', + output: input.value({'#album': null}), }), { - dependencies: [input('notFoundMode'), '#flashActAvailability'], - compute(continuation, { - [input('notFoundMode')]: notFoundMode, - ['#flashActAvailability']: flashActIsAvailable, - }) { - if (flashActIsAvailable) return continuation(); - switch (notFoundMode) { - case 'exit': return continuation.exit(null); - case 'null': return continuation.raiseOutput({'#flashAct': null}); - } - }, - }, - - { dependencies: ['flashActData', '#flashActIndex'], compute: (continuation, { ['flashActData']: flashActData, diff --git a/src/data/composite/things/track/withAlbum.js b/src/data/composite/things/track/withAlbum.js index cbd16dcd..143e0971 100644 --- a/src/data/composite/things/track/withAlbum.js +++ b/src/data/composite/things/track/withAlbum.js @@ -1,60 +1,27 @@ // Gets the track's album. This will early exit if albumData is missing. -// By default, if there's no album whose list of tracks includes this track, -// the output dependency will be null; set {notFoundMode: 'exit'} to early -// exit instead. +// If there's no album whose list of tracks includes this track, the output +// dependency will be null. // // This step models with Flash.withFlashAct. import {input, templateCompositeFrom} from '#composite'; import {is} from '#validators'; -import {exitWithoutDependency, withResultOfAvailabilityCheck} +import {exitWithoutDependency, raiseOutputWithoutDependency} from '#composite/control-flow'; import {withPropertyFromList} from '#composite/data'; export default templateCompositeFrom({ annotation: `withAlbum`, - inputs: { - notFoundMode: input({ - validate: is('exit', 'null'), - defaultValue: 'null', - }), - }, - outputs: ['#album'], steps: () => [ - // null albumData is always an early exit. - exitWithoutDependency({ dependency: 'albumData', mode: input.value('null'), }), - // empty albumData conditionally exits early or outputs null. - - withResultOfAvailabilityCheck({ - from: 'albumData', - mode: input.value('empty'), - }).outputs({ - '#availability': '#albumDataAvailability', - }), - - { - dependencies: [input('notFoundMode'), '#albumDataAvailability'], - compute(continuation, { - [input('notFoundMode')]: notFoundMode, - ['#albumDataAvailability']: albumDataIsAvailable, - }) { - if (albumDataIsAvailable) return continuation(); - switch (notFoundMode) { - case 'exit': return continuation.exit(null); - case 'null': return continuation.raiseOutput({'#album': null}); - } - }, - }, - withPropertyFromList({ list: 'albumData', property: input.value('tracks'), @@ -71,30 +38,13 @@ export default templateCompositeFrom({ }), }, - // album not found conditionally exits or outputs null. - - withResultOfAvailabilityCheck({ - from: '#albumIndex', + raiseOutputWithoutDependency({ + dependency: '#albumIndex', mode: input.value('index'), - }).outputs({ - '#availability': '#albumAvailability', + output: input.value({'#album': null}), }), { - dependencies: [input('notFoundMode'), '#albumAvailability'], - compute(continuation, { - [input('notFoundMode')]: notFoundMode, - ['#albumAvailability']: albumIsAvailable, - }) { - if (albumIsAvailable) return continuation(); - switch (notFoundMode) { - case 'exit': return continuation.exit(null); - case 'null': return continuation.raiseOutput({'#album': null}); - } - }, - }, - - { dependencies: ['albumData', '#albumIndex'], compute: (continuation, { ['albumData']: albumData, diff --git a/src/data/composite/things/track/withContainingTrackSection.js b/src/data/composite/things/track/withContainingTrackSection.js index b2e5f2b3..eaac14de 100644 --- a/src/data/composite/things/track/withContainingTrackSection.js +++ b/src/data/composite/things/track/withContainingTrackSection.js @@ -1,63 +1,42 @@ // Gets the track section containing this track from its album's track list. -// If notFoundMode is set to 'exit', this will early exit if the album can't be -// found or if none of its trackSections includes the track for some reason. import {input, templateCompositeFrom} from '#composite'; import {is} from '#validators'; +import {raiseOutputWithoutDependency} from '#composite/control-flow'; + import withPropertyFromAlbum from './withPropertyFromAlbum.js'; export default templateCompositeFrom({ annotation: `withContainingTrackSection`, - inputs: { - notFoundMode: input({ - validate: is('exit', 'null'), - defaultValue: 'null', - }), - }, - outputs: ['#trackSection'], steps: () => [ withPropertyFromAlbum({ property: input.value('trackSections'), - notFoundMode: input('notFoundMode'), + }), + + raiseOutputWithoutDependency({ + dependency: '#album.trackSections', + output: input.value({'#trackSection': null}), }), { dependencies: [ input.myself(), - input('notFoundMode'), '#album.trackSections', ], - compute(continuation, { + compute: (continuation, { [input.myself()]: track, [input('notFoundMode')]: notFoundMode, ['#album.trackSections']: trackSections, - }) { - if (!trackSections) { - return continuation.raiseOutput({ - ['#trackSection']: null, - }); - } - - const trackSection = - trackSections.find(({tracks}) => tracks.includes(track)); - - if (trackSection) { - return continuation.raiseOutput({ - ['#trackSection']: trackSection, - }); - } else if (notFoundMode === 'exit') { - return continuation.exit(null); - } else { - return continuation.raiseOutput({ - ['#trackSection']: null, - }); - } - }, + }) => continuation({ + ['#trackSection']: + trackSections.find(({tracks}) => tracks.includes(track)) + ?? null, + }), }, ], }); diff --git a/src/data/composite/things/track/withPropertyFromAlbum.js b/src/data/composite/things/track/withPropertyFromAlbum.js index b236a6e8..d41390fa 100644 --- a/src/data/composite/things/track/withPropertyFromAlbum.js +++ b/src/data/composite/things/track/withPropertyFromAlbum.js @@ -1,7 +1,5 @@ // Gets a single property from this track's album, providing it as the same -// property name prefixed with '#album.' (by default). If the track's album -// isn't available, then by default, the property will be provided as null; -// set {notFoundMode: 'exit'} to early exit instead. +// property name prefixed with '#album.' (by default). import {input, templateCompositeFrom} from '#composite'; import {is} from '#validators'; @@ -15,11 +13,6 @@ export default templateCompositeFrom({ inputs: { property: input.staticValue({type: 'string'}), - - notFoundMode: input({ - validate: is('exit', 'null'), - defaultValue: 'null', - }), }, outputs: ({ @@ -27,9 +20,7 @@ export default templateCompositeFrom({ }) => ['#album.' + property], steps: () => [ - withAlbum({ - notFoundMode: input('notFoundMode'), - }), + withAlbum(), withPropertyFromObject({ object: '#album', |