My problem is this: I just can't understand why I'd want to manipulate state in an unsightly switch statement like this one from Chapter 4 of the original post:
switch (action.type) {
case 'CHANGE_LOCATION':
return Object.assign({}, state, {
location: action.location
});
case 'SET_SELECTED_TEMP':
return Object.assign({}, state, {
selected: {
temp: action.temp,
date: state.selected.date
}
});
case 'SET_SELECTED_DATE':
return Object.assign({}, state, {
selected: {
date: action.date,
temp: state.selected.temp
}
});
default:
return state;
}
This reminds me of Win32 event loops with their window message handler switches... And that's a scary association.What's the point with dispatching these fragile "stringly-typed" selectors, when you can just have real functions doing setState() updates on the relevant component?
I'm not trying to be snarky -- I know I'm missing something major here.