Skip to content

Instantly share code, notes, and snippets.

@radekwarisch
Created January 31, 2021 14:08
Show Gist options
  • Save radekwarisch/34d623237670a4044532c6d2eec4dc78 to your computer and use it in GitHub Desktop.
Save radekwarisch/34d623237670a4044532c6d2eec4dc78 to your computer and use it in GitHub Desktop.
Chainify gather options util
export const chainifyGatherOptions = <TInputType>(
gatherOptionsFn: (
tree: Tree,
context: SchematicContext
) => Observable<TInputType> | Promise<TInputType> | TInputType
) => {
const reassignInputKeys = (input: TInputType) => (newInput: TInputType) => {
Object.entries(newInput).forEach(([key, newValue]: [string, unknown]) => {
Object.assign(input, {
[key]: newValue,
});
});
};
return (input: TInputType) => (tree: Tree, context: SchematicContext) => {
return compose(gatherOptionsFn)(tree, context).pipe(
tap(reassignInputKeys(input)),
map(() => {
return tree;
})
);
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment