From f5f21156d205a1ad8533a717e5552707d26551a2 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Wed, 30 Oct 2024 15:41:21 -0300 Subject: data: withFilteredList: flip option --- src/data/composite/data/withFilteredList.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/data/composite/data/withFilteredList.js b/src/data/composite/data/withFilteredList.js index 60fe66f4..1dbbd3af 100644 --- a/src/data/composite/data/withFilteredList.js +++ b/src/data/composite/data/withFilteredList.js @@ -2,6 +2,9 @@ // corresponding items in a list. Items which correspond to a truthy value // are kept, and the rest are excluded from the output list. // +// If the flip option is set, only items corresponding with a *falsy* value in +// the filter are kept. +// // TODO: It would be neat to apply an availability check here, e.g. to allow // not providing a filter at all and performing the check on the contents of // the list (though on the filter, if present, is fine too). But that's best @@ -25,19 +28,28 @@ export default templateCompositeFrom({ inputs: { list: input({type: 'array'}), filter: input({type: 'array'}), + + flip: input({ + type: 'boolean', + defaultValue: false, + }), }, outputs: ['#filteredList'], steps: () => [ { - dependencies: [input('list'), input('filter')], + dependencies: [input('list'), input('filter'), input('flip')], compute: (continuation, { [input('list')]: list, [input('filter')]: filter, + [input('flip')]: flip, }) => continuation({ '#filteredList': - list.filter((item, index) => filter[index]), + list.filter((_item, index) => + (flip + ? !filter[index] + : filter[index])), }), }, ], -- cgit 1.3.0-6-gf8a5