Skip to content
This repository has been archived by the owner on Apr 24, 2023. It is now read-only.

Improve validation with asynchronous pipeline #175

Open
wants to merge 22 commits into
base: canary
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
1aefc98
Fix: check whether validator is a function to avoid type error
Mosoc Apr 27, 2019
db82657
Fix: typo `ComponentWithValidation`
Mosoc Apr 27, 2019
8c03926
Only pass schema property to avj.compile()
Mosoc Apr 29, 2019
ae5d0ce
Fix some coding style
Mosoc Apr 29, 2019
991c04f
Add async keyword to validate function
Mosoc May 9, 2019
0d51466
Update validation test file because of object structure change
Mosoc May 14, 2019
ff1312c
Update validator test
Mosoc May 14, 2019
2f642e0
Implement asynchronous pipline of validation
Mosoc May 9, 2019
763fde4
Fix typo: withValidation
Mosoc May 14, 2019
dfa6ce1
Reform validation's test file with async/await, and remove unused props
Mosoc May 15, 2019
c5711d0
Change the test label of customized validator
Mosoc May 15, 2019
9e5748a
Create test cases of sync validator function
Mosoc May 15, 2019
1c731c9
Correct fault in validation HoC
Mosoc May 15, 2019
e10c57f
Create test cases with async-wait functions
Mosoc May 15, 2019
67ffc9a
Create test cases with promise operations
Mosoc May 15, 2019
a493e5a
Add try-catch in validate to handle uncaught error
Mosoc May 15, 2019
096a86a
Workaround for when validator is not a function
Mosoc May 15, 2019
91038ba
Reove `_ ` prefix of promise creator
Mosoc May 16, 2019
831fd24
Update type definition of validation
Mosoc May 16, 2019
471a875
Update the usage of customized validator in docs
Mosoc May 18, 2019
0993e84
Use keep (verb) as prefix for promise creator
Mosoc May 19, 2019
9157f2c
Change `keep`(verb) with `promise`(verb)
Mosoc May 29, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fix: check whether validator is a function to avoid type error
  • Loading branch information
Mosoc committed May 14, 2019
commit 1aefc98f6b204b94f9d4c8b91400593513796b18
4 changes: 2 additions & 2 deletions packages/canner/src/hocs/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import * as React from 'react';
import RefId from 'canner-ref-id';
import Ajv from 'ajv';
import {isEmpty, isArray, isPlainObject, get} from 'lodash';
import {isEmpty, isArray, isPlainObject, isFunction, get} from 'lodash';
import type {HOCProps} from './types';

type State = {
Expand Down Expand Up @@ -49,7 +49,7 @@ export default function withValidation(Com: React.ComponentType<*>) {
// custom validator
const {validator, errorMessage} = validation;
const reject = message => ({error: true, message});
const validatorResult = validator && validator(value, reject);
const validatorResult = (validator && isFunction(validator) ) && validator(value, reject);

let customValid = !(validatorResult && validatorResult.error);
// if value is empty, should not validate with ajv
Expand Down