-
-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
patch: add skipWhen for forward compatibility
- Loading branch information
Showing
14 changed files
with
66 additions
and
35 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,7 +62,7 @@ Vest tries to remediate this by separating validation logic from feature logic s | |
## Example code ([Run in sandbox](https://codesandbox.io/s/vest-react-tutorial-finished-ztt8t?file=/src/validate.js)) | ||
|
||
```js | ||
import { create, only, test, enforce, warn } from 'vest'; | ||
import { create, only, test, enforce, warn, skipWhen } from 'vest'; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
ealush
via email
Author
Owner
|
||
|
||
export default create('user_form', (data = {}, currentField) => { | ||
only(currentField); | ||
|
@@ -88,11 +88,11 @@ export default create('user_form', (data = {}, currentField) => { | |
enforce(data.password).matches(/[0-9]/); | ||
}); | ||
|
||
if (data.password) { | ||
skipWhen(!data.password, () => { | ||
test('confirm_password', 'Passwords do not match', () => { | ||
enforce(data.confirm_password).equals(data.password); | ||
}); | ||
} | ||
}); | ||
|
||
test('email', 'Email Address is not valid', () => { | ||
enforce(data.email).isEmail(); | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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,4 +1,5 @@ | ||
export { only, skip } from 'exclusive'; | ||
export { default as skipWhen } from 'skipWhen' | ||
export { default as warn } from 'warn'; | ||
export { default as group } from 'group'; | ||
export { default as optional } from 'optionalTests'; |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import isFunction from 'isFunction'; | ||
import { isFalsy } from 'isTruthy'; | ||
import optionalFunctionValue from 'optionalFunctionValue'; | ||
|
||
// This function by itself doesn't do much, and is only a wrapper around | ||
// an if statement. The reason for it is to support version 4 api in version 3 | ||
// so that someone reading the latest docs can still run the code. | ||
|
||
export default function skipWhen(conditional, callback) { | ||
if (isFalsy(optionalFunctionValue(conditional))) { | ||
if (isFunction(callback)) { | ||
callback(); | ||
} | ||
} | ||
} |
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
Hey @ealush I guess it should be a minor version upgrade
3.3.0
, usingadd
instead ofpatch
in the commit message to make it work with the semantic releasing tool