Is your feature request related to a problem? Please describe.
It's a wide-used feature for checking username availability, filtering forbidden words in the content, or any other computing/request which need to take a certain amount of run time.
Describe the solution you'd like
It seems that making validation.validator perform not only synchronous function call but also asynchronous one with Promise is Intuitive way.
How to implement
The quick way in babel era is use async/await syntax.
validate = async () => {
// ...
let validatorResult = null;
if(validator && isFunction(validator)) {
validatorResult = await validator(value, reject);
}
// ...
}
But I think there are still some compatibility or performance issues.
For Promise only case, I prefer the method in Formik source code and doc, which Promisify either async function or normal one.
runSingleFieldLevelValidation = (
field: string,
value: void | string
): Promise<string> => {
return new Promise(resolve =>
resolve(this.fields[field].props.validate(value))
).then(x => x, e => e);
};
As this way, we can Promisify all the validate handle include orginal ajv validation.
Then, we can use Promise.all and map reduce to handle results and errors clearly.
Is your feature request related to a problem? Please describe.
It's a wide-used feature for checking username availability, filtering forbidden words in the content, or any other computing/request which need to take a certain amount of run time.
Describe the solution you'd like
It seems that making validation.validator perform not only synchronous function call but also asynchronous one with
Promiseis Intuitive way.How to implement
The quick way in babel era is use async/await syntax.
But I think there are still some compatibility or performance issues.
For
Promiseonly case, I prefer the method in Formik source code and doc, whichPromisifyeither async function or normal one.As this way, we can
Promisifyall the validate handle include orginal ajv validation.Then, we can use Promise.all and map reduce to handle results and errors clearly.