Skip to content

Instantly share code, notes, and snippets.

@nikolasleblanc
Created July 26, 2017 14:03
Show Gist options
  • Save nikolasleblanc/cf01d90d87350a1516dd6ae9d0fe9208 to your computer and use it in GitHub Desktop.
Save nikolasleblanc/cf01d90d87350a1516dd6ae9d0fe9208 to your computer and use it in GitHub Desktop.
// example for single field
const validators = {
validatorKey: validatorFunction,
};
function validatorFunction(value): boolean {
return true;
}
const isValid = (value, validatorKeys: Array<string>): boolean => {
return validatorKeys.reduce((valIsValid, key) => validators[key](value), true);
}
const createFormFieldSelector = <T>(fieldPath: string[]) =>
createSelector(
formStateSelector,
(form: IForm) => path<T>(fieldPath, form)
);
const createValidatorSelector = (fieldPath, validatorKeys) => {
return createSelector(
createFormFieldSelector(fieldPath),
(fieldValue) => isValid(fieldPath, validatorKeys),
);
}
// in your component
@select(createValidatorSelector(fieldPath, validatorKeys))
isFieldValid$: Observable<boolean>;; //Observable boolean
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment