<commit_before>import React from 'react'
import ReactDOM from 'react-dom'
import GoogleApiComponent from 'google-maps-react/dist/GoogleApiComponent'
import { GOOGLE_MAPS_API_KEY } from '../../../../config'
import GOOGLE_MAPS_CONFIG from './config'
import './styles.scss'

// This component will not re-render in response to redux state or prop
// changes. We don't want to reload the map everytime these hapen. Instead,
// we'll keep an internal state, and we'll use Google Maps API to manage it.
const Map = React.createClass({

  render () {
    return (
      <div className='map-wrapper'>
        <div className='map' ref='map' />
      </div>
    )
  },

  // Define internal state.
  getInitialState () {
    return {
      selectedCountry: null
    }
  },

  // The country selected will be received via props.
  componentWillReceiveProps (nextProps) {
    if (nextProps.selectedCountry) {
      this.selectCountry(nextProps.selectedCountry)
    }
  },

  // This component should never update after its initialisation as
  // the map would be reloaded.
  shouldComponentUpdate (nextProps) {
    return !this.props.loaded
  },

  // This is the first and only time the component is rendered.
  componentDidUpdate (prevProps, prevState) {
    this.loadMap()
  },

  // Load the map
  loadMap () {
    const { google } = this.props
    const mapEl = ReactDOM.findDOMNode(this.refs.map)
    this.map = new google.maps.Map(mapEl, GOOGLE_MAPS_CONFIG)
  },

  selectCountry (country) {
    this.setState({ selectedCountry: country })
    const { lat, lng } = country
    this.map.panTo({ lat, lng })
  },

  propTypes: {
    loaded: React.PropTypes.bool,
    google: React.PropTypes.object,
    selectedCountry: React.PropTypes.object
  }
})

export default GoogleApiComponent({
  apiKey: GOOGLE_MAPS_API_KEY
})(Map)
<commit_msg>Fit country on selection using LatLngBounds<commit_after>import React from 'react'
import ReactDOM from 'react-dom'
import GoogleApiComponent from 'google-maps-react/dist/GoogleApiComponent'
import { GOOGLE_MAPS_API_KEY } from '../../../../config'
import GOOGLE_MAPS_CONFIG from './config'
import './styles.scss'

// This component will not re-render in response to redux state or prop
// changes. We don't want to reload the map everytime these hapen. Instead,
// we'll keep an internal state, and we'll use Google Maps API to manage it.
const Map = React.createClass({

  render () {
    return (
      <div className='map-wrapper'>
        <div className='map' ref='map' />
      </div>
    )
  },

  // Define internal state.
  getInitialState () {
    return {
      selectedCountry: null
    }
  },

  // The country selected will be received via props.
  componentWillReceiveProps (nextProps) {
    if (nextProps.selectedCountry) {
      this.selectCountry(nextProps.selectedCountry)
    }
  },

  // This component should never update after its initialisation as
  // the map would be reloaded.
  shouldComponentUpdate (nextProps) {
    return !this.props.loaded
  },

  // This is the first and only time the component is rendered.
  componentDidUpdate (prevProps, prevState) {
    this.loadMap()
  },

  // Load the map
  loadMap () {
    const { google } = this.props
    const mapEl = ReactDOM.findDOMNode(this.refs.map)
    this.map = new google.maps.Map(mapEl, GOOGLE_MAPS_CONFIG)
  },

  // Fit country in map using South West and North East coordinates
  selectCountry (country) {
    const { sw, ne } = country.latLngBounds
    const bounds = new this.props.google.maps.LatLngBounds(sw, ne)
    this.map.fitBounds(bounds)
    this.setState({ selectedCountry: country })
  },

  propTypes: {
    loaded: React.PropTypes.bool,
    google: React.PropTypes.object,
    selectedCountry: React.PropTypes.object
  }
})

export default GoogleApiComponent({
  apiKey: GOOGLE_MAPS_API_KEY
})(Map)

{'fraction_non_alphanumeric': 0.1090245174752217, 'fraction_numerical': 0.0, 'mean_word_length': 3.1775599128540306, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3503570', 'n_tokens_mistral': 1179, 'n_tokens_neox': 1130, 'n_words': 345}