Calculated state should override raw state.
This commit is contained in:
parent
f30e053593
commit
061a24b593
@ -1,23 +1,21 @@
|
||||
import { has, get } from 'lodash';
|
||||
import { has, get, merge } from 'lodash';
|
||||
|
||||
export default function getValueOrFallback(state, calculatedState, fallbackState, paths, parse) {
|
||||
const combinedState = merge({}, state, calculatedState);
|
||||
for (let path of paths) {
|
||||
if (has(state, path)) {
|
||||
if (has(combinedState, path)) {
|
||||
if (parse) {
|
||||
try {
|
||||
return parse(get(state, path));
|
||||
return parse(get(combinedState, path));
|
||||
}
|
||||
catch {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return get(state, path);
|
||||
return get(combinedState, path);
|
||||
}
|
||||
}
|
||||
else if (has(calculatedState, path)) {
|
||||
return get(calculatedState, path);
|
||||
}
|
||||
else {
|
||||
continue;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user