Add support for loading (a) harness(es) on a component
Opened this issue · 0 comments
Heines1983 commented
It would be great of a harness could also be loaded within a specific component instead of the document root. Now I've added myself two methods but it would of course be better if its included in the package. My code at the moment:
export function getHarnessForComponent<HARNESS extends ComponentHarness, COMPONENT extends ContentContainerComponentHarness<string>>(
query: HarnessQuery<HARNESS>, component: ChainableHarness<COMPONENT>
): ChainableHarness<HARNESS> {
return new Proxy<ChainableHarness<HARNESS>>({} as any, {
get: (_, prop) =>
(addHarnessMethodsToChainer(component.getHarness(query) as ChainableHarness<HARNESS>) as any)[prop],
});
}
export function getAllHarnessesForComponent<HARNESS extends ComponentHarness, COMPONENT extends ContentContainerComponentHarness<string>>(
query: HarnessQuery<HARNESS>, component: ChainableHarness<COMPONENT>
): ChainableHarness<HARNESS[]> {
return new Proxy<ChainableHarness<HARNESS[]>>({} as any, {
get: (_, prop) => (component.getAllHarnesses(query) as any as ChainableHarness<HARNESS[]> as any)[prop],
});
}