Last active
September 30, 2019 07:07
-
-
Save landrysoules/a3930eba6f4af8b9c5c8f665b208cebe to your computer and use it in GitHub Desktop.
Example of using dynamic function call via map + reduce for adding boolean values
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
const validate = (value, allValues, meta, validationTypes) => { | |
const ret = validationTypes.reduce((sum, next) => { | |
console.debug({ sum, next }); | |
return sum && next(value, allValues, meta); | |
}, true); | |
console.debug('V_A_L_I_D_AT_I_O_N_', ret); | |
return ret; | |
}; | |
const required = value => { | |
return value ? undefined : 'validation.required'; | |
}; | |
const test = (value, allValues, meta) => { | |
console.debug({ value, allValues, meta }); | |
return true; | |
}; | |
const test2 = (value, allValues, meta) => { | |
console.debug({ value, allValues, meta }); | |
return false; | |
}; | |
export const VALIDATION_TYPE = { | |
REQUIRED: required, | |
TEST: test, | |
TEST2: test2 | |
}; | |
export default validate; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment