Compute shared Context properties
Bind one synchronous computeContext callback to a builder and share its inferred Context across configurations and extensions.
Use createVectorBuilder({ computeContext }) when several configuration and extension callbacks need the same derived value. The builder binds one inferred Context extension to all of its helpers.
This example derives a short project label for the existing project-summary command.
import { createVectorBuilder } from '@evilkiwi/vector';
export const vector = createVectorBuilder({
computeContext: ({ project }) => ({
projectLabel: project.canonical.split('/').at(-1) ?? project.id,
}),
});
Define the command with the bound helper so context.projectLabel is inferred.
import { vector } from '../vector.js';
export const projectSummary = vector.defineCommand({
name: 'project-summary',
build: (context) => ({
template: `Summarize ${context.projectLabel}`,
}),
});
Select it with the same builder’s defineVector().
import { projectSummary } from './extensions/project-summary.js';
import { vector } from './vector.js';
export default vector.defineVector({
id: 'project-tools',
build: (context) => ({
commands: context.projectLabel.length === 0 ? [] : [projectSummary],
}),
});
Vector calls computeContext once per activation and shares the resulting Context properties with the root callback and every selected bound extension.
An ordinary non-callable then property and a null-prototype record are valid. A builder created without options preserves the root helpers’ base Context shape.
See createVectorBuilder() and Context for the exact types and boundaries.