<commit_before>import React from 'react';
import {
	openInfoWindow,
	updateMarkers
} from '../../actions/mapActions';

export default class Markers extends React.Component {
	componentDidUpdate (prevProps) {
		if (this.props.map && !prevProps.map || this.props.pokemons !== prevProps.pokemons) {
			this.updateMarkers();
		}
	}

	updateMarkers () {
	    if (this.props.markers.length > 0) {
	        this.clearMarkers();
	    }

	    this.createMarkers();
	}

	createMarkers () {
	    let _markers = [];

	    if (this.props.map) {
	        for (let p of this.props.pokemons) {
	            let _marker = new google.maps.Marker({
	                position: new google.maps.LatLng(p.lat, p.lon),
	                icon: '/img/pokemon/' + p.id + '.svg'
	            });
	            _marker.pokemon = p;

		_marker.addListener('click', this.openInfoWindow.bind(this, _marker));
		_marker.setMap(this.props.map);

	            _markers.push(_marker);
	        }
	    }

		this.props.dispatch(updateMarkers(_markers));
	}

	clearMarkers (markers) {
	    for (let m of this.props.markers) {
	        m.setMap(null);
	    }
	}

	openInfoWindow (marker) {
		this.props.dispatch(openInfoWindow(marker));
	}

	render () {
		return null;
	}
}<commit_msg>Improved Marker updating on the map<commit_after>import React from 'react';
import {
	openInfoWindow,
	updateMarkers
} from '../../actions/mapActions';

export default class Markers extends React.Component {
	componentDidUpdate (prevProps) {
		if (this.props.map && !prevProps.map || this.props.pokemons !== prevProps.pokemons) {
			this.updateMarkers();
		}
	}

	updateMarkers () {
	    let markers = this.clearExpiredMarkers(this.props.markers);

		for (let p of this.props.pokemons) {
	        if (!this.markerExist(p)) {
	            this.addMarker(markers, p);
	        }
		}

		this.props.dispatch(updateMarkers(markers));
	}

	addMarker (markers, pokemon) {
		let marker = new google.maps.Marker({
			position: new google.maps.LatLng(pokemon.lat, pokemon.lon),
			icon: '/img/pokemon/' + pokemon.id + '.svg'
		});
		marker.pokemon = pokemon;

		marker.addListener('click', this.openInfoWindow.bind(this, marker));
		marker.setMap(this.props.map);
		markers.push(marker);
	}

	removeMarker (marker) {
		marker.setMap(null);
	}

	clearExpiredMarkers (markers) {
		let activeMarkers = [];

		for (let marker of markers) {
			if (this.markerActive(marker)) {
				activeMarkers.push(marker);
			}
			else {
				this.removeMarker(marker);
			}
		}

		return activeMarkers;
	}

	markerExist (pokemon) {
		return this.props.markers.find((marker) => marker.pokemon === pokemon);
	}

	markerActive (marker) {
		return this.props.pokemons.find((pokemon) => marker.pokemon === pokemon);
	}

	openInfoWindow (marker) {
		this.props.dispatch(openInfoWindow(marker));
	}

	render () {
		return null;
	}
}
{'fraction_non_alphanumeric': 0.1454737583656217, 'fraction_numerical': 0.0003522367030644593, 'mean_word_length': 2.977591036414566, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, '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': '647267', 'n_tokens_mistral': 1072, 'n_tokens_neox': 972, 'n_words': 174}