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

Commit 3948e06

Browse files
committed
Ensuring that result from actions.remove retains field state as object. Fixes #553
1 parent fe5a7d8 commit 3948e06

File tree

4 files changed

+51
-1
lines changed

4 files changed

+51
-1
lines changed

docs/api/Control.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
- [`controlProps`](#prop-controlProps)
1515
- [`component`](#prop-component)
1616
- [`ignore`](#prop-ignore)
17+
- [`disabled`](#disabled)
1718

1819
## `<Control>`
1920

examples/quick-start/components/user-form.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import React from 'react';
22
import { LocalForm, Form, actions, Control, Field, Errors } from 'react-redux-form';
33
import { connect } from 'react-redux';
4+
import icepick from 'icepick';
5+
6+
window.i = icepick;
47

58
const required = (val) => !!(val && val.length);
69

src/reducers/form/change-action-reducer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ function updateFieldValue(field, action, parentModel = undefined) {
5151
result[key] = field[key];
5252
});
5353

54-
return i.set(compact(result), '$form', field.$form);
54+
return { ...i.set(compact(result), '$form', field.$form) };
5555
}
5656

5757
result = { ...field };

test/actions-spec.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,52 @@ describe('model action creators', () => {
244244

245245
fn(dispatch, getState);
246246
});
247+
248+
it('should remove from collections of complex values', (done) => {
249+
const getState = () => ({
250+
foo: {
251+
bar: [
252+
{ value: 1 },
253+
{ value: 2 },
254+
{ value: 3 },
255+
{ value: 4 },
256+
],
257+
},
258+
});
259+
260+
const getNextState = () => ({
261+
foo: {
262+
bar: [
263+
{ value: 1 },
264+
{ value: 2 },
265+
{ value: 4 },
266+
],
267+
},
268+
});
269+
270+
const nextDispatch = action => {
271+
done(assert.deepEqual(
272+
action.value,
273+
[
274+
{ value: 1 },
275+
{ value: 2 },
276+
]));
277+
};
278+
279+
const dispatch = action => {
280+
assert.deepEqual(
281+
action.value,
282+
[
283+
{ value: 1 },
284+
{ value: 2 },
285+
{ value: 4 },
286+
]);
287+
288+
actions.remove('foo.bar', 2)(nextDispatch, getNextState);
289+
};
290+
291+
actions.remove('foo.bar', 2)(dispatch, getState);
292+
});
247293
});
248294

249295
describe('actions.move() thunk', () => {

0 commit comments

Comments
 (0)