Skip to content
This repository was archived by the owner on May 12, 2021. It is now read-only.

Commit 671b193

Browse files
authored
Merge pull request #41 from clocasto/release-1.2.1
Release 1.2.1
2 parents 1af6e8a + a34dab3 commit 671b193

File tree

6 files changed

+47
-31
lines changed

6 files changed

+47
-31
lines changed

dist/components/Field.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ var Field = function (_React$Component) {
3939
_this.state = {
4040
validators: validators,
4141
value: props.value,
42-
valid: (0, _utilities.isValid)(props.value, (0, _utilities.getValuesOf)(validators)),
42+
valid: (0, _utilities.isValid)(props.value, validators),
4343
pristine: true,
4444
debounce: Math.floor(Math.pow(Math.pow(+props.debounce, 2), 0.5)) || 0 };
4545
_this.finalValue = null;
@@ -56,15 +56,21 @@ var Field = function (_React$Component) {
5656
value: function componentWillUpdate(nextProps) {
5757
if (nextProps.passedValue !== this.props.passedValue) {
5858
this.cancelBroadcast(nextProps.passedValue);
59-
this.setState({ value: nextProps.passedValue }, this.debouncedBroadcastChange);
59+
this.setState({
60+
value: nextProps.passedValue,
61+
valid: (0, _utilities.isValid)(nextProps.passedValue, this.state.validators)
62+
}, this.debouncedBroadcastChange);
6063
} else if (nextProps.value !== this.props.value && nextProps.value !== this.state.value) {
6164
this.cancelBroadcast(nextProps.value);
62-
this.setState({ value: nextProps.value });
65+
this.setState({
66+
value: nextProps.value,
67+
valid: (0, _utilities.isValid)(nextProps.value, this.state.validators)
68+
});
6369
}
6470

6571
if (this.props.match !== nextProps.match) {
6672
var validators = (0, _utilities.updateValidators)({ match: nextProps.match }, this.state.validators);
67-
this.setState({ valid: (0, _utilities.isValid)(this.state.value, (0, _utilities.getValuesOf)(validators)), validators: validators });
73+
this.setState({ valid: (0, _utilities.isValid)(this.state.value, validators), validators: validators });
6874
}
6975
}
7076
}, {
@@ -88,11 +94,9 @@ var Field = function (_React$Component) {
8894
var value = e.target.value;
8995
this.finalValue = value;
9096

91-
var validators = (0, _utilities.getValuesOf)(this.state.validators);
92-
9397
this.setState({
9498
value: value,
95-
valid: (0, _utilities.isValid)(value, validators),
99+
valid: (0, _utilities.isValid)(value, this.state.validators),
96100
pristine: false
97101
}, this.debouncedBroadcastChange);
98102
}

dist/helpers/utilities.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ var _extends = Object.assign || function (target) { for (var i = 1; i < argument
88

99
exports.assembleValidators = assembleValidators;
1010
exports.updateValidators = updateValidators;
11-
exports.isValid = isValid;
1211
exports.getValuesOf = getValuesOf;
12+
exports.isValid = isValid;
1313
exports.buildStateForField = buildStateForField;
1414
exports.addFieldsToState = addFieldsToState;
1515
exports.makeFieldProps = makeFieldProps;
@@ -74,13 +74,6 @@ function updateValidators(config, validators) {
7474
return Object.assign({}, validators, assembleValidators(config));
7575
}
7676

77-
function isValid(value, validators) {
78-
return validators.reduce(function (status, validator) {
79-
if (!status) return false;
80-
return validator(value);
81-
}, true);
82-
}
83-
8477
function getValuesOf() {
8578
var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
8679

@@ -89,6 +82,17 @@ function getValuesOf() {
8982
});
9083
}
9184

85+
function isValid(value, validatorSet) {
86+
var validators = validatorSet;
87+
if (!Array.isArray(validators)) {
88+
validators = getValuesOf(validatorSet);
89+
}
90+
return validators.reduce(function (status, validator) {
91+
if (!status) return false;
92+
return validator(value);
93+
}, true);
94+
}
95+
9296
function buildStateForField(fieldProps) {
9397
var value = fieldProps.value;
9498

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-formulize",
3-
"version": "1.2.0",
3+
"version": "1.2.1",
44
"description": "A simple form validation library for React.js which wires up custom, controlled inputs through a declarative API.",
55
"main": "dist/index",
66
"keywords": [

readme.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
react-formulize [![Build Status](https://travis-ci.org/clocasto/react-formulize.svg?branch=master)](https://travis-ci.org/clocasto/react-formulize) [![Coverage Status](https://coveralls.io/repos/github/clocasto/react-formulize/badge.svg?branch=master&version=1_2_0)](https://coveralls.io/github/clocasto/react-formulize?branch=master&version=1_2_0)
1+
react-formulize [![Build Status](https://travis-ci.org/clocasto/react-formulize.svg?branch=master)](https://travis-ci.org/clocasto/react-formulize) [![Coverage Status](https://coveralls.io/repos/github/clocasto/react-formulize/badge.svg?branch=master&version=1_2_1)](https://coveralls.io/github/clocasto/react-formulize?branch=master&version=1_2_1)
22
=========
33

44
React-formulize is a simple form validation library for React.js which wires up custom, controlled inputs through a declarative API. The library strives to be minimal, and as such, does most component communication implicity. The end result is a legible form which clearly states the rules of its behavior.
@@ -303,7 +303,8 @@ MIT (See license.txt)
303303

304304
## <a href="release-history"></a>Release History
305305

306-
* [1.2.0](https://github.com/clocasto/react-formulize/pull/38) (Current)
306+
* [1.2.1](https://github.com/clocasto/react-formulize/pull/41) (Current)
307+
* [1.2.0](https://github.com/clocasto/react-formulize/pull/38)
307308
* [1.1.1](https://github.com/clocasto/react-formulize/pull/35)
308309
* [1.1.0](https://github.com/clocasto/react-formulize/pull/32)
309310
* [1.0.0](https://github.com/clocasto/react-formulize/pull/25)

src/components/Field.jsx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {
44
assembleValidators,
55
isValid,
66
updateValidators,
7-
getValuesOf,
87
mapPropsToChild,
98
makePropsForStatus,
109
} from '../helpers/utilities';
@@ -18,7 +17,7 @@ const Field = class extends React.Component {
1817
this.state = {
1918
validators,
2019
value: props.value,
21-
valid: isValid(props.value, getValuesOf(validators)),
20+
valid: isValid(props.value, validators),
2221
pristine: true,
2322
debounce: Math.floor(Math.pow(Math.pow(+props.debounce, 2), 0.5)) || 0, //eslint-disable-line
2423
};
@@ -34,15 +33,21 @@ const Field = class extends React.Component {
3433
componentWillUpdate(nextProps) {
3534
if (nextProps.passedValue !== this.props.passedValue) {
3635
this.cancelBroadcast(nextProps.passedValue);
37-
this.setState({ value: nextProps.passedValue }, this.debouncedBroadcastChange);
36+
this.setState({
37+
value: nextProps.passedValue,
38+
valid: isValid(nextProps.passedValue, this.state.validators),
39+
}, this.debouncedBroadcastChange);
3840
} else if (nextProps.value !== this.props.value && nextProps.value !== this.state.value) {
3941
this.cancelBroadcast(nextProps.value);
40-
this.setState({ value: nextProps.value });
42+
this.setState({
43+
value: nextProps.value,
44+
valid: isValid(nextProps.value, this.state.validators),
45+
});
4146
}
4247

4348
if (this.props.match !== nextProps.match) {
4449
const validators = updateValidators({ match: nextProps.match }, this.state.validators);
45-
this.setState({ valid: isValid(this.state.value, getValuesOf(validators)), validators });
50+
this.setState({ valid: isValid(this.state.value, validators), validators });
4651
}
4752
}
4853

@@ -63,11 +68,9 @@ const Field = class extends React.Component {
6368
const value = e.target.value;
6469
this.finalValue = value;
6570

66-
const validators = getValuesOf(this.state.validators);
67-
6871
this.setState({
6972
value,
70-
valid: isValid(value, validators),
73+
valid: isValid(value, this.state.validators),
7174
pristine: false,
7275
}, this.debouncedBroadcastChange);
7376
}

src/helpers/utilities.jsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,21 @@ export function updateValidators(config, validators) {
2929
return Object.assign({}, validators, assembleValidators(config));
3030
}
3131

32-
export function isValid(value, validators) {
32+
export function getValuesOf(obj = {}) {
33+
return Object.keys(obj).map(key => obj[key]);
34+
}
35+
36+
export function isValid(value, validatorSet) {
37+
let validators = validatorSet;
38+
if (!Array.isArray(validators)) {
39+
validators = getValuesOf(validatorSet);
40+
}
3341
return validators.reduce((status, validator) => {
3442
if (!status) return false;
3543
return validator(value);
3644
}, true);
3745
}
3846

39-
export function getValuesOf(obj = {}) {
40-
return Object.keys(obj).map(key => obj[key]);
41-
}
42-
4347
export function buildStateForField(fieldProps) {
4448
const { value } = fieldProps;
4549
const newState = {

0 commit comments

Comments
 (0)