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

  angular.module('stream', [])
    .factory('Stream', function($window, $log){
      if ($window.streams === undefined) {
        $window.streams = {};
      }

      return function($scope, url, callback) {
        if ($window.streams[url]) {
          $log.info('[Stream] Closing connection to ' + url);
          window.streams[url].close();
        }
        $log.info('[Stream] Initiating connection to ' + url);

        $window.streams[url] = new EventSource(url + '?_=' + new Date().getTime());
        $window.streams[url].onopen = function(e) {
          $log.info('[Stream] Connection opened to ' + url);
        };

        $scope.$on("$destroy", function() {
          if (!$window.streams[url]) {
            return;
          }
          $log.info('[Stream] Closing connection to ' + url);
          $window.streams[url].close();
          delete window.streams[url];
        });

        return {
          subscribe: function(event, callback){
            $window.streams[url].addEventListener(event, function(e) {
              var data = $.parseJSON(e.data);
              $log.info('[Stream] Got event for ' + event);
              callback(data);<commit_msg>Bad ref to window<commit_after>define(['angular'], function(angular) {
  'use strict';

  angular.module('stream', [])
    .factory('Stream', function($window, $log){
      if ($window.streams === undefined) {
        $window.streams = {};
      }

      return function($scope, url, callback) {
        if ($window.streams[url]) {
          $log.info('[Stream] Closing connection to ' + url);
          $window.streams[url].close();
        }
        $log.info('[Stream] Initiating connection to ' + url);

        $window.streams[url] = new EventSource(url + '?_=' + new Date().getTime());
        $window.streams[url].onopen = function(e) {
          $log.info('[Stream] Connection opened to ' + url);
        };

        $scope.$on("$destroy", function() {
          if (!$window.streams[url]) {
            return;
          }
          $log.info('[Stream] Closing connection to ' + url);
          $window.streams[url].close();
          delete $window.streams[url];
        });

        return {
          subscribe: function(event, callback){
            $window.streams[url].addEventListener(event, function(e) {
              var data = $.parseJSON(e.data);
              $log.info('[Stream] Got event for ' + event);
              callback(data);
{'fraction_non_alphanumeric': 0.16985645933014354, 'fraction_numerical': 0.0, 'mean_word_length': 2.167929292929293, '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': '7362659', 'n_tokens_mistral': 728, 'n_tokens_neox': 715, 'n_words': 140}