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

Commit

Permalink
Return value could also be empty array
Browse files Browse the repository at this point in the history
  • Loading branch information
fastner committed May 17, 2016
1 parent f82d1fd commit 2539b5e
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/VuexValidatorPlugin.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import reduce from "lodash-es/reduce"
import isArray from "lodash-es/isArray"

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

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

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

if (!myself)
return all

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

if (all)
return all.concat(self)
return all.concat(myself)

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

0 comments on commit 2539b5e

Please sign in to comment.