<commit_before>define(['app'], function(app) {

  return app.controller('BreadcrumbsCtrl', ['$rootScope', '$scope', '$location', 'breadcrumbs',
    function($rootScope, $scope, $location, breadcrumbs) {

      function computeCrumbs() {
        $scope.breadcrumbs = breadcrumbs.get();
        $scope.showCrumbs = $location.path() !== '/';
      }

      function addCrumb(title, url) {
        // if the last current crumbs is dynamic, we replace it with the
        // new incoming one;
        if ($scope.breadcrumbs[$scope.breadcrumbs.length-1].dynamic)
          $scope.breadcrumbs.pop();

        $scope.breadcrumbs.push({
          label: title,
          path: url,
          dynamic: true
        });
      }

      $scope.$on('breadcrumbs:add', function(event, title, url) {
        addCrumb(title, url);
      });

      $rootScope.$on('$routeChangeSuccess', function(e, route) {
        computeCrumbs();
      });
    }
  ]);
});<commit_msg>fix up event handling and add clean up code<commit_after>define(['app'], function(app) {

  return app.controller('BreadcrumbsCtrl', ['$rootScope', '$scope', '$location', 'breadcrumbs',
    function($rootScope, $scope, $location, breadcrumbs) {

      function computeCrumbs() {
        $scope.breadcrumbs = breadcrumbs.get();
        $scope.showCrumbs = $location.path() !== '/';
      }

      function addCrumb(title, url) {
        // if the last current crumbs is dynamic, we replace it with the
        // new incoming one;
        if ($scope.breadcrumbs[$scope.breadcrumbs.length-1].dynamic)
          $scope.breadcrumbs.pop();

        $scope.breadcrumbs.push({
          label: title,
          path: url,
          dynamic: true
        });
      }

      var crumblistener = $rootScope.$on('breadcrumbs:add', function(event, title, url) {
        addCrumb(title, url);
      });

      var routeChangeListener = $rootScope.$on('$routeChangeSuccess', function(e, route) {
        computeCrumbs();
      });

      $scope.$on('$destroy', function() {
        crumblistener();
        routeChangeListener();
      });
    }
  ]);
});
{'fraction_non_alphanumeric': 0.15671285236502627, 'fraction_numerical': 0.0009555661729574773, 'mean_word_length': 2.4958263772954923, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2206668', 'n_tokens_mistral': 635, 'n_tokens_neox': 641, 'n_words': 128}