egghead.io_idiomatic_redux_course_notes
egghead.io_idiomatic_redux_course_notes copied to clipboard
Is there an potential bug with the Reducers in Section 26
In 26. Normalizing API Responses with normalizer
The byId Reducer goes from
switch (action.type) {
case 'FETCH_TODOS_SUCCESS': // eslint-disable-line no-case-declarations
const nextState = { ...state };
action.response.forEach(todo => {
nextState[todo.id] = todo;
});
return nextState;
case 'ADD_TODO_SUCCESS':
return {
...state,
[action.response.id]: action.response,
};
default:
return state;
}
};
to
const byId = (state = {}, action) => {
if (action.response) {
return {
...state,
...action.response.entities.todos,
};
}
return state;
};
However my understanding is that ALL the actions are taken thru ALL the reducers.
So by removing the check for Action Type of 'FETCH_TODOS_SUCCESS' and 'ADD_TODO_SUCCESS' and simply checking if the action contains a response field, then I'm thinking, that what if our system has some other unrelated action that also returns a promise with a response field, and so in that scenario, our byId Reducer would also attempt to handle this unrelated action, which would be a bug.
Am I correct here, or have I missed something?