From 9dd9d5c328da8ad1d90cd33d4a13efac92104398 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Tue, 12 Sep 2023 14:34:20 -0300 Subject: data: more syntax WIP --- src/data/things/composite.js | 65 ++++++++++++++++++++++++-------------------- 1 file changed, 35 insertions(+), 30 deletions(-) (limited to 'src/data/things/composite.js') diff --git a/src/data/things/composite.js b/src/data/things/composite.js index 26124b56..32a61033 100644 --- a/src/data/things/composite.js +++ b/src/data/things/composite.js @@ -344,7 +344,9 @@ import { const globalCompositeCache = {}; -export function compositeFrom(firstArg, secondArg) { +export function compositeFrom(description) { + const {annotation, steps: composition} = description; + const debug = fn => { if (compositeFrom.debug === true) { const label = @@ -363,13 +365,6 @@ export function compositeFrom(firstArg, secondArg) { } }; - let annotation, composition; - if (typeof firstArg === 'string') { - [annotation, composition] = [firstArg, secondArg]; - } else { - [annotation, composition] = [null, firstArg]; - } - const base = composition.at(-1); const steps = composition.slice(); @@ -974,6 +969,7 @@ export function exposeConstant({ export function withResultOfAvailabilityCheck({ fromUpdateValue, fromDependency, + modeDependency, mode = 'null', into = '#availability', }) { @@ -1026,31 +1022,40 @@ export function withResultOfAvailabilityCheck({ // Exposes a dependency as it is, or continues if it's unavailable. // See withResultOfAvailabilityCheck for {mode} options! -export function exposeDependencyOrContinue({ - dependency, - mode = 'null', -}) { - return compositeFrom(`exposeDependencyOrContinue`, [ - withResultOfAvailabilityCheck({ - fromDependency: dependency, - mode, - }), +export const exposeDependencyOrContinue = + templateCompositeFrom({ + annotation: `exposeDependencyOrContinue`, - { - dependencies: ['#availability'], - compute: ({'#availability': availability}, continuation) => - (availability - ? continuation() - : continuation.raise()), + inputs: { + dependency: input(), + mode: input.default('null'), }, - { - mapDependencies: {dependency}, - compute: ({dependency}, continuation) => - continuation.exit(dependency), - }, - ]); -} + steps: () => [ + withResultOfAvailabilityCheck({ + from: input('dependency'), + mode: input('mode'), + }), + + { + dependencies: ['#availability'], + compute: (continuation, { + ['#availability']: availability, + }) => + (availability + ? continuation() + : continuation.raise()), + }, + + { + dependencies: [input('#dependency')], + compute: (continuation, { + [input('#dependency')]: dependency, + }) => + continuation.exit(dependency), + }, + ], + }); // Exposes the update value of an {update: true} property as it is, // or continues if it's unavailable. See withResultOfAvailabilityCheck -- cgit 1.3.0-6-gf8a5