Created
July 26, 2017 14:03
-
-
Save nikolasleblanc/cf01d90d87350a1516dd6ae9d0fe9208 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// 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