From 72c7c91b2785e8ad043252902532d30647e19ab8 Mon Sep 17 00:00:00 2001 From: casperlamboo Date: Thu, 16 Nov 2017 14:54:47 +0100 Subject: [PATCH] mov static functions --- src/interface/Settings.js | 39 ++++++++++++-------------- src/interface/index.js | 58 ++++++++++++++++++++------------------- 2 files changed, 48 insertions(+), 49 deletions(-) diff --git a/src/interface/Settings.js b/src/interface/Settings.js index c2e0cb8..281084f 100644 --- a/src/interface/Settings.js +++ b/src/interface/Settings.js @@ -14,15 +14,24 @@ const styles = { }; class Settings extends React.Component { - constructor(props) { - super(props); - this.state = { - settings: props.initialSettings, - printers: props.defaultPrinter, - quality: props.defaultQuality, - material: props.defaultMaterial - }; - } + static childContextTypes = { state: PropTypes.object, onChange: PropTypes.func }; + static propTypes = { + classes: PropTypes.objectOf(PropTypes.string), + onChange: PropTypes.func, + printers: PropTypes.object.isRequired, + defaultPrinter: PropTypes.string.isRequired, + quality: PropTypes.object.isRequired, + defaultQuality: PropTypes.string.isRequired, + material: PropTypes.object.isRequired, + defaultMaterial: PropTypes.string.isRequired, + initialSettings: PropTypes.object.isRequired + }; + state = { + settings: props.initialSettings, + printers: props.defaultPrinter, + quality: props.defaultQuality, + material: props.defaultMaterial + }; changeSettings = (fieldName, value) => { const { onChange } = this.props; @@ -141,17 +150,5 @@ class Settings extends React.Component { ); } } -Settings.childContextTypes = { state: PropTypes.object, onChange: PropTypes.func }; -Settings.propTypes = { - classes: PropTypes.objectOf(PropTypes.string), - onChange: PropTypes.func, - printers: PropTypes.object.isRequired, - defaultPrinter: PropTypes.string.isRequired, - quality: PropTypes.object.isRequired, - defaultQuality: PropTypes.string.isRequired, - material: PropTypes.object.isRequired, - defaultMaterial: PropTypes.string.isRequired, - initialSettings: PropTypes.object.isRequired -}; export default injectSheet(styles)(Settings); diff --git a/src/interface/index.js b/src/interface/index.js index 7ebce0a..fbb45cb 100644 --- a/src/interface/index.js +++ b/src/interface/index.js @@ -64,6 +64,35 @@ const styles = { }; class Interface extends React.Component { + static propTypes = { + geometry(props, propName) { + if (!(props[propName].isGeometry || props[propName].isBufferGeometry)) { + throw new Error('invalid prop, is not geometry'); + } + }, + classes: PropTypes.objectOf(PropTypes.string), + onCompleteActions: PropTypes.arrayOf(PropTypes.shape({ title: PropTypes.string, callback: PropTypes.func })).isRequired, + defaultSettings: PropTypes.object.isRequired, + printers: PropTypes.object.isRequired, + defaultPrinter: PropTypes.string.isRequired, + quality: PropTypes.object.isRequired, + defaultQuality: PropTypes.string.isRequired, + material: PropTypes.object.isRequired, + defaultMaterial: PropTypes.string.isRequired, + pixelRatio: PropTypes.number.isRequired + }; + + static defaultProps = { + defaultSettings: baseSettings, + printers: printerSettings, + defaultPrinter: 'ultimaker2', + quality: qualitySettings, + defaultQuality: 'medium', + material: materialSettings, + defaultMaterial: 'pla', + pixelRatio: 1 + }; + constructor(props) { super(props); const { defaultPrinter, defaultQuality, defaultMaterial, printers, quality, material, defaultSettings } = props; @@ -87,7 +116,7 @@ class Interface extends React.Component { componentDidMount() { const { canvas } = this.refs; const scene = createScene(canvas, this.props, this.state); - this.setState(scene); + this.setState({ ...scene }); } resetMesh = () => { @@ -243,32 +272,5 @@ class Interface extends React.Component { ); } } -Interface.propTypes = { - geometry(props, propName) { - if (!(props[propName].isGeometry || props[propName].isBufferGeometry)) { - throw new Error('invalid prop, is not geometry'); - } - }, - classes: PropTypes.objectOf(PropTypes.string), - onCompleteActions: PropTypes.arrayOf(PropTypes.shape({ title: PropTypes.string, callback: PropTypes.func })).isRequired, - defaultSettings: PropTypes.object.isRequired, - printers: PropTypes.object.isRequired, - defaultPrinter: PropTypes.string.isRequired, - quality: PropTypes.object.isRequired, - defaultQuality: PropTypes.string.isRequired, - material: PropTypes.object.isRequired, - defaultMaterial: PropTypes.string.isRequired, - pixelRatio: PropTypes.number.isRequired -}; -Interface.defaultProps = { - defaultSettings: baseSettings, - printers: printerSettings, - defaultPrinter: 'ultimaker2', - quality: qualitySettings, - defaultQuality: 'medium', - material: materialSettings, - defaultMaterial: 'pla', - pixelRatio: 1 -}; export default injectSheet(styles)(Interface);