mirror of
https://github.com/a-nyx/maputnik-with-pmtiles.git
synced 2024-12-28 17:21:18 +01:00
Only update if structure of JSON changes
This commit is contained in:
parent
ae9afdd8d9
commit
3be3a716d4
1 changed files with 12 additions and 0 deletions
|
@ -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
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue