diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2024-11-16 13:27:30 -0400 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2024-11-17 13:40:00 -0400 |
commit | f2464c6031d83108d12b08df83af2b2f8e426002 (patch) | |
tree | 321e1e3d36df90cb1dc4a91f7fabef182db6e6c9 /src/data/composite/control-flow | |
parent | 6df70e89d2cbfb0790e7d2b6e181bfebd29cb929 (diff) |
data: withAvailabilityFilter
Diffstat (limited to 'src/data/composite/control-flow')
-rw-r--r-- | src/data/composite/control-flow/index.js | 1 | ||||
-rw-r--r-- | src/data/composite/control-flow/withAvailabilityFilter.js | 40 | ||||
-rw-r--r-- | src/data/composite/control-flow/withResultOfAvailabilityCheck.js | 1 |
3 files changed, 42 insertions, 0 deletions
diff --git a/src/data/composite/control-flow/index.js b/src/data/composite/control-flow/index.js index 6148d465..7e137a14 100644 --- a/src/data/composite/control-flow/index.js +++ b/src/data/composite/control-flow/index.js @@ -12,4 +12,5 @@ export {default as exposeUpdateValueOrContinue} from './exposeUpdateValueOrConti export {default as exposeWhetherDependencyAvailable} from './exposeWhetherDependencyAvailable.js'; export {default as raiseOutputWithoutDependency} from './raiseOutputWithoutDependency.js'; export {default as raiseOutputWithoutUpdateValue} from './raiseOutputWithoutUpdateValue.js'; +export {default as withAvailabilityFilter} from './withAvailabilityFilter.js'; export {default as withResultOfAvailabilityCheck} from './withResultOfAvailabilityCheck.js'; diff --git a/src/data/composite/control-flow/withAvailabilityFilter.js b/src/data/composite/control-flow/withAvailabilityFilter.js new file mode 100644 index 00000000..cfea998e --- /dev/null +++ b/src/data/composite/control-flow/withAvailabilityFilter.js @@ -0,0 +1,40 @@ +// Performs the same availability check across all items of a list, providing +// a list that's suitable anywhere a filter is expected. +// +// Accepts the same mode options as withResultOfAvailabilityCheck. +// +// See also: +// - withFilteredList +// - withResultOfAvailabilityCheck +// + +import {input, templateCompositeFrom} from '#composite'; + +import inputAvailabilityCheckMode from './inputAvailabilityCheckMode.js'; + +import performAvailabilityCheck from './helpers/performAvailabilityCheck.js'; + +export default templateCompositeFrom({ + annotation: `withAvailabilityFilter`, + + inputs: { + from: input({type: 'array'}), + mode: inputAvailabilityCheckMode(), + }, + + outputs: ['#availabilityFilter'], + + steps: () => [ + { + dependencies: [input('from'), input('mode')], + compute: (continuation, { + [input('from')]: list, + [input('mode')]: mode, + }) => continuation({ + ['#availabilityFilter']: + list.map(value => + performAvailabilityCheck(value, mode)), + }), + }, + ], +}); diff --git a/src/data/composite/control-flow/withResultOfAvailabilityCheck.js b/src/data/composite/control-flow/withResultOfAvailabilityCheck.js index c2f64d21..c5221a62 100644 --- a/src/data/composite/control-flow/withResultOfAvailabilityCheck.js +++ b/src/data/composite/control-flow/withResultOfAvailabilityCheck.js @@ -20,6 +20,7 @@ // - exposeWhetherDependencyAvailable // - raiseOutputWithoutDependency // - raiseOutputWithoutUpdateValue +// - withAvailabilityFilter // import {input, templateCompositeFrom} from '#composite'; |