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

Commit 096b2bb

Browse files
committed
(WIP) deprecating use of redux-thunk internally
1 parent e93fe2e commit 096b2bb

File tree

4 files changed

+30
-12
lines changed

4 files changed

+30
-12
lines changed

src/actions/model-actions.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,7 @@ export function createModelActions(s = defaultStrategies) {
8585

8686
const toggle = createModifierAction((value) => !value, undefined, 1);
8787

88-
const check = (model, value) => (dispatch, getState) => {
89-
const modelValue = s.get(getState(), model);
90-
88+
const checkWithValue = (model, value, modelValue) => {
9189
if (isMulti(model)) {
9290
const valueWithItem = modelValue || s.array;
9391
const valueWithoutItem = (valueWithItem || s.array)
@@ -96,10 +94,18 @@ export function createModelActions(s = defaultStrategies) {
9694
? s.push(valueWithItem, value)
9795
: valueWithoutItem;
9896

99-
dispatch(change(model, multiValue));
100-
} else {
101-
dispatch(change(model, !modelValue));
97+
return change(model, multiValue);
10298
}
99+
100+
return change(model, !modelValue);
101+
};
102+
103+
const check = (model, value) => (dispatch, getState) => {
104+
const modelValue = s.get(getState(), model);
105+
106+
const action = checkWithValue(model, value, modelValue);
107+
108+
dispatch(action);
103109
};
104110

105111
const filter = createModifierAction((value, iteratee) => value.filter(iteratee), s.array, 2);
@@ -151,6 +157,7 @@ export function createModelActions(s = defaultStrategies) {
151157
push,
152158
toggle,
153159
check,
160+
checkWithValue,
154161
filter,
155162
reset,
156163
map,

src/components/control-component.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ function createControlClass(customControlPropsMap = {}, s = defaultStrategy) {
173173
const keys = Object.keys(validators)
174174
.concat(Object.keys(errors));
175175

176-
dispatch(actions.resetValidity(model, keys));
176+
dispatch(actions.setValidity(model, omit(fieldValue.validity, keys)));
177177
}
178178
}
179179

@@ -207,13 +207,14 @@ function createControlClass(customControlPropsMap = {}, s = defaultStrategy) {
207207
getChangeAction(event) {
208208
const {
209209
model,
210+
modelValue,
210211
changeAction,
211212
} = this.props;
212213
const value = this.readOnlyValue
213214
? getReadOnlyValue(this.props)
214215
: event;
215216

216-
return changeAction(model, getValue(value));
217+
return changeAction(model, getValue(value), modelValue);
217218
}
218219

219220
getValidateAction(value, eventName) {
@@ -651,7 +652,7 @@ function createControlClass(customControlPropsMap = {}, s = defaultStrategy) {
651652
...controlPropsMap.checkbox,
652653
...props.mapProps,
653654
}}
654-
changeAction={props.changeAction || s.actions.check}
655+
changeAction={props.changeAction || s.actions.checkWithValue}
655656
{...omit(props, 'mapProps')}
656657
/>
657658
);

src/components/field-component.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ function createFieldClass(customControlPropsMap = {}, s = defaultStrategy) {
126126
// TODO: refactor
127127
const defaultControlPropsMap = {
128128
checkbox: {
129-
changeAction: s.actions.check,
129+
changeAction: s.actions.checkWithValue,
130130
},
131131
};
132132

src/components/form-component.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,10 +284,20 @@ function createFormClass(s = defaultStrategy) {
284284
? merge(invertValidators(validators), errorValidators)
285285
: errorValidators;
286286

287+
const fieldsValidity = mapValues(finalErrorValidators, (validator, field) => {
288+
const fieldValue = field
289+
? s.get(modelValue, field)
290+
: modelValue;
291+
292+
const fieldValidity = getValidity(validator, fieldValue);
293+
294+
return fieldValidity;
295+
});
296+
287297
dispatch(s.actions.batch(model, [
288-
s.actions.validateFieldsErrors(
298+
s.actions.setFieldsErrors(
289299
model,
290-
finalErrorValidators
300+
fieldsValidity
291301
),
292302
s.actions.addIntent(model, { type: 'submit' }),
293303
]));

0 commit comments

Comments
 (0)