[Maps] only sync layer list state to mapbox once (#37133)

* [Maps] only sync layer list state to mapbox once

* clean up getDerivedStateFromProps logic
This commit is contained in:
Nathan Reese 2019-05-29 17:38:50 -06:00 committed by GitHub
parent c8177e07cb
commit a3f5e9f83d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -32,19 +32,29 @@ const TOOLTIP_TYPE = {
export class MBMapContainer extends React.Component {
state = {
isDrawingFilter: false
isDrawingFilter: false,
prevLayerList: undefined,
hasSyncedLayerList: false,
};
static getDerivedStateFromProps(nextProps, prevState) {
const nextIsDrawingFilter = nextProps.drawState !== null;
if (nextIsDrawingFilter === prevState.isDrawingFilter) {
return null;
if (nextIsDrawingFilter !== prevState.isDrawingFilter) {
return {
isDrawingFilter: nextIsDrawingFilter,
};
}
return {
isDrawingFilter: nextIsDrawingFilter
};
const nextLayerList = nextProps.layerList;
if (nextLayerList !== prevState.prevLayerList) {
return {
prevLayerList: nextLayerList,
hasSyncedLayerList: false,
};
}
return null;
}
constructor() {
@ -104,8 +114,14 @@ export class MBMapContainer extends React.Component {
_debouncedSync = _.debounce(() => {
if (this._isMounted) {
this._syncMbMapWithLayerList();
this._syncMbMapWithInspector();
if (!this.state.hasSyncedLayerList) {
this.setState({
hasSyncedLayerList: true
}, () => {
this._syncMbMapWithLayerList();
this._syncMbMapWithInspector();
});
}
this._syncDrawControl();
}
}, 256);