Created
January 31, 2021 14:08
-
-
Save radekwarisch/34d623237670a4044532c6d2eec4dc78 to your computer and use it in GitHub Desktop.
Chainify gather options util
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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