You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would like to be able to pass a function that returns Promise and when the promise fails or returns a string it will indicate an invalid value.
Describe alternatives you've considered
deasync - Anti pattern
Additional context
Implementation suggestions:
Check if the return value is Promise by checking if .then exist
Transform any value to Promise and handle it everywhere like Promise:
// Option 1.1:functionoption1_1(){returnPromise.resolve(validator(args))}// Option 1.2:functionoption1_2(){constvalidatorRes=validator(args);if(validatorRes.then){returnvalidator;}if(validatorRes===true){returnPromise.resolve(validatorRes);}returnPromise.reject(validatorRes);}// Option 2.1:functionoption2_1(){returnnewPromise(resolve=>{// If the validator function throws it will reject the promiseresolve(validator(args));});}// Option 2.2:functionoption2_2(){returnnewPromise(resolve=>{// If the validator function throws it will reject the promiseresolve(validator(args));}).then(res=>{if(res===true){returntrue;}thrownewError(res);});}
The text was updated successfully, but these errors were encountered:
Is your feature request related to a problem?
I can't use validate that returns a Promise.
Use cases which this would be helpful:
Describe the solution you'd like
I would like to be able to pass a function that returns Promise and when the promise fails or returns a string it will indicate an invalid value.
Describe alternatives you've considered
deasync
- Anti patternAdditional context
Implementation suggestions:
Promise
by checking if.then
existThe text was updated successfully, but these errors were encountered: