Skip to content

Consumption of context tokens pattern #2

@DexterStorey

Description

@DexterStorey

Imagine a generic block called "view". A view provides some snippet of data that is compatible with a string, for example a username. This token is available via the literal USERNAME. The view has an input key username, that can only be passed the literal USERNAME, which at runtime gets hydrated with an actual username. The view also has an input key children which takes any void returning node. How can we give these children access to consume the context token USERNAME, while ensuring that other nodes outside of the view don't have access to it? Essentially, we need to duplicate any schema that accepts string-like inputs and put those defs inside view, while keeping the originals intact.

Why is this important? Consider more complex examples of consumption, such as a table. A table provides data per N rows, such as {name: string, age: number, alive: boolean}. To define a table, you will want to pass a consumer per column which uses the specific row<>column value, such as a number display for the age, and a boolean display for the alive.

const table = {
	node: 'personTable',
	input: {
		query: {
			node: 'getPeople',
			input: {}
		},
		columns: {
			name: {
				node: 'renderText',
				input: {
                                        // 👇
					text: '$.NAME'
				}
			},
			age: {
				node: 'renderText',
				input: {
                                        // 👇
					text: '$.AGE'
				}
			},
			alive: {
				node: 'renderText',
				input: {
                                        // 👇
					text: '$.ALIVE'
				}
			}
		}
	}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions