From be402bfcad9a8ab5287ed15f942f5d4730d7490e Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Mon, 4 Mar 2024 20:25:05 -0400 Subject: data: contribution: context --- src/data/composite/things/contribution/index.js | 1 + .../things/contribution/withContributionContext.js | 29 ++++++++++++++++++++++ src/data/things/contribution.js | 26 ++++++++++++++++++- 3 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 src/data/composite/things/contribution/withContributionContext.js (limited to 'src/data') diff --git a/src/data/composite/things/contribution/index.js b/src/data/composite/things/contribution/index.js index c0506a2b..b06e8677 100644 --- a/src/data/composite/things/contribution/index.js +++ b/src/data/composite/things/contribution/index.js @@ -1 +1,2 @@ export {default as withContributionArtist} from './withContributionArtist.js'; +export {default as withContributionContext} from './withContributionContext.js'; diff --git a/src/data/composite/things/contribution/withContributionContext.js b/src/data/composite/things/contribution/withContributionContext.js new file mode 100644 index 00000000..83ad5b73 --- /dev/null +++ b/src/data/composite/things/contribution/withContributionContext.js @@ -0,0 +1,29 @@ +import {input, templateCompositeFrom} from '#composite'; + +import {withPropertiesFromObject} from '#composite/data'; + +export default templateCompositeFrom({ + annotation: `withContributionContext`, + + outputs: [ + '#contributionTarget', + '#contributionProperty', + ], + + steps: () => [ + { + dependencies: ['thing', 'thingProperty'], + + compute: (continuation, { + ['thing']: thing, + ['thingProperty']: thingProperty, + }) => continuation({ + ['#contributionTarget']: + thing.constructor[Symbol.for('Thing.referenceType')], + + ['#contributionProperty']: + thingProperty, + }), + }, + ], +}); diff --git a/src/data/things/contribution.js b/src/data/things/contribution.js index 7eb8cfc7..e6479a1e 100644 --- a/src/data/things/contribution.js +++ b/src/data/things/contribution.js @@ -10,7 +10,10 @@ import {isStringNonEmpty, isThing, validateReference} from '#validators'; import {exposeDependency} from '#composite/control-flow'; import {withResolvedReference} from '#composite/wiki-data'; -import {withContributionArtist} from '#composite/things/contribution'; +import { + withContributionArtist, + withContributionContext, +} from '#composite/things/contribution'; export class Contribution extends Thing { static [Thing.getPropertyDescriptors] = () => ({ @@ -42,6 +45,27 @@ export class Contribution extends Thing { flags: {update: true, expose: true}, update: {validate: isStringNonEmpty}, }, + + // Expose only + + context: [ + withContributionContext(), + + { + dependencies: [ + '#contributionTarget', + '#contributionProperty', + ], + + compute: ({ + ['#contributionTarget']: target, + ['#contributionProperty']: property, + }) => ({ + target, + property, + }), + }, + ], }); [inspect.custom](depth, options, inspect) { -- cgit 1.3.0-6-gf8a5