Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.
Remove string refs from components in favor of callback-style (#73)
Adam Krebs8177f264c487
diff --git a/src/components/common/file-uploader/file-upload.js b/src/components/common/file-uploader/file-upload.jsindex 453d3d71e..004ce63fd 100644--- a/src/components/common/file-uploader/file-upload.js+++ b/src/components/common/file-uploader/file-upload.js@@ -101,11 +101,11 @@ const StyledFileUpload = styled.div`height: 0;position: absolute;}-+.file-drop {position: relative;}-+.file-upload__message {color: ${props => props.theme.textColorLT};font-size: 14px;@@ -212,7 +212,6 @@ export default class FileUpload extends Component {<inputclassName="filter-upload__input"type="file"- ref="fileInput"onChange={this._onChange}/>{FileDrop ? (diff --git a/src/components/common/file-uploader/upload-button.js b/src/components/common/file-uploader/upload-button.jsindex e8c2102ac..33e351254 100644--- a/src/components/common/file-uploader/upload-button.js+++ b/src/components/common/file-uploader/upload-button.js@@ -42,8 +42,8 @@ export default class UploadButton extends Component {};_onClick = () => {- this.refs.fileInput.value = null;- this.refs.fileInput.click();+ this._fileInput.value = null;+ this._fileInput.click();};_onChange = ({target: {files}}) => {@@ -59,7 +59,7 @@ export default class UploadButton extends Component {<Wrapper><inputtype="file"- ref="fileInput"+ ref={ref => {this._fileInput = ref}}style={{display: 'none'}}onChange={this._onChange}/>diff --git a/src/components/common/item-selector/typeahead.js b/src/components/common/item-selector/typeahead.jsindex b7bd99661..e14aeef9d 100644--- a/src/components/common/item-selector/typeahead.js+++ b/src/components/common/item-selector/typeahead.js@@ -227,7 +227,6 @@ export default class Typeahead extends Component {_renderIncrementalSearchResults() {return (<this.props.customListComponent- ref="sel"fixedOptions={this.props.fixedOptions}options={this.props.maxVisiblediff --git a/src/components/map-container.js b/src/components/map-container.jsindex dcd41cf78..48ae0ed07 100644--- a/src/components/map-container.js+++ b/src/components/map-container.js@@ -112,34 +112,6 @@ export default function MapContainerFactory(MapPopover, MapControl) {}}- componentDidUpdate(prevProps, prevState) {- if (!this._map && this.refs.mapbox) {- this._map = this.refs.mapbox.getMap();- // bind mapboxgl event listener- this._map.on(MAPBOXGL_STYLE_UPDATE, () => {- // force refresh mapboxgl layers-- updateMapboxLayers(- this._map,- this._renderMapboxLayers(),- this.previousLayers,- this.props.mapLayers,- {force: true}- );-- if (typeof this.props.onMapStyleLoaded === 'function') {- this.props.onMapStyleLoaded(this._map);- }- });-- this._map.on('render', () => {- if (typeof this.props.onMapRender === 'function') {- this.props.onMapRender(this._map);- }- });- }- }-componentWillUnmount() {// unbind mapboxgl event listenerif (this._map) {@@ -191,6 +163,34 @@ export default function MapContainerFactory(MapPopover, MapControl) {visStateActions.toggleLayerForMap(mapIndex, layerId);};+ _setMapboxMap = (mapbox) => {+ if (!this._map && mapbox) {+ this._map = mapbox.getMap();+ // bind mapboxgl event listener+ this._map.on(MAPBOXGL_STYLE_UPDATE, () => {+ // force refresh mapboxgl layers++ updateMapboxLayers(+ this._map,+ this._renderMapboxLayers(),+ this.previousLayers,+ this.props.mapLayers,+ {force: true}+ );++ if (typeof this.props.onMapStyleLoaded === 'function') {+ this.props.onMapStyleLoaded(this._map);+ }+ });++ this._map.on('render', () => {+ if (typeof this.props.onMapRender === 'function') {+ this.props.onMapRender(this._map);+ }+ });+ }+ }+/* deck.gl doesn't support blendFuncSeparate yet* so we're applying the blending ourselves*/@@ -453,7 +453,7 @@ export default function MapContainerFactory(MapPopover, MapControl) {<this.props.MapComponent{...mapProps}key="bottom"- ref="mapbox"+ ref={this._setMapboxMap}mapStyle={mapStyle.bottomMapStyle}onClick={onMapClick}>diff --git a/src/components/modals/data-table-modal.js b/src/components/modals/data-table-modal.jsindex 02638097e..1f13184ca 100644--- a/src/components/modals/data-table-modal.js+++ b/src/components/modals/data-table-modal.js@@ -95,7 +95,7 @@ export class DataTableModal extends Component {// positions of a container.// react-data-grid canvas element can be scrolled- const canvas = this.refs.root.querySelector('.react-grid-Canvas');+ const canvas = this._root.querySelector('.react-grid-Canvas');// If canvas can not be scrolled left anymore when we try to scroll leftconst prevent_left = e.deltaX < 0 && canvas.scrollLeft <= 0;@@ -128,7 +128,7 @@ export class DataTableModal extends Component {.filter(({name}) => name !== '_geojson');return (- <div ref="root" className="dataset-modal" style={{overflow: 'scroll'}}>+ <div ref={ref => {this._root = ref}} className="dataset-modal" style={{overflow: 'scroll'}}><DatasetTabsactiveDataset={activeDataset}datasets={datasets}