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:
committed by
Facebook Github Bot
parent
5fd1ebba2e
commit
de800fee37
@@ -42,18 +42,28 @@ export default function reducer(
|
|||||||
state: State = INITIAL_STATE,
|
state: State = INITIAL_STATE,
|
||||||
action: Action,
|
action: Action,
|
||||||
): State {
|
): State {
|
||||||
const newValue =
|
const {payload, type} = action;
|
||||||
typeof action.payload === 'undefined'
|
const newValue = typeof payload === 'undefined' ? !state[type] : payload;
|
||||||
? !state[action.type]
|
|
||||||
: action.payload;
|
if (
|
||||||
if (state[action.type] === newValue) {
|
type === 'leftSidebarVisible' ||
|
||||||
// value hasn't changed, do nothing
|
type === 'rightSidebarVisible' ||
|
||||||
return state;
|
type === 'rightSidebarAvailable' ||
|
||||||
|
type === 'bugDialogVisible' ||
|
||||||
|
type === 'windowIsFocused' ||
|
||||||
|
type === 'pluginManagerVisible'
|
||||||
|
) {
|
||||||
|
if (state[type] === newValue) {
|
||||||
|
// value hasn't changed
|
||||||
|
return state;
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
[type]: newValue,
|
||||||
|
};
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return {
|
return state;
|
||||||
...state,
|
|
||||||
[action.type]: newValue,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user