Calculated state should override raw state.

This commit is contained in:
Matt Swensen 2018-10-27 20:37:42 -06:00
parent f30e053593
commit 061a24b593
No known key found for this signature in database
GPG Key ID: 3F9E482BFC526F35

@ -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;
}