Skip to content

Commit

Permalink
frontend-plugin-api: refactor to use symbol to pass param overrides
Browse files Browse the repository at this point in the history
Signed-off-by: Patrik Oldsberg <[email protected]>
  • Loading branch information
Rugvip committed Sep 18, 2024
1 parent 7ac5d97 commit ac30b57
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
18 changes: 10 additions & 8 deletions packages/frontend-plugin-api/src/wiring/createExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ import { z } from 'zod';
import { createSchemaFromZod } from '../schema/createSchemaFromZod';
import { OpaqueExtensionDefinition } from '@internal/frontend';

/**
* This symbol is used to pass parameter overrides from the extension override to the blueprint factory
* @internal
*/
export const ctxParamsSymbol = Symbol('params');

/**
* Convert a single extension input into a matching resolved input.
* @public
Expand Down Expand Up @@ -484,11 +490,8 @@ export function createExtension<
apis,
config: config as any,
inputs: inputs as any,
params: overrideOptions.params,
// TODO(Rugvip): This is a bit of a hack to send the params
// through to the blueprint factory, might be that there's a
// better way to do this
} as Parameters<typeof options.factory>[0]);
[ctxParamsSymbol as any]: overrideOptions.params,
});
}
const parentResult = overrideOptions.factory(
(innerContext): ExtensionDataContainer<UOutput> => {
Expand All @@ -502,9 +505,8 @@ export function createExtension<
inputs,
innerContext?.inputs,
) as any,
params: innerContext?.params,
// TODO(Rugvip): Same as above
} as Parameters<typeof options.factory>[0]) as Iterable<any>,
[ctxParamsSymbol as any]: innerContext?.params,
}) as Iterable<any>,
options.output,
);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
ResolvedExtensionInputs,
VerifyExtensionFactoryOutput,
createExtension,
ctxParamsSymbol,
} from './createExtension';
import { z } from 'zod';
import { ExtensionInput } from './createExtensionInput';
Expand Down Expand Up @@ -482,10 +483,7 @@ export function createExtensionBlueprint<
config: options.config,
factory: ctx =>
options.factory(
// TODO(Rugvip): The `ctx` here might actually have a `params` key
// when the extension has been overridden. It's currently hidden in
// the types and there might be a better way to do this.
{ ...args.params, ...(ctx as any).params },
{ ...args.params, ...(ctx as any)[ctxParamsSymbol] },
ctx,
) as Iterable<ExtensionDataValue<any, any>>,
}) as ExtensionDefinition;
Expand Down Expand Up @@ -514,8 +512,7 @@ export function createExtensionBlueprint<
(innerParams, innerContext) => {
return createExtensionDataContainer<UOutput>(
options.factory(
// TODO(Rugvip): Same as ctx.params from .make
{ ...innerParams, ...(ctx as any).params },
{ ...innerParams, ...(ctx as any)[ctxParamsSymbol] },
{
apis,
node,
Expand Down

0 comments on commit ac30b57

Please sign in to comment.