Don't use bind in mapStateToProps
This commit is contained in:
1 parent
8747315ab2
commit
5a9679fa40
2 files changed
+12
-15
No files matched your search
@@ -14,12 +14,9 @@ class LoadButton extends React.Component {
|
||||
'handleClick'
|
||||
]);
|
||||
}
|
||||
shouldComponentUpdate () {
|
||||
return false;
|
||||
}
|
||||
handleChange (e) {
|
||||
const reader = new FileReader();
|
||||
reader.onload = () => this.props.loadProject(reader.result);
|
||||
reader.onload = () => this.props.vm.fromJSON(reader.result);
|
||||
reader.readAsText(e.target.files[0]);
|
||||
}
|
||||
handleClick () {
|
||||
@@ -30,7 +27,7 @@ class LoadButton extends React.Component {
|
||||
}
|
||||
render () {
|
||||
const {
|
||||
loadProject, // eslint-disable-line no-unused-vars
|
||||
vm, // eslint-disable-line no-unused-vars
|
||||
...props
|
||||
} = this.props;
|
||||
return (
|
||||
@@ -45,11 +42,13 @@ class LoadButton extends React.Component {
|
||||
}
|
||||
|
||||
LoadButton.propTypes = {
|
||||
loadProject: PropTypes.func.isRequired
|
||||
vm: PropTypes.shape({
|
||||
fromJSON: PropTypes.func
|
||||
})
|
||||
};
|
||||
|
||||
const mapStateToProps = state => ({
|
||||
loadProject: state.vm.fromJSON.bind(state.vm)
|
||||
vm: state.vm
|
||||
});
|
||||
|
||||
export default connect(
|
||||
|
||||
@@ -14,11 +14,8 @@ class SaveButton extends React.Component {
|
||||
'handleClick'
|
||||
]);
|
||||
}
|
||||
shouldComponentUpdate () {
|
||||
return false;
|
||||
}
|
||||
handleClick () {
|
||||
const json = this.props.saveProjectSb3();
|
||||
const json = this.props.vm.saveProjectSb3();
|
||||
|
||||
// Download project data into a file - create link element,
|
||||
// simulate click on it, and then remove it.
|
||||
@@ -39,7 +36,7 @@ class SaveButton extends React.Component {
|
||||
}
|
||||
render () {
|
||||
const {
|
||||
saveProjectSb3, // eslint-disable-line no-unused-vars
|
||||
vm, // eslint-disable-line no-unused-vars
|
||||
...props
|
||||
} = this.props;
|
||||
return (
|
||||
@@ -60,11 +57,12 @@ class SaveButton extends React.Component {
|
||||
}
|
||||
|
||||
SaveButton.propTypes = {
|
||||
saveProjectSb3: PropTypes.func.isRequired
|
||||
};
|
||||
vm: PropTypes.shape({
|
||||
saveProjectSb3: PropTypes.func
|
||||
})};
|
||||
|
||||
const mapStateToProps = state => ({
|
||||
saveProjectSb3: state.vm.saveProjectSb3.bind(state.vm)
|
||||
vm: state.vm
|
||||
});
|
||||
|
||||
export default connect(
|
||||
|
||||
Reference in new issue
Block a user