Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
4 additions
and
44 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,12 @@ | ||
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms)) | ||
|
||
function composeAsyncValidators(validatorFns) { | ||
return async (values, dispatch, props, field) => { | ||
const validatorFn = validatorFns[field] | ||
await validatorFn(values, dispatch, props, field) | ||
} | ||
} | ||
|
||
const usernameValidate = (values /*, dispatch */) => { | ||
const asyncValidate = (values /*, dispatch */) => { | ||
return sleep(1000).then(() => { | ||
// simulate server latency | ||
console.log('asyncValidate username') | ||
if (['john', 'paul', 'george', 'ringo'].includes(values.username)) { | ||
throw { username: 'That username is taken' } | ||
} | ||
}) | ||
} | ||
|
||
const companynameValidate = (values /*, dispatch */) => { | ||
return sleep(1000).then(() => { | ||
// simulate server latency | ||
console.log('asyncValidate companyname') | ||
if (['google', 'amazon', 'tesla'].includes(values.companyname)) { | ||
throw { companyname: 'That companyname is taken' } | ||
} | ||
}) | ||
} | ||
|
||
const asyncValidate = composeAsyncValidators({ | ||
username: usernameValidate, | ||
companyname: companynameValidate | ||
}) | ||
|
||
export default asyncValidate |
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