Skip to content
Snippets Groups Projects
Commit b85c61a6 authored by Ray Schamp's avatar Ray Schamp
Browse files

YAGNI: Remove clutter from GUI component

parent f9970d6c
No related branches found
No related tags found
No related merge requests found
const defaultsDeep = require('lodash.defaultsdeep');
const React = require('react'); const React = require('react');
const VM = require('scratch-vm'); const VM = require('scratch-vm');
const shapeFromPropTypes = require('../../lib/shape-from-prop-types');
const Blocks = require('../../containers/blocks.jsx'); const Blocks = require('../../containers/blocks.jsx');
const GreenFlag = require('../../containers/green-flag.jsx'); const GreenFlag = require('../../containers/green-flag.jsx');
const TargetPane = require('../../containers/target-pane.jsx'); const TargetPane = require('../../containers/target-pane.jsx');
...@@ -13,24 +10,15 @@ const StopAll = require('../../containers/stop-all.jsx'); ...@@ -13,24 +10,15 @@ const StopAll = require('../../containers/stop-all.jsx');
const Box = require('../box/box.jsx'); const Box = require('../box/box.jsx');
const GUIComponent = props => { const GUIComponent = props => {
let { const {
basePath, basePath,
blocksProps,
children, children,
greenFlagProps, vm,
targetPaneProps, ...componentProps
stageProps,
stopAllProps,
vm
} = props; } = props;
blocksProps = defaultsDeep({}, blocksProps, {
options: {
media: `${basePath}static/blocks-media/`
}
});
if (children) { if (children) {
return ( return (
<Box> <Box {...componentProps}>
{children} {children}
</Box> </Box>
); );
...@@ -40,6 +28,7 @@ const GUIComponent = props => { ...@@ -40,6 +28,7 @@ const GUIComponent = props => {
grow={1} grow={1}
height="100%" height="100%"
style={{overflow: 'hidden'}} style={{overflow: 'hidden'}}
{...componentProps}
> >
<Box <Box
direction="column" direction="column"
...@@ -55,8 +44,10 @@ const GUIComponent = props => { ...@@ -55,8 +44,10 @@ const GUIComponent = props => {
/> />
<Blocks <Blocks
grow={1} grow={1}
options={{
media: `${basePath}static/blocks-media/`
}}
vm={vm} vm={vm}
{...blocksProps}
/> />
</Box> </Box>
<Box <Box
...@@ -72,24 +63,16 @@ const GUIComponent = props => { ...@@ -72,24 +63,16 @@ const GUIComponent = props => {
marginTop: 8 marginTop: 8
}} }}
> >
<GreenFlag <GreenFlag vm={vm} />
vm={vm} <StopAll vm={vm} />
{...greenFlagProps}
/>
<StopAll
vm={vm}
{...stopAllProps}
/>
</Box> </Box>
<Stage <Stage
shrink={0} shrink={0}
vm={vm} vm={vm}
{...stageProps}
/> />
<TargetPane <TargetPane
grow={1} grow={1}
vm={vm} vm={vm}
{...targetPaneProps}
/> />
</Box> </Box>
</Box> </Box>
...@@ -97,21 +80,11 @@ const GUIComponent = props => { ...@@ -97,21 +80,11 @@ const GUIComponent = props => {
}; };
GUIComponent.propTypes = { GUIComponent.propTypes = {
basePath: React.PropTypes.string, basePath: React.PropTypes.string,
blocksProps: shapeFromPropTypes(Blocks.propTypes, {omit: ['vm']}),
children: React.PropTypes.node, children: React.PropTypes.node,
greenFlagProps: shapeFromPropTypes(GreenFlag.propTypes, {omit: ['vm']}),
stageProps: shapeFromPropTypes(Stage.propTypes, {omit: ['vm']}),
stopAllProps: shapeFromPropTypes(StopAll.propTypes, {omit: ['vm']}),
targetPaneProps: shapeFromPropTypes(TargetPane.propTypes, {omit: ['vm']}),
vm: React.PropTypes.instanceOf(VM) vm: React.PropTypes.instanceOf(VM)
}; };
GUIComponent.defaultProps = { GUIComponent.defaultProps = {
basePath: '/', basePath: '/',
blocksProps: {},
greenFlagProps: {},
targetPaneProps: {},
stageProps: {},
stopAllProps: {},
vm: new VM() vm: new VM()
}; };
module.exports = GUIComponent; module.exports = GUIComponent;
const React = require('react');
module.exports = function shapeFromPropTypes (propTypes, opts) {
opts = Object.assign({}, opts, {omit: []});
const shape = Object
.keys(propTypes)
.filter(key => opts.omit.indexOf(key) !== -1)
.reduce((newPropTypes, key) => {
newPropTypes[key] = propTypes[key];
return newPropTypes;
}, {});
return React.PropTypes.shape(shape);
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment