<commit_before>! function(window, angular, undefined) {
  var defaultMapSettings = {
      center: {
        lat: 12.94206,
        lng: 77.62229
      },
      zoom: 8
    },
    setMarkerFunc = undefined;

  function setMarkerCurryFunc(placesMap) {
    if (placesMap) {
      var map = placesMap;
    }
    return function(marker) {
      if (!map) {
        throw "Please pass a map reference before setting marker";
      }
      if (Object.prototype.toString.call(marker) == "[object Object]" && marker.position !== undefined) {
        marker.map = map;
        var newMarker = new google.maps.Marker(marker);
        newMarker.setMap(map);
        return newMarker;
      }
    }
  }

  angular.module('ds.map', []).
  factory('dsMapFactory', ['$http', function($http) {
    var obj = {
      getDefaultMapSettings: getDefaultMapSettingsFunc,
      setDefaultMapSettings: setDefaultMapSettingsFunc,
      setDirectionsToLocation: function() {}
    };

    function getDefaultMapSettingsFunc() {
      return defaultMapSettings;
    }

    function setDefaultMapSettingsFunc(settingsObj) {
      defaultMapSettings = settingsObj;
    }

    return obj;
  }]).
  directive('dsMap', ['$q', '$timeout', 'dsMapFactory', function($q, $timeout, dsMapFactory) {
    var deferred = $q.defer(),
      obj = {
        scope: {
          mapSettings: "="
        },
        restrict: "E",
        link: function(scope) {

        },
        controller: ['$scope', '$element', '$attrs', function($scope, $element, $attr) {
          var _deferred = $q.defer(),
            placesDeferred = $q.defer(),
            dsMapElements = 0,
            deferredArray = [],
            that = this,
            mapSettings = that.mapSettings = $scope.mapSettings || dsMapFactory.getDefaultMapSettings(),
            map = new google.maps.Map(document.createElement('div'), mapSettings);

          function getLocationFunc() {
            return that.dsPlacesLocation;
          }

          function setLocationFunc(center) {
            that.dsPlacesLocation = center || that.getMap().getCenter();
          }

          function getMapFunc() {
            return that.map;
          }

          function setMapFunc(map) {
            dsMapFactory.map = that.map = map;
            that.setLocation(that.map.getCenter());
          }

          function iterateAllMarkersFunc(callback) {
            for (var groups in that.placesGroupHash) {
              var eachGroupRef = that.placesGroupHash[groups];
              for (var _count = 0, len = eachGroupRef.length; _count < len; _count++) {
                var allIteratedMarkers = eachGroupRef[_count];
                callback.call(allIteratedMarkers);
              }
            }
          }

          function iterateMarkersMatchingBooleanFunc(bool, callback) {
            that.iterateAllMarkers(function() {
              var eachPreviousMarker = this;
              if (eachPreviousMarker.visible === bool) {
                callback.call(eachPreviousMarker);
                eachPreviousMarker.setMap(eachPreviousMarker.getMap());
              }
            });
          }

          function setGroupMarkerVisibilityFunc(group, bool, setVisibleMarkerBounds) {
            var currentGroupRef = that.placesGroupHash[group],
              previousGroup = undefined;
            if (previousGroup != group) {
              that.bounds = new google.maps.LatLngBounds();
              for (var currentGroupCount = 0, len = currentGroupRef.length; currentGroupCount < len; currentGroupCount++) {
                var eachCurrentMarker = currentGroupRef[currentGroupCount];
                if (eachCurrentMarker.visible !== bool) {
                  eachCurrentMarker.visible = bool;
                  eachCurrentMarker.setMap(eachCurrentMarker.getMap());
                  if (setVisibleMarkerBounds && eachCurrentMarker.visible) {
                    that.bounds.extend(eachCurrentMarker.position);
                  }
                }
              }

              if (setVisibleMarkerBounds) {
                that.changeMapBounds();
              }
            }

            previousGroup = group;
          }

          function hideAllVisibleMarkersFunc() {
            that.iterateMarkersMatchingBoolean(true, function() {
              var visibleMarker = this;
              visibleMarker.visible = false;
            });
          }

          function changeMapBoundsFunc() {
            that.getMap().fitBounds(that.bounds);
            that.getMap().setCenter(that.getLocation());
            that.getMap().setZoom(that.getMap().getZoom() - 1);
          }

          that.mapDeferred = deferred;
          that.mapRendered = deferred.promise;
          that.placesDeferred = placesDeferred;
          that.placesRendered = placesDeferred.promise;
          that.placesGroupHash = {};
          that.placesCount = 0;
          that.getLocation = getLocationFunc;
          that.setLocation = setLocationFunc;
          that.getMap = getMapFunc;
          that.setMap = setMapFunc;
          that.iterateAllMarkers = iterateAllMarkersFunc;
          that.iterateMarkersMatchingBoolean = iterateMarkersMatchingBooleanFunc;
          that.setGroupMarkerVisibility = setGroupMarkerVisibilityFunc;
          that.hideAllVisibleMarkers = hideAllVisibleMarkersFunc;
          that.changeMapBounds = changeMapBoundsFunc;

          that.setMap(map);

          that.placesRendered.then(function() {
            that.changeMapBounds();
          });

          (function(dfrd, _dfrd) {
            that.mapRendered.then(function() {
              dsMapFactory.setMarker = setMarkerFunc = setMarkerCurryFunc(that.getMap());
            });
          })(deferred, _deferred);

          that.nextDefer = deferred = _deferred;
        }]
      };
    return obj;
  }]).
  directive('dsMapView', function() {
      var obj = {
        scope: {
          mapSettings: "=",
          originOptions: "=",
          destinationOptions: "="
        },
        restrict: "E",
        replace: true,
        template: "<div></div>",
        require: "^?dsMap",
        link: function(scope, element, attrs, dsMapController) {
          var map = new google.maps.Map(element[0], scope.mapSettings || dsMapController.mapSettings),
            clonedOriginMarkerObject = angular.copy(scope.originOptions || {});
          dsMapController.setMap(map);
          dsMapController.isViewSet = true;
          dsMapController.destinationOptions = angular.copy(scope.destinationOptions || {});
          dsMapController.mapRendered.then(function() {
            clonedOriginMarkerObject.position = dsMapController.getLocation();
            setMarkerFunc(clonedOriginMarkerObject);
          });
        },
        controller: ['$scope', function($scope) {
          var that = this;
          that.originOptions = $scope.originOptions;
          that.destinationOptions = angular.copy($scope.destinationOptions);
        }]
      };
      return obj;
    }).directive('dsMapPlaces', ['$q', 'dsMapFactory', function($q, dsMapFactory) {
      var initialdsMapView = true,
        deferred = $q.defer(),
        obj = {
          scope: {
            options: "="
          },
          restrict: "E",
          replace: true,
          require: "^?dsMap",
          link: function(scope, element, attrs, dsMapController) {
            var rankByDistance = google.maps.places.RankBy.DISTANCE;

            if (initialdsMapView) {
              dsMapController.mapDeferred.resolve();
              initialdsMapView = false;
            }

            dsMapController.mapRendered.then(function() {
              dsMapController.placesService = new google.maps.places.PlacesService(dsMapController.getMap());
              dsMapController.directionsService = new google.maps.DirectionsService();
              scope.options.map = dsMapController.getMap();
              dsMapController.directionsDisplay = new google.maps.DirectionsRenderer(scope.options);
              dsMapController.bounds = new google.maps.LatLngBounds();
              deferred.resolve(dsMapController.placesService);
            });
          },
          controller: ['$scope', '$element', '$attrs', function($scope, $element, $attr) {
            var that = this;

            function dsMapPlacesDeferredFunc() {
              var _deferred = $q.defer();
              return function() {
                return _deferred;
              };
            }

            function dsMapPlacesLoadedFunc(callback) {
              that.dsMapPlacesDeferred().promise.then(callback);
            }

            that.placesServiceSet = deferred.promise;
            that.dsMapPlacesDeferred = dsMapPlacesDeferredFunc();
            dsMapFactory.dsMapPlacesLoaded = that.dsMapPlacesLoaded = dsMapPlacesLoadedFunc;
          }]
        };
      return obj;
    }])
    .directive('dsGroup', ['dsMapFactory', function(dsMapFactory) {
      var obj = {
        scope: true,
        restrict: "E",
        require: ["^?dsMap", "^?dsMapPlaces"],
        link: function(scope, element, attrs, dsMapControllers) {
          previousGroup = undefined;
          dsMapController = dsMapControllers[0];
          dsMapPlacesController = dsMapControllers[1];

          (function(previousGroup, dsMapController, dsMapPlacesController) {
            function onToggleClickFunc(group) {
              dsMapController.directionsDisplay.setMap(null);
              if (previousGroup !== undefined) {
                if (previousGroup == group) {
                  return;
                }
                dsMapController.setGroupMarkerVisibility(previousGroup, false, true);
              } else {
                dsMapController.hideAllVisibleMarkers();
              }

              dsMapController.setGroupMarkerVisibility(group, true, true);

              previousGroup = group;
            }

            function toggleGroupVisibilityFunc(group) {
              dsMapPlacesController.dsMapPlacesLoaded(function() {
                onToggleClickFunc(group);
              });
            }

            function setDirectionsToLocationFunc(location, mode) {
              var request = {
                origin: dsMapController.getLocation(),
                destination: location,
                travelMode: google.maps.TravelMode[mode]
              };

              dsMapController.destinationOptions.position = location;

              dsMapPlacesController.dsMapPlacesLoaded(function() {
                dsMapController.hideAllVisibleMarkers();
                dsMapController.directionsDisplay.setMap(dsMapController.getMap());
                dsMapController.directionsService.route(request, function(response, status) {
                  if (status == "OK") {
                    var destinationMarker = setMarkerFunc(dsMapController.destinationOptions);
                    dsMapController.directionsDisplay.setDirections(response);
                    dsMapController.bounds = new google.maps.LatLngBounds();
                    dsMapController.bounds.extend(dsMapController.getLocation());
                    dsMapController.bounds.extend(location);
                    dsMapController.placesGroupHash['searchedLocation'] = [destinationMarker];
                    dsMapController.changeMapBounds();
                  }
                });
              });
            }

            scope.toggleGroupVisibility = toggleGroupVisibilityFunc;
<commit_msg>Preventing too many callbacks getting registered<commit_after>! function(window, angular, undefined) {
  var defaultMapSettings = {
      center: {
        lat: 12.94206,
        lng: 77.62229
      },
      zoom: 8
    },
    setMarkerFunc = undefined;

  function setMarkerCurryFunc(placesMap) {
    if (placesMap) {
      var map = placesMap;
    }
    return function(marker) {
      if (!map) {
        throw "Please pass a map reference before setting marker";
      }
      if (Object.prototype.toString.call(marker) == "[object Object]" && marker.position !== undefined) {
        marker.map = map;
        var newMarker = new google.maps.Marker(marker);
        newMarker.setMap(map);
        return newMarker;
      }
    }
  }

  angular.module('ds.map', []).
  factory('dsMapFactory', ['$http', function($http) {
    var obj = {
      getDefaultMapSettings: getDefaultMapSettingsFunc,
      setDefaultMapSettings: setDefaultMapSettingsFunc,
      setDirectionsToLocation: function() {}
    };

    function getDefaultMapSettingsFunc() {
      return defaultMapSettings;
    }

    function setDefaultMapSettingsFunc(settingsObj) {
      defaultMapSettings = settingsObj;
    }

    return obj;
  }]).
  directive('dsMap', ['$q', '$timeout', 'dsMapFactory', function($q, $timeout, dsMapFactory) {
    var deferred = $q.defer(),
      obj = {
        scope: {
          mapSettings: "="
        },
        restrict: "E",
        link: function(scope) {

        },
        controller: ['$scope', '$element', '$attrs', function($scope, $element, $attr) {
          var _deferred = $q.defer(),
            placesDeferred = $q.defer(),
            dsMapElements = 0,
            deferredArray = [],
            that = this,
            mapSettings = that.mapSettings = $scope.mapSettings || dsMapFactory.getDefaultMapSettings(),
            map = new google.maps.Map(document.createElement('div'), mapSettings);

          function getLocationFunc() {
            return that.dsPlacesLocation;
          }

          function setLocationFunc(center) {
            that.dsPlacesLocation = center || that.getMap().getCenter();
          }

          function getMapFunc() {
            return that.map;
          }

          function setMapFunc(map) {
            dsMapFactory.map = that.map = map;
            that.setLocation(that.map.getCenter());
          }

          function iterateAllMarkersFunc(callback) {
            for (var groups in that.placesGroupHash) {
              var eachGroupRef = that.placesGroupHash[groups];
              for (var _count = 0, len = eachGroupRef.length; _count < len; _count++) {
                var allIteratedMarkers = eachGroupRef[_count];
                callback.call(allIteratedMarkers);
              }
            }
          }

          function iterateMarkersMatchingBooleanFunc(bool, callback) {
            that.iterateAllMarkers(function() {
              var eachPreviousMarker = this;
              if (eachPreviousMarker.visible === bool) {
                callback.call(eachPreviousMarker);
                eachPreviousMarker.setMap(eachPreviousMarker.getMap());
              }
            });
          }

          function setGroupMarkerVisibilityFunc(group, bool, setVisibleMarkerBounds) {
            var currentGroupRef = that.placesGroupHash[group],
              previousGroup = undefined;
            if (previousGroup != group) {
              that.bounds = new google.maps.LatLngBounds();
              for (var currentGroupCount = 0, len = currentGroupRef.length; currentGroupCount < len; currentGroupCount++) {
                var eachCurrentMarker = currentGroupRef[currentGroupCount];
                if (eachCurrentMarker.visible !== bool) {
                  eachCurrentMarker.visible = bool;
                  eachCurrentMarker.setMap(eachCurrentMarker.getMap());
                  if (setVisibleMarkerBounds && eachCurrentMarker.visible) {
                    that.bounds.extend(eachCurrentMarker.position);
                  }
                }
              }

              if (setVisibleMarkerBounds) {
                that.changeMapBounds();
              }
            }

            previousGroup = group;
          }

          function hideAllVisibleMarkersFunc() {
            that.iterateMarkersMatchingBoolean(true, function() {
              var visibleMarker = this;
              visibleMarker.visible = false;
            });
          }

          function changeMapBoundsFunc() {
            that.getMap().fitBounds(that.bounds);
            that.getMap().setCenter(that.getLocation());
            that.getMap().setZoom(that.getMap().getZoom() - 1);
          }

          that.mapDeferred = deferred;
          that.mapRendered = deferred.promise;
          that.placesDeferred = placesDeferred;
          that.placesRendered = placesDeferred.promise;
          that.placesGroupHash = {};
          that.placesCount = 0;
          that.getLocation = getLocationFunc;
          that.setLocation = setLocationFunc;
          that.getMap = getMapFunc;
          that.setMap = setMapFunc;
          that.iterateAllMarkers = iterateAllMarkersFunc;
          that.iterateMarkersMatchingBoolean = iterateMarkersMatchingBooleanFunc;
          that.setGroupMarkerVisibility = setGroupMarkerVisibilityFunc;
          that.hideAllVisibleMarkers = hideAllVisibleMarkersFunc;
          that.changeMapBounds = changeMapBoundsFunc;

          that.setMap(map);

          that.placesRendered.then(function() {
            that.changeMapBounds();
          });

          (function(dfrd, _dfrd) {
            that.mapRendered.then(function() {
              dsMapFactory.setMarker = setMarkerFunc = setMarkerCurryFunc(that.getMap());
            });
          })(deferred, _deferred);

          that.nextDefer = deferred = _deferred;
        }]
      };
    return obj;
  }]).
  directive('dsMapView', function() {
      var obj = {
        scope: {
          mapSettings: "=",
          originOptions: "=",
          destinationOptions: "="
        },
        restrict: "E",
        replace: true,
        template: "<div></div>",
        require: "^?dsMap",
        link: function(scope, element, attrs, dsMapController) {
          var map = new google.maps.Map(element[0], scope.mapSettings || dsMapController.mapSettings),
            clonedOriginMarkerObject = angular.copy(scope.originOptions || {});
          dsMapController.setMap(map);
          dsMapController.isViewSet = true;
          dsMapController.destinationOptions = angular.copy(scope.destinationOptions || {});
          dsMapController.mapRendered.then(function() {
            clonedOriginMarkerObject.position = dsMapController.getLocation();
            setMarkerFunc(clonedOriginMarkerObject);
          });
        },
        controller: ['$scope', function($scope) {
          var that = this;
          that.originOptions = $scope.originOptions;
          that.destinationOptions = angular.copy($scope.destinationOptions);
        }]
      };
      return obj;
    }).directive('dsMapPlaces', ['$q', 'dsMapFactory', function($q, dsMapFactory) {
      var initialdsMapView = true,
        deferred = $q.defer(),
        obj = {
          scope: {
            options: "="
          },
          restrict: "E",
          replace: true,
          require: "^?dsMap",
          link: function(scope, element, attrs, dsMapController) {
            var rankByDistance = google.maps.places.RankBy.DISTANCE;

            if (initialdsMapView) {
              dsMapController.mapDeferred.resolve();
              initialdsMapView = false;
            }

            dsMapController.mapRendered.then(function() {
              dsMapController.placesService = new google.maps.places.PlacesService(dsMapController.getMap());
              dsMapController.directionsService = new google.maps.DirectionsService();
              scope.options.map = dsMapController.getMap();
              dsMapController.directionsDisplay = new google.maps.DirectionsRenderer(scope.options);
              dsMapController.bounds = new google.maps.LatLngBounds();
              deferred.resolve(dsMapController.placesService);
            });
          },
          controller: ['$scope', '$element', '$attrs', function($scope, $element, $attr) {
            var that = this;

            function dsMapPlacesDeferredFunc() {
              var _deferred = $q.defer();
              return function() {
                return _deferred;
              };
            }

            function dsMapPlacesLoadedFunc(callback) {
              that.dsMapPlacesDeferred().promise.then(callback);
            }

            that.placesServiceSet = deferred.promise;
            that.dsMapPlacesDeferred = dsMapPlacesDeferredFunc();
            dsMapFactory.dsMapPlacesLoaded = that.dsMapPlacesLoaded = dsMapPlacesLoadedFunc;
          }]
        };
      return obj;
    }])
    .directive('dsGroup', ['dsMapFactory', function(dsMapFactory) {
      var obj = {
        scope: true,
        restrict: "E",
        require: ["^?dsMap", "^?dsMapPlaces"],
        link: function(scope, element, attrs, dsMapControllers) {
          previousGroup = undefined;
          dsMapController = dsMapControllers[0];
          dsMapPlacesController = dsMapControllers[1];

          (function(previousGroup, dsMapController, dsMapPlacesController) {
            var isMapPlacesLoaded = false;

            function onToggleClickFunc(group) {
              dsMapController.directionsDisplay.setMap(null);
              if (previousGroup !== undefined) {
                if (previousGroup == group) {
                  return;
                }
                dsMapController.setGroupMarkerVisibility(previousGroup, false, true);
              } else {
                dsMapController.hideAllVisibleMarkers();
              }

              dsMapController.setGroupMarkerVisibility(group, true, true);

              previousGroup = group;
            }

            function toggleGroupVisibilityFunc(group) {
              dsMapPlacesController.dsMapPlacesLoaded(function() {
                isMapPlacesLoaded = true;
              });
              if (isMapPlacesLoaded) {
                onToggleClickFunc(group);
              }
            }

            function setDirectionsToLocationFunc(location, mode) {
              var request = {
                origin: dsMapController.getLocation(),
                destination: location,
                travelMode: google.maps.TravelMode[mode]
              };

              dsMapController.destinationOptions.position = location;

              dsMapPlacesController.dsMapPlacesLoaded(function() {
                dsMapController.hideAllVisibleMarkers();
                dsMapController.directionsDisplay.setMap(dsMapController.getMap());
                dsMapController.directionsService.route(request, function(response, status) {
                  if (status == "OK") {
                    var destinationMarker = setMarkerFunc(dsMapController.destinationOptions);
                    dsMapController.directionsDisplay.setDirections(response);
                    dsMapController.bounds = new google.maps.LatLngBounds();
                    dsMapController.bounds.extend(dsMapController.getLocation());
                    dsMapController.bounds.extend(location);
                    dsMapController.placesGroupHash['searchedLocation'] = [destinationMarker];
                    dsMapController.changeMapBounds();
                  }
                });
              });
            }

            scope.toggleGroupVisibility = toggleGroupVisibilityFunc;

{'fraction_non_alphanumeric': 0.10264183629276744, 'fraction_numerical': 0.001992204417496752, 'mean_word_length': 1.9482890704800817, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 7, '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': '766813', 'n_tokens_mistral': 5978, 'n_tokens_neox': 5735, 'n_words': 982}