Skip to content

Commit

Permalink
reorganize code to need fewer null checks and qualified state accesse…
Browse files Browse the repository at this point in the history
…s (like `state.property` instead of `property` after having destructured `state`)
  • Loading branch information
SillyFreak committed May 20, 2020
1 parent fc7bc43 commit 6acd5cc
Showing 1 changed file with 14 additions and 17 deletions.
31 changes: 14 additions & 17 deletions src/components/ide/Ide/Ide.js
Expand Up @@ -754,12 +754,21 @@ function Ide({ projectName }: Props) {
}
}

function factory(node: any): React.Node {
// eslint-disable-next-line no-throw-literal
if (projectInfo === null || state === null) throw 'unreachable';
const projectSettingsPopupState = usePopupState({
variant: 'popover',
popupId: 'project-controls-menu',
});

useStyles(FlexLayoutTheme);
const classes = useStylesMaterial();

if (projectInfo === null || state === null) return null;

const { fileTreeState, editorStates, showMetadataFolder } = state;

function factory(node: any): React.Node {
const getEditorState = (path: string, editorType: string) => {
const editorState = state.editorStates[path];
const editorState = editorStates[path];
return editorState ? editorState[editorType] : null;
};

Expand Down Expand Up @@ -828,24 +837,12 @@ function Ide({ projectName }: Props) {
}
}

const projectSettingsPopupState = usePopupState({
variant: 'popover',
popupId: 'project-controls-menu',
});

useStyles(FlexLayoutTheme);
const classes = useStylesMaterial();

if (projectInfo === null || state === null) return null;

function filter(path: string, child: FilerRecursiveStatInfo): boolean {
if (path === '.' && child.name === '.metadata' && !state.showMetadataFolder)
if (path === '.' && child.name === '.metadata' && !showMetadataFolder)
return false;
return true;
}

const { fileTreeState, showMetadataFolder } = state;

return (
<Grid className={classes.root} container direction="row" wrap="nowrap">
<Grid
Expand Down

0 comments on commit 6acd5cc

Please sign in to comment.