mirror of
https://github.com/maputnik/editor.git
synced 2026-01-07 14:00:01 +00:00
Only update if structure of JSON changes
This commit is contained in:
@@ -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) {
|
onCodeUpdate(newCode) {
|
||||||
try {
|
try {
|
||||||
const parsedLayer = JSON.parse(newCode)
|
const parsedLayer = JSON.parse(newCode)
|
||||||
this.props.onChange(parsedLayer)
|
this.props.onChange(parsedLayer)
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
console.warn(err)
|
console.warn(err)
|
||||||
|
} finally {
|
||||||
this.setState({
|
this.setState({
|
||||||
code: newCode
|
code: newCode
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user