<commit_before>define(['angular'], function(angular) {
  'use strict';

  angular.module('flash', [])
    .factory('flash', ['$rootScope', '$timeout', function($rootScope, $timeout){
      var messages = [],
          reset;

      var cleanup = function() {
        $timeout.cancel(reset);
        reset = $timeout(function() {
          messages = [];
        });
      };

      var emit = function() {
        $rootScope.$emit('flash:message', messages, cleanup);
      };

      $rootScope.$on('$routeChangeSuccess', emit);

      var asMessage = function(level, text) {
        if (!text) {
          text = level;
          level = 'success';
        }
        return {
          level: level,
          text: text
        };
      };

      var asArrayOfMessages = function(level, text) {
        if (level instanceof Array) return level.map(function(message) {
          return message.text ? message : asMessage(message);
        });
        return text ? [{ level: level, text: text }] : [asMessage(level)];
      };

      return function(level, text) {
        emit(messages = asArrayOfMessages(level, text));
      };
    }])
    .directive('flashMessages', function() {
      return {
        restrict: 'E',
        replace: true,
        template:
          '<ol class="alert-list" id="flash-messages">' +
            '<li ng-repeat="m in messages" class="alert alert-{{levelClassName(m.level)}} alert-dismissable">' +
              '<div class="container">' +
                '<button type="button" class="close" data-dismiss="alert">&times;</button>' +
                '{{m.text}}' +
              '</div>' +
            '</li>' +
          '</ol>',
        controller: function($scope, $rootScope) {
          $scope.levelClassName = function(level) {
            if (level == 'error') {
              return 'danger';
            } else {
              return level;
            }
          };

          $rootScope.$on('flash:message', function(_, messages, done) {
            $scope.messages = messages;
            done();
          });
        }
      };
    });
});<commit_msg>Remove messages on state change<commit_after>define(['angular'], function(angular) {
  'use strict';

  angular.module('flash', [])
    .factory('flash', ['$rootScope', '$timeout', function($rootScope, $timeout){
      var messages = [],
          reset;

      var cleanup = function() {
        $timeout.cancel(reset);
        reset = $timeout(function() {
          messages = [];
        });
      };

      var emit = function() {
        $rootScope.$emit('flash:message', messages, cleanup);
      };

      $rootScope.$on('$routeChangeSuccess', emit);

      var asMessage = function(level, text) {
        if (!text) {
          text = level;
          level = 'success';
        }
        return {
          level: level,
          text: text
        };
      };

      var asArrayOfMessages = function(level, text) {
        if (level instanceof Array) return level.map(function(message) {
          return message.text ? message : asMessage(message);
        });
        return text ? [{ level: level, text: text }] : [asMessage(level)];
      };

      return function(level, text) {
        emit(messages = asArrayOfMessages(level, text));
      };
    }])
    .directive('flashMessages', function() {
      return {
        restrict: 'E',
        replace: true,
        template:
          '<ol class="alert-list" id="flash-messages">' +
            '<li ng-repeat="m in messages" class="alert alert-{{levelClassName(m.level)}} alert-dismissable">' +
              '<div class="container">' +
                '<button type="button" class="close" data-dismiss="alert">&times;</button>' +
                '{{m.text}}' +
              '</div>' +
            '</li>' +
          '</ol>',
        controller: function($scope, $rootScope) {
          $scope.levelClassName = function(level) {
            if (level == 'error') {
              return 'danger';
            } else {
              return level;
            }
          };

          $rootScope.$on('flash:message', function(_, messages, done) {
            $scope.messages = messages;
            done();
          });

          $rootScope.$on('$stateChangeSuccess', function(_u1, _u2, $stateParams){
            $scope.messages = [];
          });
        }
      };
    });
});
{'fraction_non_alphanumeric': 0.1618828932261768, 'fraction_numerical': 0.0004592422502870264, 'mean_word_length': 1.7994858611825193, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, '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': '6688867', 'n_tokens_mistral': 1187, 'n_tokens_neox': 1173, 'n_words': 245}