Skip to content

Instantly share code, notes, and snippets.

@landrysoules
Last active September 30, 2019 07:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save landrysoules/a3930eba6f4af8b9c5c8f665b208cebe to your computer and use it in GitHub Desktop.
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
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