From 383dcc488d272e7da30c9b7d9cf3ec71f971a6cf Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Wed, 6 Mar 2024 14:23:33 -0400 Subject: data: exposeWhetherDependencyAvailable --- .../exposeWhetherDependencyAvailable.js | 42 ++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/data/composite/control-flow/exposeWhetherDependencyAvailable.js (limited to 'src/data/composite/control-flow/exposeWhetherDependencyAvailable.js') diff --git a/src/data/composite/control-flow/exposeWhetherDependencyAvailable.js b/src/data/composite/control-flow/exposeWhetherDependencyAvailable.js new file mode 100644 index 00000000..a2fdd6b0 --- /dev/null +++ b/src/data/composite/control-flow/exposeWhetherDependencyAvailable.js @@ -0,0 +1,42 @@ +// Exposes true if a dependency is available, and false otherwise, +// or the reverse if the `negate` input is set true. +// +// See withResultOfAvailabilityCheck for {mode} options. + +import {input, templateCompositeFrom} from '#composite'; + +import inputAvailabilityCheckMode from './inputAvailabilityCheckMode.js'; +import withResultOfAvailabilityCheck from './withResultOfAvailabilityCheck.js'; + +export default templateCompositeFrom({ + annotation: `exposeWhetherDependencyAvailable`, + + compose: false, + + inputs: { + dependency: input({acceptsNull: true}), + + mode: inputAvailabilityCheckMode(), + + negate: input({type: 'boolean', defaultValue: false}), + }, + + steps: () => [ + withResultOfAvailabilityCheck({ + from: input('dependency'), + mode: input('mode'), + }), + + { + dependencies: ['#availability', input('negate')], + + compute: ({ + ['#availability']: availability, + [input('negate')]: negate, + }) => + (negate + ? !availability + : availability), + }, + ], +}); -- cgit 1.3.0-6-gf8a5