From 8b20b6d84ee9e296ee9107eda8831aa9a18b3589 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Mon, 5 Aug 2024 12:18:53 -0300 Subject: data: thingList --- src/data/composite/wiki-properties/index.js | 1 + src/data/composite/wiki-properties/thingList.js | 44 +++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 src/data/composite/wiki-properties/thingList.js (limited to 'src/data') diff --git a/src/data/composite/wiki-properties/index.js b/src/data/composite/wiki-properties/index.js index 5328d17e..e35948e7 100644 --- a/src/data/composite/wiki-properties/index.js +++ b/src/data/composite/wiki-properties/index.js @@ -25,5 +25,6 @@ export {default as simpleDate} from './simpleDate.js'; export {default as simpleString} from './simpleString.js'; export {default as singleReference} from './singleReference.js'; export {default as thing} from './thing.js'; +export {default as thingList} from './thingList.js'; export {default as urls} from './urls.js'; export {default as wikiData} from './wikiData.js'; diff --git a/src/data/composite/wiki-properties/thingList.js b/src/data/composite/wiki-properties/thingList.js new file mode 100644 index 00000000..f4c00e06 --- /dev/null +++ b/src/data/composite/wiki-properties/thingList.js @@ -0,0 +1,44 @@ +// A list of Things, provided directly rather than by reference. +// +// Essentially the same as wikiData, but exposes the list of things, +// instead of keeping it private. + +import {input, templateCompositeFrom} from '#composite'; +import {isThingClass, validateWikiData} from '#validators'; + +import {exposeConstant, exposeUpdateValueOrContinue} + from '#composite/control-flow'; + +export default templateCompositeFrom({ + annotation: `wikiData`, + + compose: false, + + inputs: { + class: input.staticValue({ + validate: isThingClass, + defaultValue: null, + }), + }, + + update: ({ + [input.staticValue('class')]: thingClass, + }) => ({ + validate: + validateWikiData({ + referenceType: + (thingClass + ? thingClass[Symbol.for('Thing.referenceType')] + : ''), + }), + }), + + steps: () => [ + exposeUpdateValueOrContinue(), + + exposeConstant({ + value: input.value([]), + }), + ], +}); + -- cgit 1.3.0-6-gf8a5