Skip to content
This repository has been archived by the owner on Nov 15, 2017. It is now read-only.

Commit

Permalink
Refactor validation process to support more than one validation result
Browse files Browse the repository at this point in the history
  • Loading branch information
fastner committed May 17, 2016
1 parent 2539b5e commit db28144
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/VuexValidatorPlugin.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import reduce from "lodash-es/reduce"
import isArray from "lodash-es/isArray"

const validators = []
const validatorsMap = {}
Expand Down Expand Up @@ -52,22 +51,21 @@ function propertyValidator(state)

return reduce(vals.map((val) => val.validatorFunction(state)), (all, self) =>
{
if (!self)
return all

let myself = self

if (myself instanceof Array && myself.length <= 1)
myself = myself[0]

if (!myself)
return all
if (!(myself instanceof Array))
myself = [ myself ]

// It is possible, that a validation fails without being this property as reason
if (myself.fields.indexOf(property) < 0)
return all
myself = myself.filter((item) => item.fields.indexOf(property) >= 0)

if (all)
return all.concat(myself)

return [ myself ]
return myself
}, null)
}
}
Expand Down

0 comments on commit db28144

Please sign in to comment.