From db28144f1d4c7f1a0c1367031dda76ee7484c30d Mon Sep 17 00:00:00 2001 From: Sebastian Fastner Date: Tue, 17 May 2016 13:44:19 +0200 Subject: [PATCH] Refactor validation process to support more than one validation result --- src/VuexValidatorPlugin.js | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/VuexValidatorPlugin.js b/src/VuexValidatorPlugin.js index 6afe96a..f2c13d8 100644 --- a/src/VuexValidatorPlugin.js +++ b/src/VuexValidatorPlugin.js @@ -1,5 +1,4 @@ import reduce from "lodash-es/reduce" -import isArray from "lodash-es/isArray" const validators = [] const validatorsMap = {} @@ -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) } }