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) {
|
export default function getValueOrFallback(state, calculatedState, fallbackState, paths, parse) {
|
||||||
|
const combinedState = merge({}, state, calculatedState);
|
||||||
for (let path of paths) {
|
for (let path of paths) {
|
||||||
if (has(state, path)) {
|
if (has(combinedState, path)) {
|
||||||
if (parse) {
|
if (parse) {
|
||||||
try {
|
try {
|
||||||
return parse(get(state, path));
|
return parse(get(combinedState, path));
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return get(state, path);
|
return get(combinedState, path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (has(calculatedState, path)) {
|
|
||||||
return get(calculatedState, path);
|
|
||||||
}
|
|
||||||
else {
|
else {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user