From de800fee3749792df1028b53383548a08f1babf8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20B=C3=BCchele?= Date: Mon, 6 Aug 2018 06:19:31 -0700 Subject: [PATCH] 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 --- src/reducers/application.js | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/src/reducers/application.js b/src/reducers/application.js index 528847deb..e550e0ccc 100644 --- a/src/reducers/application.js +++ b/src/reducers/application.js @@ -42,18 +42,28 @@ 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 - return state; + 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, + [type]: newValue, + }; + } } else { - return { - ...state, - [action.type]: newValue, - }; + return state; } }