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
This commit is contained in:
Pascal Hartig
2018-10-25 12:52:25 -07:00
committed by Facebook Github Bot
parent 1be54ebee1
commit 2f307b8b4f

View File

@@ -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;