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

Add shapeFromPropTypes utility for passed props

parent 767721be
No related merge requests found
...@@ -5,6 +5,7 @@ const VM = require('scratch-vm'); ...@@ -5,6 +5,7 @@ const VM = require('scratch-vm');
const VMManager = require('../lib/vm-manager'); const VMManager = require('../lib/vm-manager');
const MediaLibrary = require('../lib/media-library'); const MediaLibrary = require('../lib/media-library');
const shapeFromPropTypes = require('../lib/shape-from-prop-types');
const Blocks = require('./blocks.jsx'); const Blocks = require('./blocks.jsx');
const GUIComponent = require('../components/gui.jsx'); const GUIComponent = require('../components/gui.jsx');
...@@ -60,30 +61,30 @@ class GUI extends React.Component { ...@@ -60,30 +61,30 @@ class GUI extends React.Component {
vm, vm,
...guiProps ...guiProps
} = this.props; } = this.props;
backdropLibraryProps = defaultsDeep({}, backdropLibraryProps, {
mediaLibrary: this.mediaLibrary,
onRequestClose: this.closeModal,
visible: this.state.currentModal === 'backdrop-library'
});
blocksProps = defaultsDeep({}, blocksProps, { blocksProps = defaultsDeep({}, blocksProps, {
options: { options: {
media: `${basePath}static/blocks-media/` media: `${basePath}static/blocks-media/`
} }
}); });
spriteSelectorProps = defaultsDeep({}, spriteSelectorProps, {
openNewBackdrop: () => this.openModal('backdrop-library'),
openNewCostume: () => this.openModal('costume-library'),
openNewSprite: () => this.openModal('sprite-library')
});
spriteLibraryProps = defaultsDeep({}, spriteLibraryProps, {
mediaLibrary: this.mediaLibrary,
onRequestClose: this.closeModal,
visible: this.state.currentModal === 'sprite-library'
});
costumeLibraryProps = defaultsDeep({}, costumeLibraryProps, { costumeLibraryProps = defaultsDeep({}, costumeLibraryProps, {
mediaLibrary: this.mediaLibrary, mediaLibrary: this.mediaLibrary,
onRequestClose: this.closeModal, onRequestClose: this.closeModal,
visible: this.state.currentModal === 'costume-library' visible: this.state.currentModal === 'costume-library'
}); });
backdropLibraryProps = defaultsDeep({}, backdropLibraryProps, { spriteLibraryProps = defaultsDeep({}, spriteLibraryProps, {
mediaLibrary: this.mediaLibrary, mediaLibrary: this.mediaLibrary,
onRequestClose: this.closeModal, onRequestClose: this.closeModal,
visible: this.state.currentModal === 'backdrop-library' visible: this.state.currentModal === 'sprite-library'
});
spriteSelectorProps = defaultsDeep({}, spriteSelectorProps, {
openNewBackdrop: () => this.openModal('backdrop-library'),
openNewCostume: () => this.openModal('costume-library'),
openNewSprite: () => this.openModal('sprite-library')
}); });
if (this.props.children) { if (this.props.children) {
return ( return (
...@@ -110,17 +111,17 @@ class GUI extends React.Component { ...@@ -110,17 +111,17 @@ class GUI extends React.Component {
} }
GUI.propTypes = { GUI.propTypes = {
backdropLibraryProps: React.PropTypes.shape(BackdropLibrary.propTypes), backdropLibraryProps: shapeFromPropTypes(BackdropLibrary.propTypes, {omit: ['vm']}),
basePath: React.PropTypes.string, basePath: React.PropTypes.string,
blocksProps: React.PropTypes.shape(Blocks.propTypes), blocksProps: shapeFromPropTypes(Blocks.propTypes, {omit: ['vm']}),
children: React.PropTypes.node, children: React.PropTypes.node,
costumeLibraryProps: React.PropTypes.shape(CostumeLibrary.propTypes), costumeLibraryProps: shapeFromPropTypes(CostumeLibrary.propTypes, {omit: ['vm']}),
greenFlagProps: React.PropTypes.shape(GreenFlag.propTypes), greenFlagProps: shapeFromPropTypes(GreenFlag.propTypes, {omit: ['vm']}),
projectData: React.PropTypes.string, projectData: React.PropTypes.string,
spriteLibraryProps: React.PropTypes.shape(SpriteLibrary.propTypes), spriteLibraryProps: shapeFromPropTypes(SpriteLibrary.propTypes, {omit: ['vm']}),
spriteSelectorProps: React.PropTypes.shape(SpriteSelector.propTypes), spriteSelectorProps: shapeFromPropTypes(SpriteSelector.propTypes, {omit: ['vm']}),
stageProps: React.PropTypes.shape(Stage.propTypes), stageProps: shapeFromPropTypes(Stage.propTypes, {omit: ['vm']}),
stopAllProps: React.PropTypes.shape(StopAll.propTypes), stopAllProps: shapeFromPropTypes(StopAll.propTypes, {omit: ['vm']}),
vm: React.PropTypes.instanceOf(VM), vm: React.PropTypes.instanceOf(VM),
}; };
......
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