From bfdc1db2e0c4a09b6836e2fefed3eb2ee82db57f Mon Sep 17 00:00:00 2001
From: Paul Kaplan <pkaplan@media.mit.edu>
Date: Mon, 26 Feb 2018 15:41:08 -0500
Subject: [PATCH] Don't bind in mapStateToProps to prevent sound editor
 re-render

---
 src/containers/sound-editor.jsx | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/src/containers/sound-editor.jsx b/src/containers/sound-editor.jsx
index bbe032c0b..de10ebc2c 100644
--- a/src/containers/sound-editor.jsx
+++ b/src/containers/sound-editor.jsx
@@ -89,7 +89,7 @@ class SoundEditor extends React.Component {
         }
 
         this.resetState(samples, sampleRate);
-        this.props.onUpdateSoundBuffer(
+        this.props.vm.updateSoundBuffer(
             this.props.soundIndex,
             this.audioBufferPlayer.buffer,
             wavBuffer ? new Uint8Array(wavBuffer) : new Uint8Array());
@@ -112,7 +112,7 @@ class SoundEditor extends React.Component {
         this.setState({playhead});
     }
     handleChangeName (name) {
-        this.props.onRenameSound(this.props.soundIndex, name);
+        this.props.vm.renameSound(this.props.soundIndex, name);
     }
     handleActivateTrim () {
         if (this.state.trimStart === null && this.state.trimEnd === null) {
@@ -200,12 +200,14 @@ class SoundEditor extends React.Component {
 
 SoundEditor.propTypes = {
     name: PropTypes.string.isRequired,
-    onRenameSound: PropTypes.func.isRequired,
-    onUpdateSoundBuffer: PropTypes.func.isRequired,
     sampleRate: PropTypes.number,
     samples: PropTypes.instanceOf(Float32Array),
     soundId: PropTypes.string,
-    soundIndex: PropTypes.number
+    soundIndex: PropTypes.number,
+    vm: PropTypes.shape({
+        updateSoundBuffer: PropTypes.func,
+        renameSound: PropTypes.func
+    })
 };
 
 const mapStateToProps = (state, {soundIndex}) => {
@@ -219,8 +221,7 @@ const mapStateToProps = (state, {soundIndex}) => {
         sampleRate: audioBuffer.sampleRate,
         samples: audioBuffer.getChannelData(0),
         name: sound.name,
-        onRenameSound: state.vm.renameSound.bind(state.vm),
-        onUpdateSoundBuffer: state.vm.updateSoundBuffer.bind(state.vm)
+        vm: state.vm
     };
 };
 
-- 
GitLab