check for action type in application reducer

Summary: Previously, accidentally all action payloads have been written to the application reducer, because it didn't check the action type. Now, this diff makes sure, the application reducer checks for the action type and only writes actions to the store which are meant for the reducer.

Reviewed By: jknoxville

Differential Revision: D9179305

fbshipit-source-id: 833776468ed32e0385058571130e81eff06c370e
This commit is contained in:
Daniel Büchele
2018-08-06 06:19:31 -07:00
committed by Facebook Github Bot
parent 5fd1ebba2e
commit de800fee37

View File

@@ -42,19 +42,29 @@ export default function reducer(
state: State = INITIAL_STATE,
action: Action,
): State {
const newValue =
typeof action.payload === 'undefined'
? !state[action.type]
: action.payload;
if (state[action.type] === newValue) {
// value hasn't changed, do nothing
const {payload, type} = action;
const newValue = typeof payload === 'undefined' ? !state[type] : payload;
if (
type === 'leftSidebarVisible' ||
type === 'rightSidebarVisible' ||
type === 'rightSidebarAvailable' ||
type === 'bugDialogVisible' ||
type === 'windowIsFocused' ||
type === 'pluginManagerVisible'
) {
if (state[type] === newValue) {
// value hasn't changed
return state;
} else {
return {
...state,
[action.type]: newValue,
[type]: newValue,
};
}
} else {
return state;
}
}
export const toggleAction = (type: ActionType, payload?: boolean): Action => ({