From 2f307b8b4f8ee156079de17c0741915e1844fd6f Mon Sep 17 00:00:00 2001 From: Pascal Hartig Date: Thu, 25 Oct 2018 12:52:25 -0700 Subject: [PATCH] Avoid import-time side effects for application Summary: `INITIAL_STATE` is defined at import-time and relies on `remote.getCurrentWindow()`, which means that any import from the `flipper` module will require a display server + electron running. Happy to take alternative suggestions to make this look a bit less intrusive. Reviewed By: danielbuechele Differential Revision: D10507539 fbshipit-source-id: 62b6bff0b4fd40638e54328613de4d3821b69dd6 --- src/reducers/application.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/reducers/application.js b/src/reducers/application.js index e550e0ccc..c2fc6eb93 100644 --- a/src/reducers/application.js +++ b/src/reducers/application.js @@ -29,19 +29,17 @@ export type Action = { payload?: boolean, }; -const INITIAL_STATE: State = { +const initialState: () => State = () => ({ leftSidebarVisible: true, rightSidebarVisible: true, rightSidebarAvailable: false, bugDialogVisible: false, windowIsFocused: remote.getCurrentWindow().isFocused(), pluginManagerVisible: false, -}; +}); -export default function reducer( - state: State = INITIAL_STATE, - action: Action, -): State { +export default function reducer(state: State, action: Action): State { + state = state || initialState(); const {payload, type} = action; const newValue = typeof payload === 'undefined' ? !state[type] : payload;