diff options
Diffstat (limited to 'src/data/composite')
-rw-r--r-- | src/data/composite/data/withFilteredList.js | 16 |
1 files changed, 14 insertions, 2 deletions
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])), }), }, ], |