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

Commit 1611b7f

Browse files
committed
Allow deep loading. Fixes #571
1 parent 75ccb58 commit 1611b7f

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ function updateFieldValue(field, action, parentModel = undefined) {
8686
return updateFieldValue(subField, {
8787
model: index,
8888
value: subValue,
89+
load,
8990
}, parentModel ? `${parentModel}.${model}` : model);
9091
}
9192

test/control-component-spec.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import React from 'react';
44
import ReactDOM from 'react-dom';
55
import TestUtils from 'react-addons-test-utils';
66
import { Provider } from 'react-redux';
7+
import { createStore } from 'redux';
78
import sinon from 'sinon';
89
import capitalize from '../src/utils/capitalize';
910
import _get from 'lodash.get';
@@ -19,13 +20,15 @@ import {
1920
formReducer as _formReducer,
2021
Control as _Control,
2122
actions as _actions,
23+
combineForms as _combineForms,
2224
} from '../src';
2325
import {
2426
controls as immutableControls,
2527
modelReducer as immutableModelReducer,
2628
formReducer as immutableFormReducer,
2729
Control as immutableControl,
2830
actions as immutableActions,
31+
combineForms as immutableCombineForms,
2932
} from '../immutable';
3033

3134
const testContexts = {
@@ -39,6 +42,7 @@ const testContexts = {
3942
get: _get,
4043
set: (state, path, value) => i.setIn(state, path, value),
4144
getInitialState: (state) => state,
45+
combineForms: _combineForms,
4246
},
4347
immutable: {
4448
controls: immutableControls,
@@ -57,6 +61,7 @@ const testContexts = {
5761
},
5862
set: (state, path, value) => state.setIn(path, value),
5963
getInitialState: (state) => Immutable.fromJS(state),
64+
combineForms: immutableCombineForms,
6065
},
6166
};
6267

@@ -70,6 +75,7 @@ Object.keys(testContexts).forEach((testKey) => {
7075
const object = testContext.object;
7176
const get = testContext.get;
7277
const getInitialState = testContext.getInitialState;
78+
const combineForms = testContext.combineForms;
7379

7480
describe(`<Control> component (${testKey} context)`, () => {
7581
describe('existence check', () => {
@@ -948,6 +954,36 @@ Object.keys(testContexts).forEach((testKey) => {
948954
});
949955
});
950956

957+
describe('deep initial value after reset', () => {
958+
const store = createStore(combineForms({
959+
user: getInitialState({
960+
nest: {
961+
name: 'initial name',
962+
email: 'initial email',
963+
},
964+
}),
965+
}));
966+
967+
TestUtils.renderIntoDocument(
968+
<Provider store={store}>
969+
<div>
970+
<Control.text model="user.nest.name" />
971+
<Control.text type="email" model="user.nest.email" />
972+
</div>
973+
</Provider>
974+
);
975+
976+
it('should reset the control to the last deeply loaded value', () => {
977+
store.dispatch(actions.load('user', getInitialState({
978+
nest: { name: 'loaded name', email: 'loaded email' },
979+
})));
980+
store.dispatch(actions.reset('user'));
981+
982+
assert.equal(get(store.getState().user, 'nest.name'), 'loaded name');
983+
assert.equal(get(store.getState().user, 'nest.email'), 'loaded email');
984+
});
985+
});
986+
951987
describe('errors property', () => {
952988
const reducer = formReducer('test');
953989

0 commit comments

Comments
 (0)