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

Commit ff7c958

Browse files
committed
Adding options for change action
1 parent 822dca9 commit ff7c958

File tree

4 files changed

+20
-8
lines changed

4 files changed

+20
-8
lines changed

src/actions/model-actions.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,21 @@ function isMulti(model) {
1717
return endsWith(model, '[]');
1818
}
1919

20-
const change = (model, value) => ({
21-
type: actionTypes.CHANGE,
22-
model,
23-
multi: isMulti(model),
24-
value: getValue(value),
25-
});
20+
const change = (model, value, options = {}) => {
21+
// option defaults
22+
const changeOptions = {
23+
silent: false,
24+
multi: isMulti(model),
25+
...options,
26+
};
27+
28+
return {
29+
type: actionTypes.CHANGE,
30+
model,
31+
value: getValue(value),
32+
...changeOptions,
33+
};
34+
};
2635

2736
const xor = (model, item) => (dispatch, getState) => {
2837
const state = _get(getState(), model, []);

src/reducers/form-reducer.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ function getField(state, path) {
4242
' from an invalid/empty form state. Must pass in a valid form state as the first argument.');
4343
}
4444

45-
const localPath = toPath(path);
45+
const localPath = typeof path === 'function'
46+
? path(state)
47+
: toPath(path);
4648

4749
if (!localPath.length) {
4850
return state;

test/actions-spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { actions, actionTypes } from '../src';
44
describe('model action creators', () => {
55
describe('actions.change()', () => {
66
it('should return an action', () => {
7-
assert.deepEqual(
7+
assert.containSubset(
88
actions.change('foo.bar', 'baz'),
99
{
1010
model: 'foo.bar',

test/batched-actions-spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ describe('batched actions', (done) => {
2323
{
2424
model: 'test.foo',
2525
multi: false,
26+
silent: false,
2627
type: 'rrf/change',
2728
value: 'testing',
2829
},

0 commit comments

Comments
 (0)