Initial import
This commit is contained in:
16
src/types/component-plugin.ts
Executable file
16
src/types/component-plugin.ts
Executable file
@@ -0,0 +1,16 @@
|
||||
export type PropsPlugin<TProps> = (props: TProps) => TProps;
|
||||
|
||||
export type ComponentPlugin<TInput, TProps = TInput> = (input: TInput) => TProps;
|
||||
|
||||
export type ComponentPluginFactory<
|
||||
TArgs extends unknown[] = [],
|
||||
TInput = unknown,
|
||||
TProps = TInput,
|
||||
> = (...args: TArgs) => ComponentPlugin<TInput, TProps>;
|
||||
|
||||
export function plugins<TProps>(
|
||||
props: TProps,
|
||||
pluginList: ReadonlyArray<PropsPlugin<TProps>>,
|
||||
): TProps {
|
||||
return pluginList.reduce((currentProps, plugin) => plugin(currentProps), props);
|
||||
}
|
||||
Reference in New Issue
Block a user