Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: iterate the rules in the forEach state, not the state, closes #1002 #1050

Open
wants to merge 1 commit into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 2 additions & 4 deletions packages/validators/src/utils/__tests__/forEach.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ describe('forEach', () => {
required: false,
$invalid: true,
$error: true
},
surname: {}
}
}
],
$errors: [
Expand All @@ -72,8 +71,7 @@ describe('forEach', () => {
$response: false,
$validator: 'required'
}
],
surname: []
]
}
],
$valid: false
Expand Down
6 changes: 3 additions & 3 deletions packages/validators/src/utils/forEach.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ export default function forEach (validators) {
// go over the collection. It can be a ref as well.
return unwrap(collection).reduce((previous, collectionItem) => {
// go over each property
const collectionEntryResult = Object.entries(collectionItem).reduce((all, [property, $model]) => {
// get the validators for this property
const innerValidators = validators[property] || {}
const collectionEntryResult = Object.entries(validators).reduce((all, [property, innerValidators]) => {
// get the model value for this property
const $model = collectionItem[property] || ''
// go over each validator and run it
const propertyResult = Object.entries(innerValidators).reduce((all, [validatorName, currentValidator]) => {
// extract the validator. Supports simple and extended validators.
Expand Down