Skip to content
This repository was archived by the owner on Aug 23, 2022. It is now read-only.

Commit eb767a9

Browse files
committed
Merge branch 'master' into etrepum-rerendering-gh225
# Conflicts: # test/field-component-spec.js
2 parents f3c4a50 + f20c5e4 commit eb767a9

File tree

8 files changed

+23
-20
lines changed

8 files changed

+23
-20
lines changed

src/actions/model-actions.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import _get from '../utils/get';
22
import endsWith from 'lodash/endsWith';
3-
import isEqual from 'lodash/isEqual';
43
import identity from 'lodash/identity';
54
import icepick from 'icepick';
65

@@ -34,9 +33,9 @@ const change = (model, value, options = {}) => {
3433
};
3534
};
3635

37-
const xor = (model, item) => (dispatch, getState) => {
36+
const xor = (model, item, iteratee = (value) => value === item) => (dispatch, getState) => {
3837
const state = _get(getState(), model, []);
39-
const stateWithoutItem = state.filter(stateItem => !isEqual(stateItem, item));
38+
const stateWithoutItem = state.filter(stateItem => !iteratee(stateItem));
4039
const value = (state.length === stateWithoutItem.length) ? [...state, item] : stateWithoutItem;
4140

4241
dispatch({

src/components/field-component.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import connect from 'react-redux/lib/components/connect';
44

55
import _get from '../utils/get';
66
import identity from 'lodash/identity';
7-
import isEqual from 'lodash/isEqual';
87
import omit from 'lodash/omit';
98

109
import actions from '../actions';
@@ -30,7 +29,7 @@ function isChecked(props) {
3029
if (isMulti(props.model)) {
3130
return (props.modelValue || [])
3231
.filter((item) =>
33-
isEqual(item, props.value))
32+
item === props.value)
3433
.length;
3534
}
3635

@@ -47,7 +46,7 @@ const controlPropsMap = {
4746
radio: (props) => ({
4847
...props,
4948
name: props.model,
50-
checked: isEqual(props.modelValue, props.value),
49+
checked: props.modelValue === props.value,
5150
value: props.value,
5251
}),
5352
select: (props) => ({
@@ -115,9 +114,7 @@ function createFieldControlComponent(control, props, options) {
115114
}
116115

117116
/* eslint-disable react/prop-types */
118-
const {
119-
mapProps = options.controlPropsMap[getControlType(control, options)],
120-
} = props;
117+
const mapProps = options.controlPropsMap[getControlType(control, options)];
121118

122119
const controlProps = omit(props, ['children', 'className']);
123120

@@ -213,7 +210,6 @@ function createFieldClass(customControlPropsMap = {}, defaultProps = {}) {
213210
PropTypes.func,
214211
PropTypes.object,
215212
]),
216-
mapProps: PropTypes.func,
217213
modelValue: PropTypes.any,
218214
};
219215

src/components/form-component.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@ class Form extends Component {
5353
} = this.props;
5454

5555
if (!validators && !errors && (modelValue !== nextProps.modelValue)) {
56-
dispatch(actions.setValidity(model, true));
56+
if (!formValue.valid) {
57+
dispatch(actions.setValidity(model, true));
58+
}
59+
5760
return;
5861
}
5962

src/reducers/form-reducer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import _get from '../utils/get';
22
import every from 'lodash/every';
33
import icepick from 'icepick';
44
import isBoolean from 'lodash/isBoolean';
5-
import isEqual from 'lodash/isEqual';
5+
import arraysEqual from '../utils/arrays-equal';
66
import isPlainObject from 'lodash/isPlainObject';
77
import map from 'lodash/map';
88
import mapValues from '../utils/map-values';
@@ -127,7 +127,7 @@ function _createFormReducer(model, initialState) {
127127

128128
const path = toPath(action.model);
129129

130-
if (!isEqual(path.slice(0, modelPath.length), modelPath)) {
130+
if (!arraysEqual(path.slice(0, modelPath.length), modelPath)) {
131131
return state;
132132
}
133133

src/reducers/model-reducer.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import _get from '../utils/get';
22
import icepick from 'icepick';
3-
import isEqual from 'lodash/isEqual';
3+
import arraysEqual from '../utils/arrays-equal';
44
import toPath from '../utils/to-path';
55

66
import actionTypes from '../action-types';
@@ -20,7 +20,7 @@ function createModeler(getter = _get, setter = icepickSet, initialModelState = {
2020

2121
const path = toPath(action.model);
2222

23-
if (!isEqual(path.slice(0, modelPath.length), modelPath)) {
23+
if (!arraysEqual(path.slice(0, modelPath.length), modelPath)) {
2424
return state;
2525
}
2626

@@ -36,7 +36,7 @@ function createModeler(getter = _get, setter = icepickSet, initialModelState = {
3636
return action.value;
3737
}
3838

39-
if (isEqual(getter(state, localPath), action.value)) {
39+
if (getter(state, localPath) === action.value) {
4040
return state;
4141
}
4242

@@ -47,7 +47,7 @@ function createModeler(getter = _get, setter = icepickSet, initialModelState = {
4747
return initialState;
4848
}
4949

50-
if (isEqual(getter(state, localPath), getter(initialState, localPath))) {
50+
if (getter(state, localPath) === getter(initialState, localPath)) {
5151
return state;
5252
}
5353

src/utils/arrays-equal.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export default function arraysEqual(firstArray, secondArray) {
2+
return firstArray && secondArray
3+
&& firstArray.length === secondArray.length
4+
&& firstArray.every((item, index) => item === secondArray[index]);
5+
}

src/utils/sequence.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import identity from 'lodash/identity';
22
import capitalize from '../utils/capitalize';
33
import mapValues from '../utils/map-values';
44
import compose from 'redux/lib/compose';
5-
import isEqual from 'lodash/isEqual';
65
import merge from '../utils/merge';
76
import icepick from 'icepick';
87

@@ -33,7 +32,8 @@ const modelValueUpdaterMap = {
3332

3433
if (isMulti(model)) {
3534
const valueWithItem = modelValue || [];
36-
const valueWithoutItem = (valueWithItem || []).filter(item => !isEqual(item, eventValue));
35+
const valueWithoutItem = (valueWithItem || [])
36+
.filter(item => item !== eventValue);
3737
const value = (valueWithoutItem.length === valueWithItem.length)
3838
? icepick.push(valueWithItem, eventValue)
3939
: valueWithoutItem;

test/model-actions-spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ describe('model actions', () => {
111111
},
112112
{
113113
init: { foo: ['primitive', { a: 'b' }] },
114-
params: ['test.foo', { a: 'b' }],
114+
params: ['test.foo', { a: 'b' }, (item) => item.a === 'b'],
115115
expected: { foo: ['primitive'] },
116116
},
117117
],

0 commit comments

Comments
 (0)