From 3be3a716d4804cf79d35dd5d1c3fdfd32610be9d Mon Sep 17 00:00:00 2001 From: Lukas Martinelli Date: Thu, 29 Dec 2016 21:49:40 +0100 Subject: [PATCH] Only update if structure of JSON changes --- src/components/layers/JSONEditor.jsx | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/components/layers/JSONEditor.jsx b/src/components/layers/JSONEditor.jsx index 9043a86..2271c99 100644 --- a/src/components/layers/JSONEditor.jsx +++ b/src/components/layers/JSONEditor.jsx @@ -32,12 +32,24 @@ class JSONEditor extends React.Component { }) } + shouldComponentUpdate(nextProps, nextState) { + try { + const parsedLayer = JSON.parse(this.state.code) + // If the structure is still the same do not update + // because it affects editing experience by reformatting all the time + return nextState.code !== JSON.stringify(parsedLayer, null, 2) + } catch(err) { + return true + } + } + onCodeUpdate(newCode) { try { const parsedLayer = JSON.parse(newCode) this.props.onChange(parsedLayer) } catch(err) { console.warn(err) + } finally { this.setState({ code: newCode })