From f2464c6031d83108d12b08df83af2b2f8e426002 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Sat, 16 Nov 2024 13:27:30 -0400 Subject: data: withAvailabilityFilter --- src/data/composite/control-flow/index.js | 1 + .../control-flow/withAvailabilityFilter.js | 40 ++++++++++++++++++++++ .../control-flow/withResultOfAvailabilityCheck.js | 1 + 3 files changed, 42 insertions(+) create mode 100644 src/data/composite/control-flow/withAvailabilityFilter.js (limited to 'src/data/composite/control-flow') 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'; -- cgit 1.3.0-6-gf8a5